From f3ae9674f18da247b73e8822190697f4dfdb9bfa Mon Sep 17 00:00:00 2001 From: jacob Date: Thu, 12 Feb 2026 19:03:55 -0600 Subject: [PATCH] fix texture atlas bounds check --- src/glyph_cache/glyph_cache.c | 14 +++++++------- src/pp/pp_vis/pp_vis_core.c | 10 +--------- src/sprite/sprite.c | 14 +++++++------- 3 files changed, 15 insertions(+), 23 deletions(-) diff --git a/src/glyph_cache/glyph_cache.c b/src/glyph_cache/glyph_cache.c index a82cc493..48a9f213 100644 --- a/src/glyph_cache/glyph_cache.c +++ b/src/glyph_cache/glyph_cache.c @@ -324,22 +324,22 @@ void GC_TickAsync(WaveLaneCtx *lane, AsyncFrameLaneCtx *base_async_lane_frame) SllStackPush(GC.first_atlas, atlas); ++GC.atlases_count; } - // Determine pos in atlas - pos_in_atlas = atlas->cur_pos; - atlas->cur_row_height = MaxI32(atlas->cur_row_height, image_dims.y); - if (pos_in_atlas.x + image_dims.x > atlas->dims.x) + if (atlas->cur_pos.x + image_dims.x > atlas->dims.x) { atlas->cur_pos.x = 0; atlas->cur_pos.y += atlas->cur_row_height; - atlas->cur_row_height = image_dims.y; + atlas->cur_row_height = 0; } - atlas->cur_pos.x += image_dims.x; - if (atlas->cur_pos.x < atlas->dims.x && atlas->cur_pos.y < atlas->dims.y) + if (atlas->cur_pos.x + image_dims.x < atlas->dims.x && atlas->cur_pos.y + image_dims.y < atlas->dims.y) { + pos_in_atlas = atlas->cur_pos; + atlas->cur_row_height = MaxI32(atlas->cur_row_height, image_dims.y); + atlas->cur_pos.x += image_dims.x; can_use_atlas = 1; } else { + // New atlas required atlas = 0; } } diff --git a/src/pp/pp_vis/pp_vis_core.c b/src/pp/pp_vis/pp_vis_core.c index 2ef584d5..730826c6 100644 --- a/src/pp/pp_vis/pp_vis_core.c +++ b/src/pp/pp_vis/pp_vis_core.c @@ -4960,17 +4960,9 @@ void V_TickForever(WaveLaneCtx *lane) ////////////////////////////// //- End frame - i32 vsync = !!TweakBool("Vsync", 1); - - // { - // Arena *old_arena = sim_output->arena; - // ZeroStruct(sim_output); - // sim_output->arena = old_arena; - // ResetArena(sim_output->arena); - // } - G_CommitCommandList(frame->cl); + i32 vsync = !!TweakBool("Vsync", 1); UI_EndFrame(ui_frame, vsync); } diff --git a/src/sprite/sprite.c b/src/sprite/sprite.c index 79b0a630..a81d2b5b 100644 --- a/src/sprite/sprite.c +++ b/src/sprite/sprite.c @@ -447,22 +447,22 @@ void SPR_TickAsync(WaveLaneCtx *lane, AsyncFrameLaneCtx *base_async_lane_frame) SllStackPush(SPR.first_atlas, atlas); ++SPR.atlases_count; } - // Determine pos in atlas - atlas_pos = atlas->cur_pos; - atlas->cur_row_height = MaxI32(atlas->cur_row_height, slice_dims.y); - if (atlas_pos.x + slice_dims.x > atlas->dims.x) + if (atlas->cur_pos.x + slice_dims.x > atlas->dims.x) { atlas->cur_pos.x = 0; atlas->cur_pos.y += atlas->cur_row_height; - atlas->cur_row_height = slice_dims.y; + atlas->cur_row_height = 0; } - atlas->cur_pos.x += slice_dims.x; - if (atlas->cur_pos.x < atlas->dims.x && atlas->cur_pos.y < atlas->dims.y) + if (atlas->cur_pos.x + slice_dims.x < atlas->dims.x && atlas->cur_pos.y + slice_dims.y < atlas->dims.y) { + atlas_pos = atlas->cur_pos; + atlas->cur_row_height = MaxI32(atlas->cur_row_height, slice_dims.y); + atlas->cur_pos.x += slice_dims.x; can_use_atlas = 1; } else { + // New atlas required atlas = 0; } }