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

This commit is contained in:
Mitchell Stokes 2014-07-02 21:55:29 -07:00
parent eaf6f9fc5d
commit 4af848e557
Notes: blender-bot 2023-02-14 10:23:37 +01:00
Referenced by commit 04fdd35ba5, Slight cleanup for 4af848e.
Referenced by issue #40923, LibLoad & LibFree crash with endObject
2 changed files with 6 additions and 1 deletions

View File

@ -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

View File

@ -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();