[Bf-blender-cvs] [4af848e] master: Fix T40923: An error from a python controller on a LibFreed object causes a crash

Mitchell Stokes noreply at git.blender.org
Thu Jul 3 06:58:48 CEST 2014


Commit: 4af848e557fa8789ac0cc802d6479bd53145e1fd
Author: Mitchell Stokes
Date:   Wed Jul 2 21:55:29 2014 -0700
https://developer.blender.org/rB4af848e557fa8789ac0cc802d6479bd53145e1fd

Fix T40923: An error from a python controller on a LibFreed object causes a crash

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

M	source/gameengine/GameLogic/SCA_PythonController.cpp
M	source/gameengine/Ketsji/KX_Scene.cpp

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

diff --git a/source/gameengine/GameLogic/SCA_PythonController.cpp b/source/gameengine/GameLogic/SCA_PythonController.cpp
index 3a9e8ff..dbcbbea 100644
--- a/source/gameengine/GameLogic/SCA_PythonController.cpp
+++ b/source/gameengine/GameLogic/SCA_PythonController.cpp
@@ -263,7 +263,11 @@ PyAttributeDef SCA_PythonController::Attributes[] = {
 
 void SCA_PythonController::ErrorPrint(const char *error_msg)
 {
-	printf("%s - object '%s', controller '%s':\n", error_msg, GetParent()->GetName().Ptr(), GetName().Ptr());
+	// If GetParent() is NULL, then most likely the object this controller
+	// was attached to is gone (e.g., removed by LibFree()).
+	const char *obj_name = (GetParent()) ? GetParent()->GetName().ReadPtr() : "Unavailable";
+	const char *ctr_name = (GetParent()) ? GetName().ReadPtr() : "Unavailable";
+	printf("%s - object '%s', controller '%s':\n", error_msg, obj_name, ctr_name);
 	PyErr_Print();
 	
 	/* Added in 2.48a, the last_traceback can reference Objects for example, increasing
diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp
index 0dfdb3d..3d71327 100644
--- a/source/gameengine/Ketsji/KX_Scene.cpp
+++ b/source/gameengine/Ketsji/KX_Scene.cpp
@@ -1038,6 +1038,7 @@ int KX_Scene::NewRemoveObject(class CValue* gameobj)
 		 !(itc==controllers.end());itc++)
 	{
 		m_logicmgr->RemoveController(*itc);
+		(*itc)->ReParent(NULL);
 	}
 
 	SCA_ActuatorList& actuators = newobj->GetActuators();




More information about the Bf-blender-cvs mailing list