From 09f3cc4096e0677c002b9d58177768d7b59e1121 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Wed, 8 May 2024 01:24:01 +0200 Subject: [PATCH] editor: forgot to create tile repeat data when setting flag, causing a crash --- BBGE/Tile.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/BBGE/Tile.cpp b/BBGE/Tile.cpp index 50b6d5d..357fecf 100644 --- a/BBGE/Tile.cpp +++ b/BBGE/Tile.cpp @@ -212,11 +212,16 @@ void TileStorage::setEffect(const TileEffectStorage& effstore, int idx, const si void TileStorage::changeFlags(unsigned flagsToSet, unsigned flagsToUnset, const size_t* indices, size_t n) { + assert(!(flagsToSet & flagsToUnset)); // don't set and unset flag at the same time + const unsigned unsetMask = ~flagsToUnset; + const unsigned setRep = flagsToSet & TILEFLAG_REPEAT; for(size_t i = 0; i < n; ++i) { - unsigned& f = tiles[indices[i]].flags; - unsigned tmp = f & ~flagsToUnset; - f = tmp | flagsToSet; + TileData& t = tiles[indices[i]]; + unsigned tmp = t.flags & unsetMask; + t.flags = tmp | flagsToSet; + if(setRep && !t.rep) // setting the flag does not create the attached data, do that if necessary + t.setRepeatOn(); } } @@ -715,6 +720,7 @@ void TileData::setRepeatOff() void TileData::refreshRepeat() { + assert(!(flags & TILEFLAG_REPEAT) || rep); if(rep) { rep->refresh(*this); @@ -729,6 +735,7 @@ bool TileData::hasStandardTexcoords() const const TexCoordBox& TileData::getTexcoords() const { + assert(!(flags & TILEFLAG_REPEAT) || rep); return !(flags & TILEFLAG_REPEAT) ? et->tc : rep->grid.getTexCoords();