Reset transform stack?

Issue #1248 resolved
Kyle McLamb
created an issue

In the course of writing a game, sometimes I make mistakes. That's fine, because I can just run my game in protected mode, reset some things, and start love.run again to recover.

The one error that gums the works in this system is the max stack depth error, which happens when I forget to pop something I pushed, and sticks around even after I call love.graphics.reset(). Since reset is useful without tossing the stack, maybe an extra function like love.graphics.clearStack() could help?

Comments (10)

  1. Kyle McLamb reporter

    This is for live editing stuff: I don't plan to ship with love.graphics.clearStack(), but it'd be nice if I didn't have to restart my game all over for one specific mistake

  2. Raidho

    In meantime you can try the following:

    _lgpush, _lgpop, _counter = love.graphics.push, love.graphics.pop, 0
    love.graphics.push = function ( ) _counter = _counter + 1; _lgpush ( ) end
    love.graphics.pop = function ( ) _counter = _counter - 1; _lgpop ( ) end
    love.graphics.clearstack = function ( ) while _counter > 0 do love.graphics.pop ( ) end
    
  3. M D

    Alternatively, you can do this.

    function resetTransformStack()
        while pcall(function() love.graphics.pop() end) do end
    end
    

    This pops the stack until it encounters an error, and then it discards the error immediately.

  4. Bart van Strien

    Replace love.graphics.pop("all") with love.graphics.getStackDepth (resolves #1248 again)

    The pop("all") api was a bit awkward, especially considering there's a push("all") that does something else. I think any use case that benefited from pop("all") benefits from getStackDepth just as much if not more. There is also additional functionality, like being able to find the source of a mismatched push/pop.

    → <<cset e04219677926>>

  5. Log in to comment