Render magenta placeholder when atlas is unloaded
When a consumer renders via maps.draw_map_pre/post_entities without having called maps.load_textures (or when asset-alias resolution failed), the per-atlas diffuse_texture_handle is nil. The previous draw_layer passed nil to draw_sprite_transform and crashed. Now it falls back to engine.render.draw_rect with the classic magenta missing-asset color so the consumer sees the gap visually instead. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
19
init.lua
19
init.lua
@@ -339,6 +339,9 @@ end
|
|||||||
|
|
||||||
-- Internal: draw all cells in one layer using atlas-handle + UV sampling.
|
-- Internal: draw all cells in one layer using atlas-handle + UV sampling.
|
||||||
-- (M.2: replaces per-tile texture_handle pattern with atlas-level handle.)
|
-- (M.2: replaces per-tile texture_handle pattern with atlas-level handle.)
|
||||||
|
-- Magenta-placeholder color (RGBA8888 0xFF00FFFF) for missing-asset draw paths.
|
||||||
|
local MISSING_ASSET_COLOR = 0xFFFF00FF
|
||||||
|
|
||||||
local function draw_layer(m, layer_name)
|
local function draw_layer(m, layer_name)
|
||||||
local layer = m.layers[layer_name]
|
local layer = m.layers[layer_name]
|
||||||
if not layer then return end
|
if not layer then return end
|
||||||
@@ -351,11 +354,11 @@ local function draw_layer(m, layer_name)
|
|||||||
if gid ~= 0 then
|
if gid ~= 0 then
|
||||||
local atlas_idx, tile_id, rot_quad = decode_gid(gid)
|
local atlas_idx, tile_id, rot_quad = decode_gid(gid)
|
||||||
local atlas = m.atlases[atlas_idx + 1]
|
local atlas = m.atlases[atlas_idx + 1]
|
||||||
if atlas then
|
local px = x * ts
|
||||||
|
local py = y * ts
|
||||||
|
if atlas and atlas.diffuse_texture_handle then
|
||||||
local tile = atlas.tiles[tile_id]
|
local tile = atlas.tiles[tile_id]
|
||||||
if tile then
|
if tile and tile.uv then
|
||||||
local px = x * ts
|
|
||||||
local py = y * ts
|
|
||||||
local rot_deg = rot_quad * 90.0
|
local rot_deg = rot_quad * 90.0
|
||||||
engine.render.draw_sprite_transform(
|
engine.render.draw_sprite_transform(
|
||||||
atlas.diffuse_texture_handle,
|
atlas.diffuse_texture_handle,
|
||||||
@@ -366,7 +369,15 @@ local function draw_layer(m, layer_name)
|
|||||||
0xFFFFFFFF,
|
0xFFFFFFFF,
|
||||||
tile.uv.x, tile.uv.y, tile.uv.w, tile.uv.h
|
tile.uv.x, tile.uv.y, tile.uv.w, tile.uv.h
|
||||||
)
|
)
|
||||||
|
else
|
||||||
|
-- Tile-record missing or no uv: magenta placeholder.
|
||||||
|
engine.render.draw_rect(px, py, ts, ts, MISSING_ASSET_COLOR)
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
-- Atlas not loaded (load_textures was never called, or asset
|
||||||
|
-- alias resolution returned nil): magenta placeholder so the
|
||||||
|
-- consumer sees the missing-asset visually instead of crashing.
|
||||||
|
engine.render.draw_rect(px, py, ts, ts, MISSING_ASSET_COLOR)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user