From a2117f8c25a059875f884b794977ed348c573537 Mon Sep 17 00:00:00 2001 From: Zero Fanker Date: Tue, 26 Mar 2024 23:21:54 -0400 Subject: [PATCH] roughly expanded overlay pic buffer to 0x1000, and added some safety guardian to avoid crash . --- MissionEditor/IniFile.cpp | 9 ++++++++- MissionEditor/IsoView.cpp | 15 +++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/MissionEditor/IniFile.cpp b/MissionEditor/IniFile.cpp index b1b1e66..63c7a16 100644 --- a/MissionEditor/IniFile.cpp +++ b/MissionEditor/IniFile.cpp @@ -238,8 +238,15 @@ CString* CIniFileSection::GetValue(std::size_t index) noexcept return NULL; auto i = values.begin(); - for (auto e = 0;e < index;e++) + for (auto e = 0; e < index; e++) { + if (i == values.end()) { + break; + } i++; + } + if (i == values.end()) { + return nullptr; + } return &i->second; } diff --git a/MissionEditor/IsoView.cpp b/MissionEditor/IsoView.cpp index 3e2830a..01da86d 100644 --- a/MissionEditor/IsoView.cpp +++ b/MissionEditor/IsoView.cpp @@ -65,7 +65,7 @@ void GetNodeName(CString& name, int n); /* --------- */ /* Overlay picture table (maximum overlay count=0xFF) */ -PICDATA* ovrlpics[0xFF][max_ovrl_img]; +PICDATA* ovrlpics[0x1000][max_ovrl_img]; // cancel draw flag BOOL bCancelDraw = FALSE; @@ -5911,11 +5911,14 @@ void CIsoView::DrawMap() { if (!pic.bTried) { - SetError("Loading graphics"); - theApp.m_loading->LoadOverlayGraphic(*rules.sections["OverlayTypes"].GetValue(m.overlay), m.overlay); - UpdateOverlayPictures(m.overlay); - if (ovrlpics[m.overlay][m.overlaydata] != NULL) - pic = *ovrlpics[m.overlay][m.overlaydata]; + if (auto const pOverlayId = rules.sections["OverlayTypes"].GetValue(m.overlay)) { + SetError("Loading graphics"); + theApp.m_loading->LoadOverlayGraphic(*pOverlayId, m.overlay); + UpdateOverlayPictures(m.overlay); + if (ovrlpics[m.overlay][m.overlaydata] != NULL) { + pic = *ovrlpics[m.overlay][m.overlaydata]; + } + } } if (pic.pic == NULL)