Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(sprite): enforce tile budgets before integer conversion

yhh43af0e665257
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 5b76a1904..ab7e3c529 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -930,6 +930,11 @@ jobs:
- name: Build the Linux host and its runtime template
run: node build-tools/cli.js native --target linux
+ - name: Run native renderer regressions
+ run: |
+ cmake --build build/cmake/native-linux --target test_native_renderer --parallel 4
+ build/cmake/native-linux/test_native_renderer
+
- name: A game packaged from it renders
run: |
ls -l /usr/share/vulkan/icd.d/ || true
@@ -986,6 +991,12 @@ jobs:
- name: Build the Windows host and its runtime template
run: node build-tools/cli.js native --target windows
+ - name: Run native renderer regressions
+ shell: bash
+ run: |
+ cmake --build build/cmake/native-windows --target test_native_renderer --parallel 4
+ ./build/cmake/native-windows/test_native_renderer.exe
+
# No xvfb and no software driver: a Windows runner has a desktop and a
# D3D12 device of its own, which is what the release job relies on too.
- name: A game packaged from it renders
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8427d7fd6..1eeb68d55 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,8 @@ published separately; it ships inside the editor.
### Fixed
+- **Extreme sprite tile counts reach the bounded fallback on native hosts.** Tile budgets are checked in floating point before converting loop counts to integers, preventing overflowing axes from bypassing the existing 16,384-quad cap. Tiny positive steps retain the single stretched quad; non-finite tile steps and sizes emit no geometry, and grids at the cap remain tiled.
+
- **Sprites retain parent-induced shear in every draw mode.** Ordinary, nine-slice and tiled geometry follows the complete parent transform, and camera bounds use the same basis. Mirrored tiled grids retain positive tile steps before applying signed axes, including the capped fallback. Zero-area sprites skip geometry; existing material, UV and batch state is preserved.
## [0.82.0] - 2026-10-14
diff --git a/native/CMakeLists.txt b/native/CMakeLists.txt
index 0213e3ed3..5b1e6f510 100644
--- a/native/CMakeLists.txt
+++ b/native/CMakeLists.txt
@@ -264,6 +264,13 @@ target_compile_definitions(esengine PUBLIC # NOT ES_PLATFORM_WEB
ES_ENABLE_TILEMAP ES_ENABLE_PARTICLES ES_ENABLE_POSTPROCESS ES_ENABLE_SPINE)
target_link_libraries(esengine PUBLIC glm yogacore webgpu_dawn)
+if(ESTELLA_DESKTOP)
+ add_executable(test_native_renderer EXCLUDE_FROM_ALL
+ "${REPO}/tests/renderer/test_batch_builder.cpp")
+ target_include_directories(test_native_renderer PRIVATE "${TP}/doctest")
+ target_link_libraries(test_native_renderer PRIVATE esengine)
+endif()
+
# The host (opt-in): a QuickJS runtime drives the engine through the EHT-generated
# bindings + the real SDK. Built only when QuickJS is provided; the
# `node build-tools/cli.js native --quickjs <dir>` orchestration fetches QuickJS,
diff --git a/src/esengine/renderer/plugins/SpritePlugin.cpp b/src/esengine/renderer/plugins/SpritePlugin.cpp
index fcdc63f63..e99a9da92 100644
--- a/src/esengine/renderer/plugins/SpritePlugin.cpp
+++ b/src/esengine/renderer/plugins/SpritePlugin.cpp
@@ -194,9 +194,12 @@ void SpritePlugin::emitTiledQuads(
const BatchDrawKey& key
) {
glm::vec2 step = tileSize + tileSpacing;
- if (step.x <= 0.0f || step.y <= 0.0f) return;
+ if (step.x <= 0.0f || step.y <= 0.0f
+ || !std::isfinite(step.x) || !std::isfinite(step.y)
+ || !std::isfinite(tileSize.x) || !std::isfinite(tileSize.y)) return;
glm::vec2 absSize = glm::vec2(std::abs(size.x), std::abs(size.y));
+ if (!std::isfinite(absSize.x) || !std::isfinite(absSize.y)) return;
f32 baseX = position.x - absSize.x * pivot.x;
f32 baseY = position.y - absSize.y * pivot.y;
@@ -210,14 +213,14 @@ void SpritePlugin::emitTiledQuads(
u32 pc = packColor(color);
- i32 tilesY = static_cast<i32>(std::ceil(absSize.y / step.y));
- i32 tilesX = static_cast<i32>(std::ceil(absSize.x / step.x));
+ const f64 countY = std::ceil(static_cast<f64>(absSize.y) / step.y);
+ const f64 countX = std::ceil(static_cast<f64>(absSize.x) / step.x);
- // A huge size with a tiny tile step (bad data or a typo in the inspector)
- // would otherwise emit billions of quads and freeze the frame. Degrade to a
- // single stretched quad past a generous cap.
- constexpr i64 kMaxTiledQuads = 16384;
- if (static_cast<i64>(tilesX) * static_cast<i64>(tilesY) > kMaxTiledQuads) {
+ // Bound counts before integer conversion, which can turn overflowing native
+ // counts negative. Grids above the cap use one stretched quad.
+ constexpr f64 kMaxTiledQuads = 16384;
+ if (countX > kMaxTiledQuads || countY > kMaxTiledQuads
+ || countX * countY > kMaxTiledQuads) {
BatchVertex verts[4];
if (hasRotation) {
verts[0] = { rotatePoint(position, baseX, baseY, cosA, sinA), pc, { uvOffset.x, uvOffset.y } };
@@ -234,6 +237,9 @@ void SpritePlugin::emitTiledQuads(
return;
}
+ const i32 tilesX = static_cast<i32>(countX);
+ const i32 tilesY = static_cast<i32>(countY);
+
for (i32 iy = 0; iy < tilesY; ++iy) {
f32 ty = static_cast<f32>(iy) * step.y;
f32 th = glm::min(tileSize.y, absSize.y - ty);
diff --git a/tests/renderer/test_batch_builder.cpp b/tests/renderer/test_batch_builder.cpp
index e2dd68fda..b0e4c049d 100644
--- a/tests/renderer/test_batch_builder.cpp
+++ b/tests/renderer/test_batch_builder.cpp
@@ -28,6 +28,7 @@
#include "esengine/ecs/components/Hierarchy.hpp"
#include <functional>
+#include <limits>
#include <utility>
#include <vector>
@@ -367,6 +368,52 @@ TEST_CASE("sprites: affine parents preserve every draw mode and mirrored tile gr
}
}
+TEST_CASE("sprites: tile budget applies before integer conversion") {
+ struct Case { glm::vec2 tile, spacing; u32 quads; };
+ const Case cases[] = {
+ {{1e-20f, 1}, {}, 1},
+ {{1, 1e-20f}, {}, 1},
+ {{std::numeric_limits<f32>::denorm_min(), 1}, {}, 1},
+ {{1e-20f, 1e-20f}, {}, 1},
+ {{1, 1}, {}, 16384},
+ {{.5f, 1}, {}, 1},
+ {{1, 1}, {-1, 0}, 0},
+ {{1, 1}, {std::numeric_limits<f32>::quiet_NaN(), 0}, 0},
+ {{1, 1}, {std::numeric_limits<f32>::infinity(), 0}, 0},
+ };
+ for (const auto& item : cases) {
+ Harness h;
+ RenderContext context(h.device);
+ resource::ResourceManager resources;
+ resources.init(h.device);
+ ecs::Registry registry;
+ const auto entity = registry.create();
+ auto& transform = registry.emplace<ecs::Transform>(entity);
+ transform.worldScale = {1, 1, 1};
+ transform.decomposed_ = true;
+ auto& sprite = registry.emplace<ecs::Sprite>(entity);
+ sprite.size = {128, 128};
+ sprite.tileSize = item.tile;
+ sprite.tileSpacing = item.spacing;
+ sprite.drawMode = ecs::SpriteDrawMode::Tiled;
+ Frustum frustum;
+ frustum.extractFromMatrix(glm::ortho(-500.0f, 500.0f, -500.0f, 500.0f));
+ RenderFrameContext frameContext{context, resources};
+ RenderCollectContext collect{registry, frustum, h.clips, h.pool, h.list, frameContext, {}};
+ SpritePlugin plugin;
+ plugin.init(frameContext);
+ plugin.collect(collect);
+ CHECK(h.pool.vertexBytesUsed(LayoutId::Batch) == item.quads * 4 * sizeof(BatchVertex));
+ const auto* vertices = reinterpret_cast<const BatchVertex*>(h.pool.vertexData(LayoutId::Batch));
+ bool finite = true;
+ for (u32 i = 0; i < h.pool.vertexBytesUsed(LayoutId::Batch) / sizeof(BatchVertex); ++i) {
+ finite = finite && std::isfinite(vertices[i].position.x) && std::isfinite(vertices[i].position.y);
+ }
+ CHECK(finite);
+ resources.shutdown();
+ }
+}
+
TEST_CASE("bitmap text: world geometry follows affine transforms and parallax") {
for (u32 kind : {0u, 1u, 2u}) {
const bool alignedEdge = kind == 1, rootWithoutMatrix = kind == 2;
@@ -1454,15 +1501,15 @@ TEST_CASE("order: a higher order draws on top of a nearer sprite") {
Harness h;
BatchVertex quad[4] = {};
- BatchDrawKey near = quadKey(1, /*layer=*/3);
- near.depth = 50.0f; // nearest — depth alone would put it last
- BatchDrawKey far = quadKey(2, /*layer=*/3);
- far.depth = -50.0f;
- far.order = 1;
- far.shaderId = 8;
+ BatchDrawKey nearer = quadKey(1, /*layer=*/3);
+ nearer.depth = 50.0f; // nearest — depth alone would put it last
+ BatchDrawKey farther = quadKey(2, /*layer=*/3);
+ farther.depth = -50.0f;
+ farther.order = 1;
+ farther.shaderId = 8;
- appendQuad(h.pool, h.list, h.clips, quad, near);
- appendQuad(h.pool, h.list, h.clips, quad, far);
+ appendQuad(h.pool, h.list, h.clips, quad, nearer);
+ appendQuad(h.pool, h.list, h.clips, quad, farther);
h.list.finalize(h.pool);
REQUIRE(h.list.mergedDrawCallCount() == 2);
@@ -1728,21 +1775,21 @@ TEST_CASE("transparent: back-to-front holds across materials") {
BatchVertex quad[4] = {};
// Camera looks down -z, so larger z is nearer and must land last.
- BatchDrawKey near = quadKey(1, /*layer=*/3);
- near.materialId = 1; // lowest material — would have sorted first
- near.depth = 50.0f;
+ BatchDrawKey nearer = quadKey(1, /*layer=*/3);
+ nearer.materialId = 1; // lowest material — would have sorted first
+ nearer.depth = 50.0f;
BatchDrawKey middle = quadKey(2, /*layer=*/3);
middle.materialId = 90000;
middle.depth = 0.0f;
- BatchDrawKey far = quadKey(3, /*layer=*/3);
- far.materialId = 500;
- far.depth = -50.0f;
+ BatchDrawKey farther = quadKey(3, /*layer=*/3);
+ farther.materialId = 500;
+ farther.depth = -50.0f;
- appendQuad(h.pool, h.list, h.clips, quad, near);
+ appendQuad(h.pool, h.list, h.clips, quad, nearer);
appendQuad(h.pool, h.list, h.clips, quad, middle);
- appendQuad(h.pool, h.list, h.clips, quad, far);
+ appendQuad(h.pool, h.list, h.clips, quad, farther);
h.list.finalize(h.pool);
REQUIRE(h.list.mergedDrawCallCount() == 3);
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index 39b5c8135..6f1cbc69a 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -28,6 +28,8 @@ export const NOTES_FLOOR = 'v0.65.0';
* the reader recognises anyway.
*/
export const NOTED = {
+ 'fix(sprite): enforce tile budgets before integer conversion':
+ { note: 'Extreme sprite tile counts reach the bounded fallback on native hosts.' },
'fix(sprite): preserve affine geometry and mirrored tile grids':
{ note: 'Sprites retain parent-induced shear in every draw mode.' },
'fix(text): preserve long bitmap strings and cull hidden glyphs':