Fix crash at launch if g_GameState or g_StateManager is null, don't serialize CVarManager

This commit is contained in:
Phillip Stephens 2021-05-26 22:11:48 -07:00
parent 5fbd47a3d3
commit 037573e5ee
Signed by: Antidote
GPG Key ID: F8BEE4C83DACA60D
1 changed files with 6 additions and 15 deletions

View File

@ -388,7 +388,7 @@ void ImGuiConsole::ShowDebugOverlay() {
ImGui::SetNextWindowBgAlpha(0.65f); ImGui::SetNextWindowBgAlpha(0.65f);
if (ImGui::Begin("Debug Overlay", nullptr, windowFlags)) { if (ImGui::Begin("Debug Overlay", nullptr, windowFlags)) {
bool hasPrevious = false; bool hasPrevious = false;
if (m_frameCounter) { if (m_frameCounter && g_StateManager != nullptr) {
ImGuiStringViewText(fmt::format(FMT_STRING("Frame: {}\n"), g_StateManager->GetUpdateFrameIndex())); ImGuiStringViewText(fmt::format(FMT_STRING("Frame: {}\n"), g_StateManager->GetUpdateFrameIndex()));
hasPrevious = true; hasPrevious = true;
} }
@ -399,7 +399,7 @@ void ImGuiConsole::ShowDebugOverlay() {
ImGuiStringViewText(fmt::format(FMT_STRING("FPS: {}\n"), metaforce::CGraphics::GetFPS())); ImGuiStringViewText(fmt::format(FMT_STRING("FPS: {}\n"), metaforce::CGraphics::GetFPS()));
hasPrevious = true; hasPrevious = true;
} }
if (m_inGameTime) { if (m_inGameTime && g_GameState != nullptr) {
if (hasPrevious) { if (hasPrevious) {
ImGui::Separator(); ImGui::Separator();
} }
@ -410,7 +410,7 @@ void ImGuiConsole::ShowDebugOverlay() {
fmt::format(FMT_STRING("Play Time: {:02d}:{:02d}:{:02d}.{:03d}\n"), pt.quot, pt.rem / 60, pt.rem % 60, ms)); fmt::format(FMT_STRING("Play Time: {:02d}:{:02d}:{:02d}.{:03d}\n"), pt.quot, pt.rem / 60, pt.rem % 60, ms));
hasPrevious = true; hasPrevious = true;
} }
if (m_roomTimer) { if (m_roomTimer && g_StateManager != nullptr) {
if (hasPrevious) { if (hasPrevious) {
ImGui::Separator(); ImGui::Separator();
} }
@ -427,7 +427,7 @@ void ImGuiConsole::ShowDebugOverlay() {
currentRoomTime, curFrames, m_lastRoomTime, lastFrames)); currentRoomTime, curFrames, m_lastRoomTime, lastFrames));
hasPrevious = true; hasPrevious = true;
} }
if (m_playerInfo && g_StateManager->Player() != nullptr) { if (m_playerInfo && g_StateManager != nullptr && g_StateManager->Player() != nullptr) {
if (hasPrevious) { if (hasPrevious) {
ImGui::Separator(); ImGui::Separator();
} }
@ -449,7 +449,7 @@ void ImGuiConsole::ShowDebugOverlay() {
zeus::radToDeg(camQ.roll()), zeus::radToDeg(camQ.pitch()), zeus::radToDeg(camQ.yaw()))); zeus::radToDeg(camQ.roll()), zeus::radToDeg(camQ.pitch()), zeus::radToDeg(camQ.yaw())));
hasPrevious = true; hasPrevious = true;
} }
if (m_worldInfo) { if (m_worldInfo && g_StateManager != nullptr) {
if (hasPrevious) { if (hasPrevious) {
ImGui::Separator(); ImGui::Separator();
} }
@ -461,7 +461,7 @@ void ImGuiConsole::ShowDebugOverlay() {
aId)); aId));
hasPrevious = true; hasPrevious = true;
} }
if (m_areaInfo) { if (m_areaInfo && g_StateManager != nullptr) {
if (hasPrevious) { if (hasPrevious) {
ImGui::Separator(); ImGui::Separator();
} }
@ -536,39 +536,30 @@ void ImGuiConsole::ShowAppMainMenuBar(bool canInspect) {
if (ImGui::BeginMenu("Debug")) { if (ImGui::BeginMenu("Debug")) {
if (ImGui::MenuItem("Frame Counter", nullptr, &m_frameCounter)) { if (ImGui::MenuItem("Frame Counter", nullptr, &m_frameCounter)) {
m_cvarCommons.m_debugOverlayShowFrameCounter->fromBoolean(m_frameCounter); m_cvarCommons.m_debugOverlayShowFrameCounter->fromBoolean(m_frameCounter);
m_cvarMgr.serialize();
} }
if (ImGui::MenuItem("Frame Rate", nullptr, &m_frameRate)) { if (ImGui::MenuItem("Frame Rate", nullptr, &m_frameRate)) {
m_cvarCommons.m_debugOverlayShowFramerate->fromBoolean(m_frameRate); m_cvarCommons.m_debugOverlayShowFramerate->fromBoolean(m_frameRate);
m_cvarMgr.serialize();
} }
if (ImGui::MenuItem("In-Game Time", nullptr, &m_inGameTime)) { if (ImGui::MenuItem("In-Game Time", nullptr, &m_inGameTime)) {
m_cvarCommons.m_debugOverlayShowInGameTime->fromBoolean(m_inGameTime); m_cvarCommons.m_debugOverlayShowInGameTime->fromBoolean(m_inGameTime);
m_cvarMgr.serialize();
} }
if (ImGui::MenuItem("Room Timer", nullptr, &m_roomTimer)) { if (ImGui::MenuItem("Room Timer", nullptr, &m_roomTimer)) {
m_cvarCommons.m_debugOverlayShowRoomTimer->fromBoolean(m_roomTimer); m_cvarCommons.m_debugOverlayShowRoomTimer->fromBoolean(m_roomTimer);
m_cvarMgr.serialize();
} }
if (ImGui::MenuItem("Player Info", nullptr, &m_playerInfo)) { if (ImGui::MenuItem("Player Info", nullptr, &m_playerInfo)) {
m_cvarCommons.m_debugOverlayPlayerInfo->fromBoolean(m_playerInfo); m_cvarCommons.m_debugOverlayPlayerInfo->fromBoolean(m_playerInfo);
m_cvarMgr.serialize();
} }
if (ImGui::MenuItem("World Info", nullptr, &m_worldInfo)) { if (ImGui::MenuItem("World Info", nullptr, &m_worldInfo)) {
m_cvarCommons.m_debugOverlayWorldInfo->fromBoolean(m_worldInfo); m_cvarCommons.m_debugOverlayWorldInfo->fromBoolean(m_worldInfo);
m_cvarMgr.serialize();
} }
if (ImGui::MenuItem("Area Info", nullptr, &m_areaInfo)) { if (ImGui::MenuItem("Area Info", nullptr, &m_areaInfo)) {
m_cvarCommons.m_debugOverlayAreaInfo->fromBoolean(m_areaInfo); m_cvarCommons.m_debugOverlayAreaInfo->fromBoolean(m_areaInfo);
m_cvarMgr.serialize();
} }
if (ImGui::MenuItem("Random Stats", nullptr, &m_randomStats)) { if (ImGui::MenuItem("Random Stats", nullptr, &m_randomStats)) {
m_cvarCommons.m_debugOverlayShowRandomStats->fromBoolean(m_randomStats); m_cvarCommons.m_debugOverlayShowRandomStats->fromBoolean(m_randomStats);
m_cvarMgr.serialize();
} }
if (ImGui::MenuItem("Resource Stats", nullptr, &m_resourceStats)) { if (ImGui::MenuItem("Resource Stats", nullptr, &m_resourceStats)) {
m_cvarCommons.m_debugOverlayShowResourceStats->fromBoolean(m_resourceStats); m_cvarCommons.m_debugOverlayShowResourceStats->fromBoolean(m_resourceStats);
m_cvarMgr.serialize();
} }
ImGui::EndMenu(); ImGui::EndMenu();
} }