Hi,
When I register my layer using setIsAccelerometerEnabled, CCNode:m_uReference is not being decreased when transacting to a new scene with ::replaceScene.
This in turn causes the CCLayer dtor not to be called.
I think that the problem (and fix?) is showed below.
@implementation AccelerometerDispatcher
...
- (void) removeDelegate: (cocos2d::CCAccelerometerDelegate *) delegate
{
out ==> [delegateWrappers removeObject:[self findDelegateWrapperByDelegate:delegate]];
in <== id ptr = [self findDelegateWrapperByDelegate:delegate];
in <== [delegateWrappers removeObject:ptr];
in <== [ptr release];
}
...
@end
Please try to call layer->setIsAccelerometerEnabled(false) before the transition, do this will remove the accelerometer delegate from AccelerometerDispatcher.
I think that there is double memory leak, because CCLayer::onEnter adds one reference to layer:
void CCLayer::onEnter()
{
// register 'parent' nodes first
// since events are propagated in reverse order
if (m_bIsTouchEnabled)
{
this->registerWithTouchDispatcher();
}
// then iterate over all the children
CCNode::onEnter();
// add this layer to concern the Accelerometer Sensor
if (m_bIsAccelerometerEnabled)
{
CCAccelerometer::sharedAccelerometer()->addDelegate(this);
}...
onEnterTransitionDidFinish adds second reference to layer:
void CCLayer::onEnterTransitionDidFinish()
{
if (m_bIsAccelerometerEnabled)
{
CCAccelerometer::sharedAccelerometer()->addDelegate(this);
}...
while onExit doesn’t remove any reference - removeDelegate is called - it’s ok, but it doesn’t decrease reference count
void CCLayer::onExit()
{
if( m_bIsTouchEnabled )
{
CCTouchDispatcher::sharedDispatcher()->removeDelegate(this);
}
// remove this layer from the delegates who concern Accelerometer Sensor
if (m_bIsAccelerometerEnabled)
{
CCAccelerometer::sharedAccelerometer()->removeDelegate(this);
}...
… tested with version cocos2d-1.0.0-x-0.9.0 (ios version - Xcode)
…AccelerometerDestroy that decreases reference count is called in “dealloc” function of AccelerometerDelegateWrapper, but it isn’t probably called at all…
How to fix it?