Page 1 of 1

Crash

Posted: Mon Apr 13, 2020 9:09 am
by SliiX
So, I am working on an infinite map generation thing for a 2d game and I have it about half way done, but I was bug testing and decided to go super far out and see if it affects performance. Anyways, once I got to about 42,000 (8 tile x 8 tile ) chunks with (64 pixel x 64 pixel) tiles in each chunk and the game program just turns off completely? Anyone know what could be the cause of this?

Re: Crash

Posted: Mon Apr 13, 2020 3:18 pm
by pgimeno
It appears that you're reaching LuaJIT's memory limit. I've tried with LuaJIT-2.1.0-beta3 with GC64 enabled and it doesn't crash.

Re: Crash

Posted: Mon Apr 13, 2020 10:47 pm
by SliiX
Alright cool thanks! Is there a way to not store the map data in memory? Or, do I have to use luaJIT 2.1.0?

Edit:

So I did some research and it appears I made a weird mistake in the code below:

Code: Select all


local chunks = {}
local loaded = {}

function render()
	-- this is supposed to reset the loaded table
	-- but apparently this does not clear it from memory?
	loaded = {}

	for i = 1,#chunks do
		-- bunch of if statements
		loaded[#loaded+1] = chunks[i]
	end
end

function love.update()
	render()
end
    

Re: Crash

Posted: Tue Apr 14, 2020 3:10 pm
by pgimeno
SliiX wrote: Mon Apr 13, 2020 10:47 pm Alright cool thanks! Is there a way to not store the map data in memory? Or, do I have to use luaJIT 2.1.0?

Edit:

So I did some research and it appears I made a weird mistake in the code below:

Code: Select all


local chunks = {}
local loaded = {}

function render()
	-- this is supposed to reset the loaded table
	-- but apparently this does not clear it from memory?
	loaded = {}

	for i = 1,#chunks do
		-- bunch of if statements
		loaded[#loaded+1] = chunks[i]
	end
end

function love.update()
	render()
end
    
You can free up some map data from memory. Chunk-based programs (e.g. Minetest) usually use a disk database to store generated chunks on and free them from memory.

Removing the call to world:render() does not fix the crash, so that's not the problem.

Re: Crash

Posted: Wed Apr 15, 2020 12:32 am
by SliiX
The disk thing is a good idea and is gonna need to me implemented anyways, I went ahead and made a much smaller and quicker and just generally less messy version of this and its working a lot better. With that being said, is there a fast and efficient way of storing tables on disk?

Re: Crash

Posted: Wed Apr 15, 2020 2:00 pm
by pgimeno
SliiX wrote: Wed Apr 15, 2020 12:32 am The disk thing is a good idea and is gonna need to me implemented anyways, I went ahead and made a much smaller and quicker and just generally less messy version of this and its working a lot better. With that being said, is there a fast and efficient way of storing tables on disk?
You need serialization for that. How fast and efficient depends on the serialization code. Take a look at
https://github.com/gvx/bitser for example.

Re: Crash

Posted: Sat Apr 18, 2020 12:04 pm
by AuahDark
You can workaround the memory limit by using love.data.newByteData and FFI then store your data there. However, depending on how you structure the game, it may be not possible.

Re: Crash

Posted: Tue Apr 21, 2020 2:42 am
by SliiX
I solved the problem thanks for the support, was really helpful!