diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-11-01 19:56:42 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-11-01 19:56:42 +0400 |
commit | f4e5404e4ae1bf0c5c45220f87e981fbc4c3ab98 (patch) | |
tree | ff46e4486c2c137aff2cd5196835d21bd5376b7d /source/blender/makesrna/RNA_access.h | |
parent | 818e9ff88d84f85ad729b8d7839ead21568cff20 (diff) |
fix for long standing problem with blender 2.5x py api.
Removing data then accessing would allow invalid memory access and often crash.
Example:
import bpy
image = bpy.data.images.new(name="a", width=5, height=5)
bpy.data.images.remove(image)
print(image.name)
Now access to the removed data raises an error:
ReferenceError: StructRNA of type Image has been removed
This is the same level of error checking that was done in blender 2.4x but was made difficult by RNA functions not having access to the PyObject's.
Diffstat (limited to 'source/blender/makesrna/RNA_access.h')
-rw-r--r-- | source/blender/makesrna/RNA_access.h | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index 60ab231ffc9..a9dbbe4273f 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -1032,6 +1032,13 @@ short RNA_type_to_ID_code(StructRNA *type); StructRNA *ID_code_to_RNA_type(short idcode); +#define RNA_POINTER_INVALIDATE(ptr) { \ + /* this is checked for validity */ \ + (ptr)->type = \ + /* should not be needed but prevent bad pointer access, just in case */ \ + (ptr)->id.data = NULL; \ +} (void)0 + /* macro which inserts the function name */ #if defined __GNUC__ || defined __sun # define RNA_warning(format, args ...) _RNA_warning("%s: " format "\n", __func__, ##args) |