Quick answer: Call tilemap_clear(tm, 0) before a wholesale rebuild, then loop sets. Verify with tilemap_get immediately after to detect coordinate or layer ID errors.
Procedural map gen sets thousands of tiles. Some don’t appear. Cache + render order can race; clearing first is safe.
The Symptom
tilemap_set_cell calls return success but visual shows missing/wrong tiles. Restarting the room sometimes fixes; sometimes not.
The Fix
/// Procedural rebuild
tilemap_clear(tm, 0);
for (var y = 0; y < 100; ++y) {
for (var x = 0; x < 100; ++x) {
var tile = choose_tile_for(x, y);
tilemap_set(tm, tile, x, y);
}
}
Clear, then loop. Cache rebuilds cleanly because every cell is freshly written.
Verifying
Read back random cells immediately after set: tile = tilemap_get(tm, x, y). Should match what you wrote. Mismatch points to layer ID or coord system error.
“Clear before mass set. Verify reads match writes. Cache stays current.”
Related Issues
For network buffer fragmentation, see fragmentation. For surface lost, see surface lost.
Clear plus rebuild. Tiles render.