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(ui): preserve traversal spans for large subtrees

yhhfe68557a28a3
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 452d9a95b..f0d01ae16 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -27,7 +27,7 @@ env:
test_ecs test_events test_particle test_tilemap test_tilemap_context test_sparse_set
test_resource_pool test_shader_variant test_log_format test_registry_safety
test_registry_ondestroy test_view_api_matrix
- test_hierarchy_links test_entity_activity test_transform_traversal test_tween_activity
+ test_hierarchy_links test_entity_activity test_transform_traversal test_ui_tree test_tween_activity
test_shader_device test_draw_params test_per_draw_blocks test_texture_fb test_buffer_device
test_compressed_format test_batch_builder test_skeletal_batch_color test_boundary_span test_webgpu_device
test_clip_depth test_sort_key test_sprite_mask_range test_sprite_draw_mode test_shadow_atlas test_particle_shapes test_lod_selection test_hdr_format test_probe_store test_occlusion_view test_reflection_store
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f1b73e0b6..37c8da530 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,8 @@ published separately; it ships inside the editor.
### Fixed
+- **Large UI subtrees keep their full traversal span.** Subtree lengths no longer wrap at 65536 nodes, preventing layout and visibility walks from freezing or skipping content at the 16-bit boundary.
+
- **Static UI layout preserves composed world transforms.** Clean early and late layout passes keep the transform cache valid, and the SDK composes through the shared change-aware path. Moving a screen box, changing layout properties, tweening, and structural edits still invalidate the affected composition.
- **Touch hit caches release ended pointer IDs.** Long-running touch sessions retain only the pointers present in the current input frame, including release-frame results needed by quick taps, instead of accumulating every historical finger ID.
diff --git a/src/esengine/ui/UITree.hpp b/src/esengine/ui/UITree.hpp
index fd2ad37d0..f95503d0f 100644
--- a/src/esengine/ui/UITree.hpp
+++ b/src/esengine/ui/UITree.hpp
@@ -28,7 +28,7 @@ struct UITree {
Entity entity;
Entity parent;
u16 depth;
- u16 subtree_size;
+ u32 subtree_size;
};
std::vector<Node> nodes_;
@@ -76,7 +76,7 @@ private:
}
if (isLayoutNode && nodeIndex >= 0) {
- nodes_[nodeIndex].subtree_size = static_cast<u16>(nodes_.size() - nodeIndex);
+ nodes_[nodeIndex].subtree_size = static_cast<u32>(nodes_.size() - nodeIndex);
}
}
};
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 62a3ac09f..eea701de5 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -24,6 +24,16 @@ target_include_directories(test_transform_traversal PRIVATE
)
add_test(NAME test_transform_traversal COMMAND test_transform_traversal)
+add_executable(test_ui_tree
+ ecs/test_ui_tree.cpp
+ ${CMAKE_SOURCE_DIR}/src/esengine/core/Log.cpp
+)
+target_include_directories(test_ui_tree PRIVATE
+ ${CMAKE_SOURCE_DIR}/src
+ ${CMAKE_SOURCE_DIR}/third_party/glm
+)
+add_test(NAME test_ui_tree COMMAND test_ui_tree)
+
add_executable(test_tween_activity
ecs/test_tween_activity.cpp
${CMAKE_SOURCE_DIR}/src/esengine/animation/TweenSystem.cpp
diff --git a/tests/ecs/test_ui_tree.cpp b/tests/ecs/test_ui_tree.cpp
new file mode 100644
index 000000000..4d52974cc
--- /dev/null
+++ b/tests/ecs/test_ui_tree.cpp
@@ -0,0 +1,39 @@
+#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
+#include <doctest.h>
+#include "esengine/ui/UITree.hpp"
+
+using namespace esengine;
+using namespace esengine::ecs;
+
+TEST_CASE("wide UI subtrees preserve their full span across the 16-bit boundary") {
+ Registry registry;
+ auto root = registry.create();
+ registry.emplace<Canvas>(root);
+ registry.emplace<Transform>(root);
+ registry.emplace<UINode>(root);
+ auto& children = registry.emplace<Children>(root).entities;
+ children.reserve(65535);
+ for (int i = 0; i < 65535; ++i) {
+ auto child = registry.create();
+ registry.emplace<UINode>(child);
+ registry.emplace<Parent>(child).entity = root;
+ children.push_back(child);
+ }
+ UITree tree;
+ tree.rebuild(registry);
+ REQUIRE(tree.nodes_.size() == 65536);
+ CHECK(tree.nodes_[0].subtree_size == tree.nodes_.size());
+ CHECK(tree.nodes_.back().subtree_size == 1);
+ children.pop_back();
+ tree.rebuild(registry);
+ REQUIRE(tree.nodes_.size() == 65535);
+ CHECK(tree.nodes_[0].subtree_size == tree.nodes_.size());
+ children.push_back(registry.create());
+ registry.emplace<UINode>(children.back());
+ tree.rebuild(registry);
+ CHECK(tree.nodes_[0].subtree_size == 65536);
+ children.push_back(registry.create());
+ registry.emplace<UINode>(children.back());
+ tree.rebuild(registry);
+ CHECK(tree.nodes_[0].subtree_size == 65537);
+}
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index f23134062..7ed6f1139 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(ui): preserve traversal spans for large subtrees':
+ { note: 'Large UI subtrees keep their full traversal span.' },
'perf(ui): preserve transform composition across clean layout passes':
{ note: 'Static UI layout preserves composed world transforms.' },
'fix(ui): bound hit caches to live pointer frames':