Calling setBackgroundDrawingCallback with a nil value will lead to problems

Hello there,

I was using to setup a function which will automatically render the background image of my game (like one of the examples does).
At some point the game transitions to another mode, where I don't want or need that background image callback anymore.
So I called

to clear the callback.
This seemed to work for a while, however when I now added another state afterwards, which again uses the background drawing callback, I ran into errors:
Note: this is after I already called setBackgroundDrawingCallback with a valid function to set it again.
So essentially this does not work:

local backgroundDraw = function ( x, y, width, height )
    -- draw call or whatever
-- insert game logic here
-- more game logic (without rendering a background image) -- this will now crash

Apparently once set to nil, the drawCallback cannot be set properly anymore afterwards.
One has to do the following instead:,y,width,height) end)

Maybe this can be mentioned in the documentation at least, if it is not a bug.
Small test project attached to reproduce the issue: (20.8 KB)

Kind regards.

Not sure if this is related.

Yeah you are correct, my thread seems to be a duplicate.
I must have missed that one during my quick search of the forums, sorry.

I think it's best to continue discussion there, so it is not split between two locations. This topic can be closed then (I seem to lack the power to do so however)

1 Like