Bug #457

Retaining an CCObject with texture will cause program crashes at exiting

Added by Zhe Wang about 2 years ago. Updated 12 months ago.

Status:New Start date:2011-04-14
Priority:Normal Due date:
Assignee:- % Done:

0%

Category:-
Target version:-

Description

A developer report this bug on QQ:

试过在AppDelegate 里面保留场景指针吗? 如果场景里面哪怕有一个带贴图的精灵都会引起崩溃 我跟了一下 应该是这样的
关闭窗口的时候 CCDirector 会先被析构 它析构的同时 应该会释放所有东西 包括opengl相关的
然后才是AppDelegate 的析构 在AppDelegate 的析构里面 调用保留的场景指针的release 本身是没问题的 但是如果里面有精灵 精灵的析构会调用 CC_SAFE_RELEASE(m_pobTexture);
m_pobTexture的析构里面又会调用跟opengl相关的接口 所以导致崩溃 那时候opengl的纹理应该都已经被清理干净了

And he hack the source, add a callback from CCDirector to AppDelegate before the destructor invoked

void CCDirector::purgeDirector()
{
    // don't release the event handlers
    // They are needed in case the director is run again
    CCTouchDispatcher::sharedDispatcher()->removeAllDelegates();

        //  [4/15/2011 JasonDeng]
        OnPurgeDirector();

        // ....
}

It's a bit ugly. Can we have a better design here, or just leave as it is, and write some tips on wiki?

History

Updated by Zhe Wang 12 months ago

  • Project changed from cocos2d-x to native
  • Category deleted (5)
  • Target version deleted (9)

Also available in: Atom PDF