Skip to content

Commit

Permalink
取消使用智能指针对NavigationHandler进行封装的方案而采取手动管理,以避免崩溃问题:
Browse files Browse the repository at this point in the history
#0  0x00007f5d3681a4f5 in raise () from /lib64/libc.so.6
#1  0x00007f5d3681bcd5 in abort () from /lib64/libc.so.6
#2  0x00007f5d3681366e in __assert_fail_base () from /lib64/libc.so.6
#3  0x00007f5d36813730 in __assert_fail () from /lib64/libc.so.6
#4  0x00000000007c1de1 in decRef (this=0x11010c0) at /home/kbe/kbengine/kbe/src/lib/common/refcountable.h:65
#5  decrementReferenceCount<KBEngine::NavigationHandle> (this=0x11010c0) at /home/kbe/kbengine/kbe/src/lib/common/smartpointer.h:37
#6  ~ConstSmartPointer (this=0x11010c0) at /home/kbe/kbengine/kbe/src/lib/common/smartpointer.h:68
#7  ~SmartPointer (this=0x11010c0) at /home/kbe/kbengine/kbe/src/lib/common/smartpointer.h:214
#8  ~pair (this=0x11010c0) at /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_pair.h:68
kbengine#9  destroy (this=0x11010c0) at /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/ext/new_allocator.h:115
#10 _M_deallocate_node (this=0x11010c0) at /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/tr1_impl/hashtable:509
kbengine#11 _M_deallocate_nodes (this=0x11010c0) at /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/tr1_impl/hashtable:530
kbengine#12 clear (this=0x11010c0) at /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/tr1_impl/hashtable:1209
kbengine#13 KBEngine::Navigation::finalise (this=0x11010c0) at navigation.cpp:49
kbengine#14 0x0000000000656591 in KBEngine::Cellapp::finalise (this=0x7ffdc0afb260) at cellapp.cpp:327
kbengine#15 0x00000000006d90a5 in KBEngine::kbeMainT<KBEngine::Cellapp> (argc=<value optimized out>, argv=<value optimized out>, componentType=KBEngine::CELLAPP_TYPE, extlisteningPort_min=17174880, extlisteningPort_max=12649664,
    extlisteningInterface=0x7ffdc0afbd01 "\223@6]\177", intlisteningPort=0, intlisteningInterface=0x10fc136 "") at /home/kbe/kbengine/kbe/src/lib/server/kbemain.h:196
kbengine#16 0x00000000006c394f in kbeMain (argc=<value optimized out>, argv=<value optimized out>) at main.cpp:79
kbengine#17 0x00000000006c3ae1 in main (argc=3, argv=0x7ffdc0afbfd8) at main.cpp:76
  • Loading branch information
imgamer committed Feb 28, 2019
1 parent 1620fb4 commit 2de162c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
12 changes: 10 additions & 2 deletions kbe/src/lib/navigation/navigation.cpp
Expand Up @@ -46,6 +46,13 @@ Navigation::~Navigation()
void Navigation::finalise()
{
KBEngine::thread::ThreadGuard tg(&mutex_);

KBEUnordered_map<std::string, NavigationHandlePtr>::iterator iter = navhandles_.begin();
for (; iter != navhandles_.end(); iter++)
{
SAFE_RELEASE(iter->second);
}

navhandles_.clear();
}

Expand All @@ -56,7 +63,8 @@ bool Navigation::removeNavigation(std::string resPath)
KBEUnordered_map<std::string, NavigationHandlePtr>::iterator iter = navhandles_.find(resPath);
if(navhandles_.find(resPath) != navhandles_.end())
{
iter->second->decRef();
//iter->second->decRef();
SAFE_RELEASE(iter->second);
navhandles_.erase(iter);

DEBUG_MSG(fmt::format("Navigation::removeNavigation: ({}) is destroyed!\n", resPath));
Expand All @@ -83,7 +91,7 @@ NavigationHandlePtr Navigation::findNavigation(std::string resPath)
else if (iter->second->type() == NavigationHandle::NAV_TILE)
{
// 由于tile需要做碰撞, 每一个space都需要一份新的数据, 我们这里采用拷贝的方式来增加构造速度
NavTileHandle* pNavTileHandle = new NavTileHandle(*(KBEngine::NavTileHandle*)iter->second.get());
NavTileHandle* pNavTileHandle = new NavTileHandle(*(KBEngine::NavTileHandle*)iter->second); // 注意,NAV_TILE寻路方式使用findNavigation需要自己释放内存
DEBUG_MSG(fmt::format("Navigation::findNavigation: copy NavTileHandle({:p})!\n", (void*)pNavTileHandle));
return NavigationHandlePtr(pNavTileHandle);
}
Expand Down
5 changes: 3 additions & 2 deletions kbe/src/lib/navigation/navigation_handle.h
Expand Up @@ -30,7 +30,7 @@ along with KBEngine. If not, see <http://www.gnu.org/licenses/>.
namespace KBEngine{


class NavigationHandle : public RefCountable
class NavigationHandle
{
public:
static const int NAV_ERROR = -1;
Expand Down Expand Up @@ -71,7 +71,8 @@ class NavigationHandle : public RefCountable
std::string resPath;
};

typedef SmartPointer<NavigationHandle> NavigationHandlePtr;
//typedef SmartPointer<NavigationHandle> NavigationHandlePtr;
typedef NavigationHandle* NavigationHandlePtr;

}
#endif // KBE_NAVIGATEHANDLE_H
Expand Down
2 changes: 1 addition & 1 deletion kbe/src/server/cellapp/space.cpp
Expand Up @@ -72,7 +72,7 @@ Space::~Space()

this->coordinateSystem_.releaseNodes();

pNavHandle_.clear();
//pNavHandle_.clear();

SAFE_RELEASE(pCell_);

Expand Down

0 comments on commit 2de162c

Please sign in to comment.