Explicit error message for double disconnect
Some checks failed
analysis / Run Luau Analyze (push) Has been cancelled
build-studio-docs / Build Studio Docs (push) Has been cancelled
unit-testing / Run Luau Tests (push) Has been cancelled

This commit is contained in:
Ukendio 2026-03-10 00:25:01 +01:00
parent 7170dbf6a1
commit 19823453aa
5 changed files with 13 additions and 18 deletions

View file

@ -1,6 +1,6 @@
{ {
"name": "@rbxts/jecs", "name": "@rbxts/jecs",
"version": "0.10.4", "version": "0.11.0",
"description": "Stupidly fast Entity Component System", "description": "Stupidly fast Entity Component System",
"main": "src/jecs.luau", "main": "src/jecs.luau",
"repository": { "repository": {

View file

@ -3142,7 +3142,8 @@ local function world_new(DEBUG: boolean?)
table.insert(listeners, fn) table.insert(listeners, fn)
return function() return function()
local n = #listeners local n = #listeners
local i = table.find(listeners, fn) local i = table.find(listeners, fn::Listener<any>)
assert(i, "Listener not found, maybe you tried to disconnect it twice")
listeners[i] = listeners[n] listeners[i] = listeners[n]
listeners[n] = nil listeners[n] = nil
end end
@ -3187,7 +3188,8 @@ local function world_new(DEBUG: boolean?)
table.insert(listeners, fn) table.insert(listeners, fn)
return function() return function()
local n = #listeners local n = #listeners
local i = table.find(listeners, fn) local i = table.find(listeners, fn::Listener<any>)
assert(i, "Listener not found, maybe you tried to disconnect it twice")
listeners[i] = listeners[n] listeners[i] = listeners[n]
listeners[n] = nil listeners[n] = nil
end end
@ -3232,6 +3234,7 @@ local function world_new(DEBUG: boolean?)
return function() return function()
local n = #listeners local n = #listeners
local i = table.find(listeners, fn::Listener<any>) local i = table.find(listeners, fn::Listener<any>)
assert(i, "Listener not found, maybe you tried to disconnect it twice")
listeners[i] = listeners[n] listeners[i] = listeners[n]
listeners[n] = nil listeners[n] = nil
end end
@ -3339,14 +3342,7 @@ local function world_new(DEBUG: boolean?)
local max_id = entity_index.max_id local max_id = entity_index.max_id
if index > max_id then if index > max_id then
-- Pre-populate all intermediate IDs to keep sparse_array as an array
for i = max_id + 1, index - 1 do for i = max_id + 1, index - 1 do
-- if not sparse_array[i] then
-- -- NOTE(marcus): We have to do this check to see if
-- -- they exist first because world:range() may have
-- -- pre-populated some slots already.
-- end
sparse_array[i] = { dense = 0, row = 0, archetype = ROOT_ARCHETYPE } sparse_array[i] = { dense = 0, row = 0, archetype = ROOT_ARCHETYPE }
end end
entity_index.max_id = index entity_index.max_id = index

View file

@ -10,7 +10,6 @@ local mirror = require(ReplicatedStorage.mirror:Clone())
return { return {
ParameterGenerator = function() ParameterGenerator = function()
local ecs = jecs.world() local ecs = jecs.world()
ecs:range(1000, 20000)
local mcs = mirror.World.new() local mcs = mirror.World.new()
return ecs, mcs return ecs, mcs
end, end,
@ -19,14 +18,14 @@ return {
Mirror = function(_, ecs, mcs) Mirror = function(_, ecs, mcs)
for i = 1, 100 do for i = 1, 100 do
mcs:entity() local _e = mcs:entity()
end end
end, end,
Jecs = function(_, ecs, mcs) Jecs = function(_, ecs, mcs)
for i = 1, 100 do for i = 1, 100 do
ecs:entity() local _e = ecs:entity()
end end
end, end,
}, },

View file

@ -178,15 +178,15 @@ TEST("migrating to real records", function()
print(jecs.record(world, e1).row) print(jecs.record(world, e1).row)
world:add(e1, jecs.pair(jecs.ChildOf, e2)) world:add(e1, jecs.pair(jecs.ChildOf, e2))
world:set(e1, jecs.Name, "hello") world:set(e1, jecs.Name, "hello")
print(jecs.record(world, e1).row) CHECK(jecs.record(world, e1).row~=0)
print(world:get(e1, jecs.Name), world:has(e1, jecs.pair(jecs.ChildOf, jecs.Wildcard))) CHECK(world:get(e1, jecs.Name)=="hello")
CHECK(world:has(e1, jecs.pair(jecs.ChildOf, jecs.Wildcard)))
end) end)
TEST("e2 is nil", function() TEST("e2 is nil", function()
local world = jecs.world(true) local world = jecs.world(true)
local e1 = world:entity(1000) local e1 = world:entity(1000)
print("-----")
local e2 = world:entity() local e2 = world:entity()
print("-----")
CHECK(e1 and world:contains(e1)) CHECK(e1 and world:contains(e1))
CHECK(e2 and world:contains(e2)) CHECK(e2 and world:contains(e2))

View file

@ -1,6 +1,6 @@
[package] [package]
name = "ukendio/jecs" name = "ukendio/jecs"
version = "0.10.4" version = "0.11.0"
registry = "https://github.com/UpliftGames/wally-index" registry = "https://github.com/UpliftGames/wally-index"
realm = "shared" realm = "shared"
license = "MIT" license = "MIT"