CCScheduler::removeHashElement releases incorrect object

Hi,
i ran into a confusing bug. When i switch scenes (replace or push) my game crashed. I found that the retain counter of some sprites drops to 0 but the auto release pool tries to retain them afterwards, which results in an assert.
This only occurs after the second or third run of my level. Never after the first run.
I tracked the retain and release calls and nailed it down to CCScheduler calling an incorrect release on the objects (see backtrace below). The scheduler never calls retain on that sprite.
Actually the sprites that are released here do not have any scheduled callbacks. I went down the call tree and got stuck when it came to the hash function and hash map preprocessor macros. I suppose there might either be some sort of hash collision or the hash map is not cleanly cleared.

I am also not sure if this is actually a problem restricted to cocos2d-x or also relevant to the objective-c version of cocos2d.

Since i never schedule anything on my custom sprites i excluded the release call with a dynamic cast. But i suppose that this release is missing on some other object then. So this might cause a memory leak.

Has anyone ever had similar issues?

Regards.

Here is the backtrace:

0 mygame 0x0018c19f ZL11print_tracev + 63
1 mygame 0x0018c2dc
ZN8LHSprite7releaseEv + 92
2 mygame 0x0003adf5 ZN7cocos2d11CCScheduler17removeHashElementEPNS_18_hashSelectorEntryE + 53
3 mygame 0x00040269
ZN7cocos2d11CCScheduler31unscheduleAllSelectorsForTargetEPNS_8CCObjectE + 1593
4 mygame 0x00031296 ZN7cocos2d6CCNode22unscheduleAllSelectorsEv + 38
5 mygame 0x0003120a
ZN7cocos2d6CCNode7cleanupEv + 42
6 mygame 0x0002facc ZN7cocos2d6CCNode31arrayMakeObjectsPerformSelectorEPNS_7CCArrayEMS0_FvvE + 332
7 mygame 0x0003123a
ZN7cocos2d6CCNode7cleanupEv + 90
8 mygame 0x0002facc ZN7cocos2d6CCNode31arrayMakeObjectsPerformSelectorEPNS_7CCArrayEMS0_FvvE + 332
9 mygame 0x0003123a
ZN7cocos2d6CCNode7cleanupEv + 90
10 mygame 0x0002facc ZN7cocos2d6CCNode31arrayMakeObjectsPerformSelectorEPNS_7CCArrayEMS0_FvvE + 332
11 mygame 0x0003123a
ZN7cocos2d6CCNode7cleanupEv + 90
12 mygame 0x000352e7 ZN7cocos2d10CCDirector12setNextSceneEv + 327
13 mygame 0x00034f11
ZN7cocos2d10CCDirector9drawSceneEv + 113
14 mygame 0x00036b8e ZN7cocos2d21CCDisplayLinkDirector8mainLoopEv + 78
15 mygame 0x0008ce35 - + 37
16 QuartzCore 0x00dcda88
ZN2CA7Display11DisplayLink8dispatchEyy + 128
17 QuartzCore 0x00dcdbcd ZN2CA7Display19EmulatorDisplayLink8callbackEP16CFRunLoopTimerPv + 145
18 CoreFoundation 0x02def8c3
CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION
_ + 19
19 CoreFoundation 0x02df0e74 CFRunLoopDoTimer + 1220
20 CoreFoundation 0x02d4d2c9
CFRunLoopRun + 1817
21 CoreFoundation 0x02d4c840 CFRunLoopRunSpecific + 208
22 CoreFoundation 0x02d4c761 CFRunLoopRunInMode + 97
23 GraphicsServices 0x02a2e1c4 GSEventRunModal + 217
24 GraphicsServices 0x02a2e289 GSEventRun + 115
25 UIKit 0x01999c93 UIApplicationMain + 1160
26 mygame 0x000f5326 main + 134
27 mygame 0x000025f5 start + 53
28 ??? 0x00000001 0x0 + 1

Could you provide a demo to reproduce it?
I can not find the bug by the description.

run TextureCacheTest first

then HiResTest and press to right to 2X mode

then exit test

will error here….
void CCScheduler::removeHashElement(_hashSelectorEntry *pElement)
{
ccArrayFree(pElement~~>timers);
pElement~~>target~~>selectorProtocolRelease;
pElement~~>target = NULL;
HASH_DEL(m_pHashForSelectors, pElement);
free(pElement);
}

After i check…

releated to -> after exit TextureCacheTest not do CCScheduler::unscheduleSelector

and can not add CCScheduler::sharedScheduler()->unscheduleUpdateForTarget(this);
in
void CCTextureCache::purgeSharedTextureCache()

because its is a static function

@Jesse Stone
You didn’t use cocos2d-x v2.x, right?