From bd9ec7ddc72c4d2708541369d20043bc58d19e71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 22 Jul 2021 10:47:50 +0200 Subject: [PATCH] Control Strict Pointer Mode from the CLI, defaulting to OFF Due to issues with library overrides and unsynced pointers, it's quite common for the Blender Animation Studio to get crashes of BAT. To avoid these, Strict Pointer Mode is disabled when using BAT from the CLI. Blender Cloud add-on will also get a similar update, so that there also the Strict Pointer Mode is disabled. --- blender_asset_tracer/blendfile/__init__.py | 14 ++++++++++++++ blender_asset_tracer/cli/__init__.py | 16 ++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/blender_asset_tracer/blendfile/__init__.py b/blender_asset_tracer/blendfile/__init__.py index edb66be..0652a12 100644 --- a/blender_asset_tracer/blendfile/__init__.py +++ b/blender_asset_tracer/blendfile/__init__.py @@ -839,3 +839,17 @@ class BlendFileBlock: """Generator, yields (property path, property value) recursively for all properties.""" for k in self.keys(): yield from self.get_recursive_iter(k, as_str=False) + + +def set_strict_pointer_mode(strict_pointers: bool) -> None: + """Control behaviour when a pointer to unknown memory is dereferenced. + + Strict pointer mode raise exceptions.SegmentationFault when dereferencing an + unknown pointer. This is the default. + + Set to False to disable this exception, and to return None instead, i.e. to + ignore such pointers. Note that this can cause None to be returned from a + non-nil pointer. + """ + + BlendFile.strict_pointer_mode = strict_pointers diff --git a/blender_asset_tracer/cli/__init__.py b/blender_asset_tracer/cli/__init__.py index 6db6fd9..04120d8 100644 --- a/blender_asset_tracer/cli/__init__.py +++ b/blender_asset_tracer/cli/__init__.py @@ -62,6 +62,14 @@ def cli_main(): const=logging.ERROR, help="Log at ERROR level and higher", ) + parser.add_argument( + "-S", + "--strict-pointers", + default=False, + action="store_true", + help="Crash on pointers to missing data; otherwise the missing data is just ignored.", + ) + subparsers = parser.add_subparsers( help="Choose a subcommand to actually make BAT do something. " "Global options go before the subcommand, " @@ -88,6 +96,8 @@ def cli_main(): if not args.func: parser.error("No subcommand was given") + set_strict_pointer_mode(args.strict_pointers) + start_time = time.time() if args.profile: import cProfile @@ -118,3 +128,9 @@ def config_logging(args): # Only set the log level on our own logger. Otherwise # debug logging will be completely swamped. logging.getLogger("blender_asset_tracer").setLevel(args.loglevel) + + +def set_strict_pointer_mode(strict_pointers: bool) -> None: + from blender_asset_tracer import blendfile + + blendfile.set_strict_pointer_mode(strict_pointers)