[Bf-blender-cvs] [24deeee09e6] master: Fix some RNA physics accessors creating data.

Bastien Montagne noreply at git.blender.org
Fri May 21 17:22:51 CEST 2021


Commit: 24deeee09e6ba8719fe69af5346eda9d521b0312
Author: Bastien Montagne
Date:   Fri May 21 14:57:29 2021 +0200
Branches: master
https://developer.blender.org/rB24deeee09e6ba8719fe69af5346eda9d521b0312

Fix some RNA physics accessors creating data.

Accessing data through RNA should never implicitely create it. Objects'
and particles' forcefields and collision settings were doing this.

Note that UI code also had to be tweaked to properly handle `None`
(NULL) cases.

Differential Revision: https://developer.blender.org/D11341

===================================================================

M	release/scripts/startup/bl_ui/properties_particle.py
M	release/scripts/startup/bl_ui/properties_physics_common.py
M	source/blender/makesrna/intern/rna_object.c
M	source/blender/makesrna/intern/rna_particle.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/properties_particle.py b/release/scripts/startup/bl_ui/properties_particle.py
index a9f040db9b5..ae15fda2c69 100644
--- a/release/scripts/startup/bl_ui/properties_particle.py
+++ b/release/scripts/startup/bl_ui/properties_particle.py
@@ -1803,9 +1803,10 @@ class PARTICLE_PT_force_fields_type1(ParticleButtonsPanel, Panel):
 
         part = particle_get_settings(context)
 
-        col = layout.column()
-        col.prop(part.force_field_1, "type", text="Type 1")
-        basic_force_field_settings_ui(self, part.force_field_1)
+        if part.force_field_1:
+            col = layout.column()
+            col.prop(part.force_field_1, "type", text="Type 1")
+            basic_force_field_settings_ui(self, part.force_field_1)
 
 
 class PARTICLE_PT_force_fields_type2(ParticleButtonsPanel, Panel):
@@ -1819,9 +1820,10 @@ class PARTICLE_PT_force_fields_type2(ParticleButtonsPanel, Panel):
 
         part = particle_get_settings(context)
 
-        col = layout.column()
-        col.prop(part.force_field_2, "type", text="Type 2")
-        basic_force_field_settings_ui(self, part.force_field_2)
+        if part.force_field_2:
+            col = layout.column()
+            col.prop(part.force_field_2, "type", text="Type 2")
+            basic_force_field_settings_ui(self, part.force_field_2)
 
 
 class PARTICLE_PT_force_fields_type1_falloff(ParticleButtonsPanel, Panel):
@@ -1836,7 +1838,8 @@ class PARTICLE_PT_force_fields_type1_falloff(ParticleButtonsPanel, Panel):
 
         part = particle_get_settings(context)
 
-        basic_force_field_falloff_ui(self, part.force_field_1)
+        if part.force_field_1:
+            basic_force_field_falloff_ui(self, part.force_field_1)
 
 
 class PARTICLE_PT_force_fields_type2_falloff(ParticleButtonsPanel, Panel):
@@ -1851,7 +1854,8 @@ class PARTICLE_PT_force_fields_type2_falloff(ParticleButtonsPanel, Panel):
 
         part = particle_get_settings(context)
 
-        basic_force_field_falloff_ui(self, part.force_field_2)
+        if part.force_field_2:
+            basic_force_field_falloff_ui(self, part.force_field_2)
 
 
 class PARTICLE_PT_vertexgroups(ParticleButtonsPanel, Panel):
diff --git a/release/scripts/startup/bl_ui/properties_physics_common.py b/release/scripts/startup/bl_ui/properties_physics_common.py
index 7f55e4888cf..f13a808e324 100644
--- a/release/scripts/startup/bl_ui/properties_physics_common.py
+++ b/release/scripts/startup/bl_ui/properties_physics_common.py
@@ -79,7 +79,7 @@ class PHYSICS_PT_add(PhysicButtonsPanel, Panel):
 
         col = flow.column()
 
-        if obj.field.type == 'NONE':
+        if not obj.field or obj.field.type == 'NONE':
             col.operator("object.forcefield_toggle", text="Force Field", icon='FORCE_FORCE')
         else:
             col.operator("object.forcefield_toggle", text="Force Field", icon='X')
diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c
index 1dc7519258b..b339682222c 100644
--- a/source/blender/makesrna/intern/rna_object.c
+++ b/source/blender/makesrna/intern/rna_object.c
@@ -1502,11 +1502,6 @@ static PointerRNA rna_Object_field_get(PointerRNA *ptr)
 {
   Object *ob = (Object *)ptr->owner_id;
 
-  /* weak */
-  if (!ob->pd) {
-    ob->pd = BKE_partdeflect_new(0);
-  }
-
   return rna_pointer_inherit_refine(ptr, &RNA_FieldSettings, ob->pd);
 }
 
@@ -1518,11 +1513,6 @@ static PointerRNA rna_Object_collision_get(PointerRNA *ptr)
     return PointerRNA_NULL;
   }
 
-  /* weak */
-  if (!ob->pd) {
-    ob->pd = BKE_partdeflect_new(0);
-  }
-
   return rna_pointer_inherit_refine(ptr, &RNA_CollisionSettings, ob->pd);
 }
 
diff --git a/source/blender/makesrna/intern/rna_particle.c b/source/blender/makesrna/intern/rna_particle.c
index d94e68a6808..7ff2a82a465 100644
--- a/source/blender/makesrna/intern/rna_particle.c
+++ b/source/blender/makesrna/intern/rna_particle.c
@@ -1413,24 +1413,12 @@ static const EnumPropertyItem *rna_Particle_ren_as_itemf(bContext *UNUSED(C),
 static PointerRNA rna_Particle_field1_get(PointerRNA *ptr)
 {
   ParticleSettings *part = (ParticleSettings *)ptr->owner_id;
-
-  /* weak */
-  if (!part->pd) {
-    part->pd = BKE_partdeflect_new(0);
-  }
-
   return rna_pointer_inherit_refine(ptr, &RNA_FieldSettings, part->pd);
 }
 
 static PointerRNA rna_Particle_field2_get(PointerRNA *ptr)
 {
   ParticleSettings *part = (ParticleSettings *)ptr->owner_id;
-
-  /* weak */
-  if (!part->pd2) {
-    part->pd2 = BKE_partdeflect_new(0);
-  }
-
   return rna_pointer_inherit_refine(ptr, &RNA_FieldSettings, part->pd2);
 }



More information about the Bf-blender-cvs mailing list