diff --git a/aniphallow.lua b/aniphallow.lua index a12a442..d3e9050 100644 --- a/aniphallow.lua +++ b/aniphallow.lua @@ -1616,6 +1616,8 @@ openPreviewWindow = function() local currentFile = app.sprite and app.sprite.filename or "" if currentFile ~= lastSpriteFilename then lastSpriteFilename = currentFile + -- Always refresh source when switching files + refreshSource() -- Look up preset for this file local presetForFile = filePresetMap[currentFile] or "Default" if presetForFile ~= S.currentPreset then @@ -1641,6 +1643,8 @@ openPreviewWindow = function() openMainDialog() end end + -- Always repaint preview on file change (even if preset is same) + pcall(function() previewDlg:repaint() end) end end } @@ -2656,13 +2660,25 @@ openMainDialog = function() text = "Analyze", visible = false, onclick = function() - if not S.sourceImage then - refreshSource() - end + -- Always refresh to avoid stale image from a different sprite + refreshSource() if not S.sourceImage then app.alert("No source image. Open a sprite first.") return end + -- Diagnostics + local diag = "mode=" .. S.gbAnalyzeMode .. + " tileW=" .. S.gbTileW .. " tileH=" .. S.gbTileH .. + " imgW=" .. tostring(S.sourceImage.width) .. + " imgH=" .. tostring(S.sourceImage.height) + if S.sourceImage.width == 0 or S.sourceImage.height == 0 then + app.alert("Source image has zero size. " .. diag) + return + end + if S.gbTileW < 1 or S.gbTileH < 1 then + app.alert("Bad tile size. " .. diag) + return + end local usedTileW = S.gbTileW local usedTileH = S.gbTileH if S.gbAnalyzeMode == "tile" then