Game freeze on factory.create

Hello ,

I am starting my first Debold game and having some odd behavior with my factory in my update statement. When I create it with a vector with X position less than about 72, the game freezes immediately when opening on this statement. When I set the X to 72 or more, it is fine. I can’t figure out why this would behave like this. My init function creates one at X of 36 which doesn’t freeze the game, so I am not sure why the update create is a problem. Any ideas on where to debug?

function init(self)
    self.spawns = {} 
    local f = "#platform9_factory"
    -- create first platform
   	local p = factory.create(f, vmath.vector3(36, self.height, 0), nil, {}, 0.6)
    table.insert(self.spawns, p)
end

function update(self, dt)
	if tablelength(self.spawns) < 6 then
		local f = "#platform9_factory"
		local p = factory.create(f, vmath.vector3(72, platform_state.next_platform_position_y, 0), nil, {}, 0.6) -- anything less than ~72 causes freeze
        table.insert(self.spawns, p)
        self.total_platforms = self.total_platforms + 1
	end
end

What is tablelength()? Unless it’s a function that you have created that returns the length of the table your update function will not work as expected. You can get the length of a table like this:

if #self.spawns < 6 then

Do you have any errors in the console in the editor?

3 Likes

Hi Björn,

Below is the tablelength function. The update code works fine as it is written, but when I change the 72 “x position” to something smaller like 36 in “local p = factory.create(f, vmath.vector3(72, platform_state.next_platform_position_y, 0), nil, {}, 0.6)”, then it “freezes” basically sitting and spinning using 100% CPU.

I use a similar line in the init function with 36 which works fine, and I tried matching them identically and it still freezes on the update statement. I put a print before and right after the factory.create line and it prints the first but doesn’t make it to the second, so I know it is freezing on that line.

No, there aren’t any errors in the console or error log so I don’t know what to go on.

function tablelength(T)
local count = 0
for _ in pairs(T) do count = count + 1 end
return count
end

Thanks for your help.
Dan

Would you mind sharing the project with me (bjorn.ritzl@king.com) so that I can take a look?

Yes, I just sent you an email with the project details. Thanks!

I just figured it out - I was glossing over the fact that factory.create runs through the init of the factory’s produced object’s script. I had a while loop in there that was getting stuck when the previous object was created close to it which is why having one at x=36 and one x=72 worked but both at x=36 got stuck in my loop.

Thanks for your help!

3 Likes

Good that you were able to figure it out! I was just about to open the project myself to take a look.

2 Likes