This has been driving me crazy for a week now. The problem is that I am creating a CCMenuItemSprite, using a function pointer as the SEL_MenuHandler, but when the function gets call, the object of the function is basically garbage.
So my creation looks like this:
CCMenuItemSprite::create(si0, si0, this, (SEL_MenuHandler)specialStart);
si0 - a sprite I defined above
this - an object that inherits from CCObject
specialStart[ 0 ] - the first index of an array of function pointers
the function pointers has this signature:
When I click on the menuitem, everything works as expect until I reach the function specialStart[ 0 ] points to. The object of that function (this) is garbage. The strange part is, the step about the call stack in CCMenuItem:
if (m_pListener && m_pfnSelector)
if (kScriptTypeNone != m_eScriptType)
m_pListener points to the correct object with correct data, and m_pfnSelector points to the correct function and same function that specialStart[ 0 ] pointed to. But as soon as the call (m_pListener->*m_pfnSelector)(this); is stepped into, m_pListener (which is now the “this” property) is garbage and not the same as m_pListener was the step above.
Someone please help me