diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index 15e65ac9fe5..05d4f45b634 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -2218,11 +2218,28 @@ void BL_ConvertBlenderObjects(struct Main* maggie, { // special case: the parent and child object are not in the same layer. // This weird situation is used in Apricot for test purposes. - // Resolve it by breaking the parent relationship + // Resolve it by not converting the child childobj->GetSGNode()->DisconnectFromParent(); delete pcit->m_gamechildnode; - // This leave the child object is an incorrect position: its local position becomes - // the global position but we don't care: the child should be in an invisble layer + // Now destroy the child object but also all its descendent that may already be linked + // Remove the child reference in the local list! + // Note: there may be descendents already if the children of the child were processed + // by this loop before the child. In that case, we must remove the children also + CListValue* childrenlist = (CListValue*)childobj->PyGetChildrenRecursive(childobj); + childrenlist->Add(childobj->AddRef()); + for ( i=0;iGetCount();i++) + { + KX_GameObject* obj = static_cast(childrenlist->GetValue(i)); + if (templist->RemoveValue(obj)) + obj->Release(); + if (sumolist->RemoveValue(obj)) + obj->Release(); + if (logicbrick_conversionlist->RemoveValue(obj)) + obj->Release(); + } + childrenlist->Release(); + // now destroy recursively + kxscene->RemoveObject(childobj); continue; } diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp index 1f5b578d441..4734b84de54 100644 --- a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp +++ b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp @@ -496,7 +496,17 @@ void KX_BlenderSceneConverter::RegisterGameObject( void KX_BlenderSceneConverter::UnregisterGameObject( KX_GameObject *gameobject) { - m_map_gameobject_to_blender.remove(CHashedPtr(gameobject)); + CHashedPtr gptr(gameobject); + struct Object **bobp= m_map_gameobject_to_blender[gptr]; + if (bobp) { + CHashedPtr bptr(*bobp); + KX_GameObject **gobp= m_map_blender_to_gameobject[bptr]; + if (gobp && *gobp == gameobject) + // also maintain m_map_blender_to_gameobject if the gameobject + // being removed is matching the blender object + m_map_blender_to_gameobject.remove(bptr); + m_map_gameobject_to_blender.remove(gptr); + } }