From 95eee996e13606608257e1ba7702b90b3ef58856 Mon Sep 17 00:00:00 2001 From: WaruGameDev <60048774+WaruGameDev@users.noreply.github.com> Date: Mon, 23 Nov 2026 10:33:07 -0300 Subject: [PATCH 1/2] Tilemap rects without a texture path use the mesh texture Tilemap::addRect only creates a submesh when it gets a texture path. With the texture set by Mesh::setTexture (a path or TextureData) and rects added without one, numSubmeshes stayed 0 and createTilemap skipped every tile, with no error. createTilemap now counts submesh 0, where setTexture puts the texture, when the tilemap has rects and no submesh. Co-Authored-By: Claude Opus 5.5 --- engine/core/subsystem/MeshSystem.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/engine/core/subsystem/MeshSystem.cpp b/engine/core/subsystem/MeshSystem.cpp index e8a8653e3..4dae4b47b 100644 --- a/engine/core/subsystem/MeshSystem.cpp +++ b/engine/core/subsystem/MeshSystem.cpp @@ -681,6 +681,13 @@ bool MeshSystem::createTilemap(TilemapComponent& tilemap, MeshComponent& mesh){ // Calling load() unconditionally would instead re-read every already-uploaded // (and released) tile texture from disk on each rebuild, spinning an endless // load loop. + // A rect added without a texture path uses submesh 0, the texture set by + // Mesh::setTexture (a path or TextureData). Only addRect with a path creates + // submeshes, so without one the count stayed 0 and every tile was skipped. + if (mesh.numSubmeshes == 0 && tilemap.numTilesRect > 0){ + mesh.numSubmeshes = 1; + } + // before the first load, see RenderSystem::loadMesh for (int s = 0; s < mesh.numSubmeshes; s++){ mesh.submeshes[s].material.baseColorTexture.setAlphaBorderAuto(true); From e69a828f706831750acf150fd90e4fbc6f2222e8 Mon Sep 17 00:00:00 2001 From: WaruGameDev <60048774+WaruGameDev@users.noreply.github.com> Date: Mon, 23 Nov 2026 14:35:43 -0300 Subject: [PATCH 2/2] tilemap: wait for the mesh texture before building rects without a submesh createTilemap waits for a tile's texture to know its size before it normalizes pixel rects, but it skipped the rects without a submesh of their own (submeshId -1), the ones drawn with submesh 0. A scene loaded from file then built the mesh before the texture size arrived, kept the pixel rects and drew the whole texture in every tile. Co-Authored-By: Claude Opus 5.5 --- engine/core/subsystem/MeshSystem.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/engine/core/subsystem/MeshSystem.cpp b/engine/core/subsystem/MeshSystem.cpp index 4dae4b47b..710071a69 100644 --- a/engine/core/subsystem/MeshSystem.cpp +++ b/engine/core/subsystem/MeshSystem.cpp @@ -705,10 +705,10 @@ bool MeshSystem::createTilemap(TilemapComponent& tilemap, MeshComponent& mesh){ preReserveTiles--; } TileRectData& rectData = tilemap.tilesRect[tilemap.tiles[i].rectId]; - if (rectData.submeshId < 0 || (unsigned int)rectData.submeshId >= mesh.numSubmeshes){ - continue; - } - Texture& texture = mesh.submeshes[rectData.submeshId].material.baseColorTexture; + // a rect without a submesh of its own uses submesh 0 (as below), so it waits for that texture too: + // built before its size is known, its pixel rect would not be normalized + const int submeshId = (rectData.submeshId >= 0 && (unsigned int)rectData.submeshId < mesh.numSubmeshes) ? rectData.submeshId : 0; + Texture& texture = mesh.submeshes[submeshId].material.baseColorTexture; Texture& mainTexture = mesh.submeshes[0].material.baseColorTexture; Texture* tileTexture = !texture.empty() ? &texture : (!mainTexture.empty() ? &mainTexture : nullptr); if (tileTexture && tileTexture->getWidth() == 0){