do more to avoid crashing in the editor

This commit is contained in:
Tim Felgentreff 2020-07-04 11:55:25 +02:00
parent 4f6b04e7e1
commit 7d97972c74
2 changed files with 24 additions and 11 deletions

View file

@ -168,9 +168,11 @@ static void EditorChangeSurrounding(const Vec2i &pos, const Vec2i &lock_pos)
unsigned q2 = QuadFromTile(pos + offset);
unsigned u = (q2 & TH_QUAD_M) | ((quad >> 16) & BH_QUAD_M);
if (u != q2 && (pos + offset) != lock_pos) {
did_change = true;
int tile = Map.Tileset->tileFromQuad(u & BH_QUAD_M, u);
EditorChangeTile(pos + offset, tile, lock_pos);
if (tile) {
did_change = true;
EditorChangeTile(pos + offset, tile, lock_pos);
}
}
}
}
@ -181,9 +183,11 @@ static void EditorChangeSurrounding(const Vec2i &pos, const Vec2i &lock_pos)
unsigned q2 = QuadFromTile(pos + offset);
unsigned u = (q2 & BH_QUAD_M) | ((quad << 16) & TH_QUAD_M);
if (u != q2 && (pos + offset) != lock_pos) {
did_change = true;
int tile = Map.Tileset->tileFromQuad(u & TH_QUAD_M, u);
EditorChangeTile(pos + offset, tile, lock_pos);
if (tile) {
did_change = true;
EditorChangeTile(pos + offset, tile, lock_pos);
}
}
}
}
@ -194,9 +198,11 @@ static void EditorChangeSurrounding(const Vec2i &pos, const Vec2i &lock_pos)
unsigned q2 = QuadFromTile(pos + offset);
unsigned u = (q2 & LH_QUAD_M) | ((quad >> 8) & RH_QUAD_M);
if (u != q2 && (pos + offset) != lock_pos) {
did_change = true;
int tile = Map.Tileset->tileFromQuad(u & RH_QUAD_M, u);
EditorChangeTile(pos + offset, tile, lock_pos);
if (tile) {
did_change = true;
EditorChangeTile(pos + offset, tile, lock_pos);
}
}
}
}
@ -207,9 +213,11 @@ static void EditorChangeSurrounding(const Vec2i &pos, const Vec2i &lock_pos)
unsigned q2 = QuadFromTile(pos + offset);
unsigned u = (q2 & RH_QUAD_M) | ((quad << 8) & LH_QUAD_M);
if (u != q2 && (pos + offset) != lock_pos) {
did_change = true;
int tile = Map.Tileset->tileFromQuad(u & LH_QUAD_M, u);
EditorChangeTile(pos + offset, tile, lock_pos);
if (tile) {
did_change = true;
EditorChangeTile(pos + offset, tile, lock_pos);
}
}
}
}

View file

@ -196,6 +196,7 @@
*/
PixelSize PixelTileSize(32, 32);
static const int TILE_PATH_MAX = 6;
/*----------------------------------------------------------------------------
-- Functions
@ -372,8 +373,11 @@ int CTileset::findTilePath(int base, int goal, int length, std::vector<char> &ma
*tileIndex = tileres;
return length;
}
if (length >= TILE_PATH_MAX) {
return TILE_PATH_MAX;
}
// Find any mixed tile
int l = INT_MAX;
int l = TILE_PATH_MAX;
for (size_t i = 0; i != tiles.size();) {
int j = 0;
if (base == tiles[i].tileinfo.BaseTerrain) {
@ -417,7 +421,8 @@ int CTileset::tileFromQuad(unsigned fixed, unsigned quad) const
while (!(type1 = (fixed & 0xFF))) {
fixed >>= 8;
if (!fixed) {
ExitFatal(-1);
DebugPrint("WARNING: No fixed tile found for %x" _C_ fixed);
return 0;
}
}
fixed >>= 8;
@ -467,7 +472,7 @@ int CTileset::tileFromQuad(unsigned fixed, unsigned quad) const
std::vector<char> marks;
marks.resize(getSolidTerrainCount(), 0);
marks[type1] = type1;
if (findTilePath(type1, type2, 0, marks, &tileIndex) == INT_MAX) {
if (findTilePath(type1, type2, 0, marks, &tileIndex) == TILE_PATH_MAX) {
DebugPrint("Huch, no mix found!!!!!!!!!!!\n");
const int res = findTileIndex(type1);
Assert(res != -1);