First-chance exception when trying to init CCDirector* pDirector in onEnter

First-chance exception when trying to init CCDirector* pDirector in onEnter
0.0 0


Hey , im porting cocos2d game to be cocos2d-x version i have this simple code that gives me this exception :
First-chance exception at 0x00B6A6C3 in mygame_port.win32.exe: 0xC0000005: Access violation reading location 0xFEEEFEEE.
note that i checked all exceptions types under Debug ~~> Exceptions window .
the problem that i dont understand is if i remove the content of onEnter function every thing is working fine
but when i keep the onEnter content that is what you see here : im getting the exception
this is the code i have :

class MAPlayfieldLayer : public CCLayer
public :
virtual void onEnter;
virtual bool init ;

@bool MAPlayfieldLayer::init {
if ) return false;
//Add the score display to the screen
//Add the timer display to the screen

return true;

void MAPlayfieldLayer::onEnter
CCDirector* pDirector = CCDirector::sharedDirector;
pDirector~~>getTouchDispatcher()->addTargetedDelegate(this, 0, true);


void MAPlayfieldLayer::update(float dt)
gemsMoving = false;

//See if we have any gems currently moving
CCObject aGemIt = NULL;
aGem = static_cast<MAGem*>(aGemIt);
if (aGem->getGemState() == kGemMoving) {
gemsMoving = true;


here is also my stack print :
  mygame_port.win32.exe!MAPlayfieldLayer::update(float dt) Line 102 C++
    libcocos2d.dll!cocos2d::CCScheduler::update(float dt) Line 809  C++
    libcocos2d.dll!cocos2d::CCDirector::drawScene() Line 217    C++
    libcocos2d.dll!cocos2d::CCDisplayLinkDirector::mainLoop() Line 966  C++
    libcocos2d.dll!cocos2d::CCApplication::run() Line 67    C++
    mymatch_port.win32.exe!wWinMain(HINSTANCE__ * hInstance, HINSTANCE__ * hPrevInstance, wchar_t * lpCmdLine, int nCmdShow) Line 30    C++
    mymatch_port.win32.exe!__tmainCRTStartup() Line 528 C
    mymatch_port.win32.exe!wWinMainCRTStartup() Line 377    C
    kernel32.dll!7786ed6c() Unknown
    [Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]  
    ntdll.dll!77d0377b()    Unknown
    ntdll.dll!77d0374e()    Unknown