Open pbs0512 opened 6 years ago
What's your device? I want to fix a crash that need monitor opengl context recreate situation, but it's too difficult to reproduce.
@ggggamer thank you for reply. my device is samsung galaxy 9. but it also happens on other devices.
---Cause of error
I can't reproduce "opengl context reload", how did you monitor this?
For your crash, Did you use TransitionScene
?
Turn the screen off, then on, and repeat with the device power button.
TransitionScene::onEnter
will disable EventDispatcher so EVENT_RENDERER_RECREATED event can't emit.
You can change cocos\platform\android\javaactivity-android.cpp
https://github.com/cocos2d/cocos2d-x/blob/c99611589c11c09edce4b1266bf211e42af6ffe4/cocos/platform/android/javaactivity-android.cpp#L106-L107
to
cocos2d::EventCustom recreatedEvent(EVENT_RENDERER_RECREATED);
if (director->getEventDispatcher()->isEnabled())
{
director->getEventDispatcher()->dispatchEvent(&recreatedEvent);
}
else
{
director->getEventDispatcher()->setEnabled(true);
director->getEventDispatcher()->dispatchEvent(&recreatedEvent);
director->getEventDispatcher()->setEnabled(false);
}
I don't use TransitionScene. use CCScene.cpp and UIListView.cpp. I solved the problem.
to
#if CC_ENABLE_CACHE_TEXTURE_DATA
if (_eventRendererRecreate == nullptr)
{
// Need to listen the event only when not use batchnode, because it will use VBO
_eventRendererRecreate = EventListenerCustom::create(EVENT_RENDERER_RECREATED, [this](EventCustom* event) {
/** listen the event that renderer was recreated on Android/WP8 */
this->init();
});
_eventDispatcher->addEventListenerWithFixedPriority(_eventRendererRecreate, 1);
}
#endif
This way, it works regardless of the node's pause (onExit) and resume (onEnter).
Congratulations!
Steps to Reproduce:
error log