I have a game scene, s, which is given a function called update_objects. Please note the count variable declared at the start of the loop. This count is incremented for each object in the scene.
Code: Select all
s.update_objects = function(self, world)
local physics_region = self.physics_region
local objects = self.objects
local count = 0
for obj, _ in pairs(objects) do
count = count+1
obj:update(world)
engine.apply_physics(obj)
if physics_region then
physics_region:update_object(obj)
end
end
print("update count", count)
end
None of the functions obj:update(world), engine.apply_physics(obj), or physics_region:update_object(obj) alter the scene's objects table in any way. There is no way for that table to mutate during the iteration and post-iteration it reports the correct number of pairs. As mentioned, turning off the JIT eliminates the bug entirely with no other code changes.