CCAutoreleasePool does not check if an object is added twice.


#1

The problem is very simple, Imagine the case when someone (by mistake) call “CCObject::autorelease” twice. This simply will access violation whenever that object is going to be deleted because that object is being deleted twice. I guess ObjectPool should be able to handle such cases or at least there should be an assertion. I can think of two possible solutions:

  1. check for duplicates whenever “void CCAutoreleasePool::addObject(CCObject* pObject)” is called
  2. add a flag is object is already managed by memory pool to members of all objects.

#2

Traversing the autorelease array each time at CCAutoreleasePool::addObject seems a bit expensive. But we do already have a flag CCObject::m_bManaged.
I just fixed it in https://github.com/cocos2d/cocos2d-x/pull/1414, related to issue #1492.

Thanks for your suggestion!


#3

This final resolution is in #1494.
Adding an object twice into autorelease pool is allown. We tweak the ~CCObject() destructor a bit to avoid the bug.