How can i fire this function recursively without the c stack overflow

I have a block generation system which has caves in it.
The problem is when the caves get big enough a c stack overflow appears.

I have two functions:

function module.UncoverBlocks(target,CaveInfo)
   for x = -1,1 do
			module.GenerateOre(x,0,0,target, CaveInfo)

		end
		for y = -1,1 do
			module.GenerateOre(0,y,0,target, CaveInfo)

		end
		for z = -1,1 do
			module.GenerateOre(0,0,z,target, CaveInfo)

		end
end

function module.GenerateOre(x,y,z,target, CaveInfo)
    If Noise > Thrash then 
       module.UncoverBlocks(OreCFrame, CaveInfo)
    end
end

How can i fire these functions recursively without the c stack overflow appearing

Have you looked into Berezaa’s infinite mining game kit? If you haven’t you might give that a look as you can examine the code and get some ideas. He modeled the code after Azure Mines I believe.

Berezaa also uses a recursive function to do this. But his caves are way smaller.

I fixed this problem by making a new thread every time the function reaches a certain amount of uses.

Wow you must have some massive caves then. I played with that mining kit and the cave I get to going down through the player area has just a massive cave to the point it was taking like 30 seconds to build it causing me to rewrite it all to make it happen realtime.

Yeah my caves are pretty big for better player experience lol


These generate in max 3 seconds.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.