mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-04-17 17:43:52 +00:00
Fix crash in character creation by deferring callback to next update
The charCreateCallback was firing synchronously during ImGui render, causing a state transition before the create screen's ImGui::End() was called. Defer the callback to GameHandler::update() and ensure update() runs during CHARACTER_CREATION and CHARACTER_SELECTION states.
This commit is contained in:
parent
0451c82661
commit
776a617f61
3 changed files with 21 additions and 5 deletions
|
|
@ -525,6 +525,9 @@ private:
|
||||||
WorldConnectSuccessCallback onSuccess;
|
WorldConnectSuccessCallback onSuccess;
|
||||||
WorldConnectFailureCallback onFailure;
|
WorldConnectFailureCallback onFailure;
|
||||||
CharCreateCallback charCreateCallback_;
|
CharCreateCallback charCreateCallback_;
|
||||||
|
bool pendingCharCreateResult_ = false;
|
||||||
|
bool pendingCharCreateSuccess_ = false;
|
||||||
|
std::string pendingCharCreateMsg_;
|
||||||
|
|
||||||
// ---- XP tracking ----
|
// ---- XP tracking ----
|
||||||
uint32_t playerXp_ = 0;
|
uint32_t playerXp_ = 0;
|
||||||
|
|
|
||||||
|
|
@ -344,11 +344,15 @@ void Application::update(float deltaTime) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AppState::CHARACTER_CREATION:
|
case AppState::CHARACTER_CREATION:
|
||||||
// Character creation update
|
if (gameHandler) {
|
||||||
|
gameHandler->update(deltaTime);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AppState::CHARACTER_SELECTION:
|
case AppState::CHARACTER_SELECTION:
|
||||||
// Character selection update
|
if (gameHandler) {
|
||||||
|
gameHandler->update(deltaTime);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AppState::IN_GAME:
|
case AppState::IN_GAME:
|
||||||
|
|
|
||||||
|
|
@ -406,6 +406,14 @@ bool GameHandler::isConnected() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameHandler::update(float deltaTime) {
|
void GameHandler::update(float deltaTime) {
|
||||||
|
// Fire deferred char-create callback (outside ImGui render)
|
||||||
|
if (pendingCharCreateResult_) {
|
||||||
|
pendingCharCreateResult_ = false;
|
||||||
|
if (charCreateCallback_) {
|
||||||
|
charCreateCallback_(pendingCharCreateSuccess_, pendingCharCreateMsg_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!socket && !singlePlayerMode_) {
|
if (!socket && !singlePlayerMode_) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -852,9 +860,10 @@ void GameHandler::createCharacter(const CharCreateData& data) {
|
||||||
characters.push_back(ch);
|
characters.push_back(ch);
|
||||||
|
|
||||||
LOG_INFO("Single-player character created: ", ch.name);
|
LOG_INFO("Single-player character created: ", ch.name);
|
||||||
if (charCreateCallback_) {
|
// Defer callback to next update() so ImGui frame completes first
|
||||||
charCreateCallback_(true, "Character created!");
|
pendingCharCreateResult_ = true;
|
||||||
}
|
pendingCharCreateSuccess_ = true;
|
||||||
|
pendingCharCreateMsg_ = "Character created!";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue