Hi, Mai Dung, may be you do the work in the Main Thread, no in the opengl thread. You have to inherit the InputEvent, and throw the event to the thread where cocos2d-x draw the UI. You can do like this:
class BackkeyEvent : public InputEvent
{
public:
BackkeyEvent();
virtual void execute(Cocos2dRenderer ^ renderer);
};
void BackkeyEvent::execute( Cocos2dRenderer ^ renderer )
{
renderer->OnBackKeyPress();
}
bool Direct3DInterop::OnBackKeyPress()
{
std::lock_guard guard(mMutex);
std::shared_ptr e(new BackkeyEvent());
mInputEvents.push(e);
return true; // return true here to avoid the mainthread do it again
}
// user pressed the Back Key on the phone
bool Cocos2dRenderer::OnBackKeyPress()
{
CCDirector* pDirector = CCDirector::sharedDirector();
// return to the main test UI
CCScene* pScene = CCScene::create();
CCLayer* pLayer = new TestController();
pLayer->autorelease();
pScene->addChild(pLayer);
CCDirector::sharedDirector()->replaceScene(pScene);
return true;
}
I Overloaded as follows on wp8-xaml and I have no issues?
EDIT: Actually it seems to randomly crash sometimes, I’ll try to resolve this with MS as it doesn’t seem to be cocos2d-x thats causing it its the interop of c++ and c#.