I am working on game using Lua, and started experiencing random crashes on hardware and segmentation faults with the simulator on MacOS.
Finally, i found a way to reproduce the crash consistently, and added some print statements to try to find the cause.
The code is this:
print("Main loop...")
function playdate.update()
print("a")
if gameStatus == 0 then
print("b")
UpdateMenu()
print("c")
elseif gameStatus == 1 then
print("d")
gameUpdate()
print("e")
gfx.sprite.update()
print("f")
end
print("g")
end
print("end of line")
And the log on the shell (using the simulator console is not possible because of the segmentation fault) is like this
Main Loop...
a
b
c
g
a
b
c
g
a
d
e
f
(...)
g
a
d
e
f
g
a
d
e
f
g
[1] 10028 segmentation fault game.pdx
Tried with SDK 1.12.3, 1.13.0, etc. up to 1.13.5 always with the same result.
Is there any way that i can get more information to find the source of the problem?
Re-reading the documentation, now i see, that the third argument to gfx.imagetable.new is not (as i somehow supposed) the width in pixels for the images, but some kind of memory allocation size .
Removing that third argument fixes all the crashes.