Fix crash when changing dimensions in certain API callbacks

This commit is contained in:
GriffinR 2025-08-06 16:41:31 -04:00
parent bc9fbe6e72
commit 5da0655a15
3 changed files with 19 additions and 6 deletions

View File

@ -31,6 +31,7 @@ and this project somewhat adheres to [Semantic Versioning](https://semver.org/sp
### Fixed
- Fix crash when rendering tiles with invalid palette numbers.
- Fix crash when opening the Tileset Editor for tilesets with no metatiles.
- Fix crash when changing the map/border size in certain API callbacks.
- Fix metatile images exporting at 2x scale.
- Fix display errors when a project's metatile limits are not divisible by 8.
- Fix incorrect dividing line position for primary tiles images that are smaller than the maximum size.

View File

@ -59,6 +59,7 @@ public:
// Scripting API
Q_INVOKABLE QJSValue getBlock(int x, int y);
void tryRedrawMapArea(bool forceRedraw);
void redrawResizedMapArea();
void tryCommitMapChanges(bool commitChanges);
Q_INVOKABLE void setBlock(int x, int y, int metatileId, int collision, int elevation, bool forceRedraw = true, bool commitChanges = true);
Q_INVOKABLE void setBlock(int x, int y, int rawValue, bool forceRedraw = true, bool commitChanges = true);

View File

@ -41,6 +41,17 @@ void MainWindow::tryRedrawMapArea(bool forceRedraw) {
}
}
void MainWindow::redrawResizedMapArea() {
// We're calling this on a timer because we want to defer the redraw
// until it's time to process events. This avoids some potential crashes,
// as redrawMapScene will destroy a handful of objects capable of triggering
// script API callbacks; we want to let them finish what they were doing
// before we destroying them.
// NOTE: This has the same problem as ScriptEditLayout, namely that it's
// doing more work than necessary and can be prohibitively slow.
QTimer::singleShot(0, this, &MainWindow::redrawMapScene);
}
void MainWindow::tryCommitMapChanges(bool commitChanges) {
if (commitChanges) {
Layout *layout = this->editor->layout;
@ -226,7 +237,7 @@ void MainWindow::setDimensions(int width, int height) {
return;
this->editor->layout->setDimensions(width, height);
this->tryCommitMapChanges(true);
this->redrawMapScene();
this->redrawResizedMapArea();
}
void MainWindow::setWidth(int width) {
@ -236,7 +247,7 @@ void MainWindow::setWidth(int width) {
return;
this->editor->layout->setDimensions(width, this->editor->layout->getHeight());
this->tryCommitMapChanges(true);
this->redrawMapScene();
this->redrawResizedMapArea();
}
void MainWindow::setHeight(int height) {
@ -246,7 +257,7 @@ void MainWindow::setHeight(int height) {
return;
this->editor->layout->setDimensions(this->editor->layout->getWidth(), height);
this->tryCommitMapChanges(true);
this->redrawMapScene();
this->redrawResizedMapArea();
}
//=====================
@ -296,7 +307,7 @@ void MainWindow::setBorderDimensions(int width, int height) {
return;
this->editor->layout->setBorderDimensions(width, height);
this->tryCommitMapChanges(true);
this->redrawMapScene();
this->redrawResizedMapArea();
}
void MainWindow::setBorderWidth(int width) {
@ -306,7 +317,7 @@ void MainWindow::setBorderWidth(int width) {
return;
this->editor->layout->setBorderDimensions(width, this->editor->layout->getBorderHeight());
this->tryCommitMapChanges(true);
this->redrawMapScene();
this->redrawResizedMapArea();
}
void MainWindow::setBorderHeight(int height) {
@ -316,7 +327,7 @@ void MainWindow::setBorderHeight(int height) {
return;
this->editor->layout->setBorderDimensions(this->editor->layout->getBorderWidth(), height);
this->tryCommitMapChanges(true);
this->redrawMapScene();
this->redrawResizedMapArea();
}
//======================