Skip to content

Commit e02ffd2

Browse files
committed
called destroySpace, crash. (kbengine#52)
1 parent 492c92a commit e02ffd2

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

kbe/src/server/cellapp/entity.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ class Entity : public script::ScriptObject
467467
获取entity所在节点
468468
*/
469469
INLINE EntityCoordinateNode* pEntityCoordinateNode()const;
470+
INLINE void pEntityCoordinateNode(EntityCoordinateNode* pNode);
470471

471472
/**
472473
安装卸载节点

kbe/src/server/cellapp/entity.ipp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ INLINE EntityCoordinateNode* Entity::pEntityCoordinateNode()const
174174
return pEntityCoordinateNode_;
175175
}
176176

177+
//-------------------------------------------------------------------------------------
178+
INLINE void Entity::pEntityCoordinateNode(EntityCoordinateNode* pNode)
179+
{
180+
pEntityCoordinateNode_ = pNode;
181+
}
182+
177183
//-------------------------------------------------------------------------------------
178184
INLINE void Entity::isOnGround(bool v)
179185
{

kbe/src/server/cellapp/space.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,20 @@ bool Space::destroy(ENTITY_ID entityID)
345345

346346
// 最后销毁创建者
347347
if(creator)
348-
creator->destroyEntity();
348+
{
349+
if(Cellapp::getSingleton().findEntity(creator->getID()) != NULL)
350+
{
351+
creator->destroyEntity();
352+
}
353+
else
354+
{
355+
// 之所以会这样是因为可能spaceEntity在调用destroy销毁的时候onDestroy中调用了destroySpace
356+
// 那么就会出现在spaceEntity-destroy过程中导致这里继续调用creator->destroyEntity()
357+
// 此时就会出现EntityApp::destroyEntity: not found.
358+
// 然后再spaceEntity析构的时候销毁pEntityCoordinateNode_会出错, 这里应该设置为NULL。
359+
creator->pEntityCoordinateNode(NULL);
360+
}
361+
}
349362

350363
pNavHandle_.clear();
351364
entities_.clear();

0 commit comments

Comments
 (0)