/** 以下为cocos2dx原码 先执行的是release,如果_data[index]与object是一个东西且ref等1
问题就来了,先删了_data[index],再retain崩溃*/
void replace(ssize_t index, T object)
{
CCASSERT(index >= 0 && index < size(), "Invalid index!");
CCASSERT(object != nullptr, "The object should not be nullptr");
_data[index]->release();
_data[index] = object;
object->retain();
}
应改为先retain再release
object->retain();
_data[index]->release();
_data[index] = object;
以上点,引用object基础编程