From 509048b9df3db1a6f53b1aac885eb5c79f5987bc Mon Sep 17 00:00:00 2001 From: vnnh <90565423+vnnh@users.noreply.github.com> Date: Sat, 4 Jan 2025 23:41:52 -0600 Subject: [PATCH] Fix table.move usage in query_cached (#173) * Fix table.move usage in query_cached * Add test case --- jecs.luau | 2 +- test/tests.luau | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/jecs.luau b/jecs.luau index 473b620a..332652ef 100644 --- a/jecs.luau +++ b/jecs.luau @@ -1589,7 +1589,7 @@ local function query_cached(query: QueryInner) local with = query.filter_with local ids = query.ids if with then - table.move(ids, 1, #ids, #with, with) + table.move(ids, 1, #ids, #with + 1, with) else query.filter_with = ids end diff --git a/test/tests.luau b/test/tests.luau index 8da151f1..a8d53b1d 100644 --- a/test/tests.luau +++ b/test/tests.luau @@ -1495,5 +1495,22 @@ TEST("repro", function() end CHECK(counter == 1) end + + do CASE "#3" -- ISSUE #171 + local world = world_new() + local component1 = world:component() + local tag1 = world:entity() + + local query = world:query(component1):with(tag1):cached() + + local entity = world:entity() + world:set(entity, component1, "some data") + + local counter = 0 + for x in query:iter() do + counter += 1 + end + CHECK(counter == 0) + end end) FINISH()