Fix potential out of bounds map layout read
Some checks failed
Build Porymap / build-linux (5.14.2) (push) Has been cancelled
Build Porymap / build-linux (6.8.2) (push) Has been cancelled
Build Porymap / build-macos (macos-15-intel) (push) Has been cancelled
Build Porymap / build-macos (macos-latest) (push) Has been cancelled
Build Porymap / build-static-windows (push) Has been cancelled

This commit is contained in:
GriffinR 2025-11-22 14:04:40 -05:00
parent 97bf444b64
commit ea8de4df76
3 changed files with 17 additions and 15 deletions

View File

@ -16,6 +16,7 @@ and this project somewhat adheres to [Semantic Versioning](https://semver.org/sp
- Previously, the middle mouse button could be used as a shortcut with the pencil tool to switch to bucket-fill mode. This is now achieved using the `Alt` key.
### Fixed
- Fix potential crash when painting and the cursor leaves the map area.
- Fix rare crash while quitting Porymap.
- Fix `Edit > Clear Map Entries` in the Region Map Editor not saving the applied changes.
- Fix `Edit > Undo/Redo` appearing enabled even when they don't do anything.

View File

@ -125,7 +125,9 @@ public:
bool isWithinBorderBounds(int x, int y) const;
bool getBlock(int x, int y, Block *out) const;
bool getBlock(const QPoint& pos, Block *out) const { return getBlock(pos.x(), pos.y(), out); }
void setBlock(int x, int y, Block block, bool enableScriptCallback = false);
void setBlock(const QPoint& pos, Block block, bool enableScriptCallback = false) { setBlock(pos.x(), pos.y(), block, enableScriptCallback); }
void setBlockdata(Blockdata blockdata, bool enableScriptCallback = false);
uint16_t getMetatileId(int x, int y) const;

View File

@ -1244,28 +1244,27 @@ void Editor::onMapHoverCleared() {
}
void Editor::setStatusFromMapPos(const QPoint &pos) {
int x = pos.x();
int y = pos.y();
Block block;
if (!this->layout || !this->layout->getBlock(pos, &block)) {
ui->statusBar->clearMessage();
return;
}
if (this->editMode == EditMode::Metatiles) {
int blockIndex = y * layout->getWidth() + x;
int metatileId = layout->blockdata.at(blockIndex).metatileId();
this->ui->statusBar->showMessage(QString("X: %1, Y: %2, %3, Scale = %4x")
.arg(x)
.arg(y)
.arg(getMetatileDisplayMessage(metatileId))
.arg(pos.x())
.arg(pos.y())
.arg(getMetatileDisplayMessage(block.metatileId()))
.arg(QString::number(zoomLevels[this->scaleIndex], 'g', 2)));
} else if (this->editMode == EditMode::Collision) {
int blockIndex = y * layout->getWidth() + x;
uint16_t collision = layout->blockdata.at(blockIndex).collision();
uint16_t elevation = layout->blockdata.at(blockIndex).elevation();
this->ui->statusBar->showMessage(QString("X: %1, Y: %2, %3")
.arg(x)
.arg(y)
.arg(this->getMovementPermissionText(collision, elevation)));
.arg(pos.x())
.arg(pos.y())
.arg(this->getMovementPermissionText(block.collision(), block.elevation())));
} else if (this->editMode == EditMode::Events) {
this->ui->statusBar->showMessage(QString("X: %1, Y: %2, Scale = %3x")
.arg(x)
.arg(y)
.arg(pos.x())
.arg(pos.y())
.arg(QString::number(zoomLevels[this->scaleIndex], 'g', 2)));
}
}