From 0faf89d289f592db91b1682f8554ccd336b9e518 Mon Sep 17 00:00:00 2001 From: Leonx254 Date: Fri, 4 Oct 2024 02:00:50 -0300 Subject: [PATCH] fix #149, prevent sheet overflow on anim editor --- RetroEDv2/tools/animationeditor.cpp | 11 ++++++----- RetroEDv2/tools/gameconfigeditorv5.cpp | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/RetroEDv2/tools/animationeditor.cpp b/RetroEDv2/tools/animationeditor.cpp index d9fb1e4..bfaf9b4 100644 --- a/RetroEDv2/tools/animationeditor.cpp +++ b/RetroEDv2/tools/animationeditor.cpp @@ -2249,7 +2249,7 @@ void AnimationEditor::UpdateView() if (currentAnim < animFile.animations.count() && currentFrame < FrameCount()) { FormatHelpers::Animation::Frame &frame = animFile.animations[currentAnim].frames[currentFrame]; - if (frame.width && frame.height && frame.sheet < sheets.count()) { + if (frame.sheet < sheets.count() && frame.width + frame.sprX <= sheets[frame.sheet].width() && frame.height + frame.sprY <= sheets[frame.sheet].height()) { QRect boundingRect(frame.sprX, frame.sprY, frame.width, frame.height); QImage frameImg = sheets[frame.sheet].copy(boundingRect); @@ -2381,10 +2381,10 @@ void AnimationEditor::SetFramePreview(bool update) if (currentFrame < FrameCount()) { FormatHelpers::Animation::Frame &f = animFile.animations[currentAnim].frames[currentFrame]; QRect boundingRect(f.sprX, f.sprY, f.width, f.height); - frameModel->itemFromIndex(frameModel->index(currentFrame, 0)) - ->setData((f.width == 0 || f.height == 0 || - f.sheet >= sheets.count()) ? missingImg : QPixmap::fromImage(sheets[f.sheet].copy(boundingRect)), + ->setData((f.sheet >= sheets.count() || f.width == 0 || f.height == 0 + || f.width + f.sprX > sheets[f.sheet].width() || f.height + f.sprY > sheets[f.sheet].height()) + ? missingImg : QPixmap::fromImage(sheets[f.sheet].copy(boundingRect)), ROLE_PIXMAP); } if (update) @@ -2399,7 +2399,8 @@ void AnimationEditor::SetupFrameList(QList &fra QStandardItem *item = new QStandardItem; item->setEditable(false); - item->setData((f.width == 0 || f.height == 0 || f.sheet >= sheets.count()) + item->setData((f.sheet >= sheets.count() || f.width == 0 || f.height == 0 + || f.width + f.sprX > sheets[f.sheet].width() || f.height + f.sprY > sheets[f.sheet].height()) ? missingImg : QPixmap::fromImage(sheets[f.sheet].copy(boundingRect)), ROLE_PIXMAP); diff --git a/RetroEDv2/tools/gameconfigeditorv5.cpp b/RetroEDv2/tools/gameconfigeditorv5.cpp index 3050ca0..0514482 100644 --- a/RetroEDv2/tools/gameconfigeditorv5.cpp +++ b/RetroEDv2/tools/gameconfigeditorv5.cpp @@ -1213,7 +1213,7 @@ bool GameConfigEditorv5::event(QEvent *event) case 1: { SetStatus("Saving GameConfig...", true); - gameConfig.readFilter = filter == 3; + gameConfig.readFilter = filter == 0; appConfig.addRecentFile( ENGINE_v5, TOOL_GAMECONFIGEDITOR, filepath, QList{ "GameConfig", filter == 1 ? "rev01" : "rev02" });