From 812848e38216048a826036d08d6d1ddefe1d8f5d Mon Sep 17 00:00:00 2001 From: fgenesis Date: Mon, 11 Jan 2021 19:26:32 +0100 Subject: [PATCH] Fix crash on startup --- Aquaria/SceneEditor.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Aquaria/SceneEditor.cpp b/Aquaria/SceneEditor.cpp index fc1ecbf..a5fba4a 100644 --- a/Aquaria/SceneEditor.cpp +++ b/Aquaria/SceneEditor.cpp @@ -2538,12 +2538,18 @@ void SceneEditor::prevElement() void SceneEditor::doPrevElement() { - int oldCur = curElement; - curElement--; - if (curElement >= game->elementTemplates.size()) - curElement = dsq->game->elementTemplates.size()-1; + size_t oldCur = curElement; + size_t maxn = dsq->game->elementTemplates.size(); - if (dsq->game->elementTemplates[curElement].idx < 1024) + if(curElement) + curElement--; + else if(maxn) + curElement = maxn-1; + + if (maxn && curElement >= maxn) + curElement = maxn-1; + + if (maxn && dsq->game->elementTemplates[curElement].idx < 1024) { placer->setTexture(dsq->game->elementTemplates[curElement].gfx); }