Skip to content

Commit

Permalink
fix #149, prevent sheet overflow on anim editor
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonx254 committed Oct 4, 2024
1 parent dfaa414 commit 0faf89d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions RetroEDv2/tools/animationeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand All @@ -2399,7 +2399,8 @@ void AnimationEditor::SetupFrameList(QList<FormatHelpers::Animation::Frame> &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);
Expand Down
2 changes: 1 addition & 1 deletion RetroEDv2/tools/gameconfigeditorv5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QString>{ "GameConfig", filter == 1 ? "rev01" : "rev02" });
Expand Down

0 comments on commit 0faf89d

Please sign in to comment.