1. Anders Ruud
  2. love
  3. Issues

Issues

Issue #472 wontfix

Don't raise errors for undefined PixelEffect variables

criptych
created an issue

When trying to :send a PixelEffect a uniform (variable) that isn't defined in its source, LOVE currently raises an error. However, some - maybe most - OpenGL implementations will also optimize //unused// uniforms out of the compiled shader, meaning that even if they are defined, LOVE cannot find them and raises an error anyway. A better way of handling this situation might be to return a boolean indicating whether the uniform was successfully sent.

This problem is even more noticeable in later hg builds since merely //creating// (with newPixelEffect) PixelEffect objects that don't use {{{love_ScreenSize}}} (or, more accurately, the {{{screen_coords}}} parameter that depends on it) may raise an error.

Comments (6)

  1. Matthias Richter

    I think raising an error is better than failing silently:

    • Typo-based bugs are easy to spot, and
    • it helps to spot code paths that the compiler optimizes out.

    I agree on the love_ScreenSize thing though. That shouldn't happen.

  2. criptych reporter

    "Typo-based bugs are easy to spot": true enough. Perhaps a workaround for when you expect a uniform could be missing (as in newPixelEffect), is to call send with pcall.

    EDIT: I'm not sure how much pcall affects performance, but what about having two methods? send raises errors as usual, and another, say trySend, does not.

  3. Matthias Richter

    If you're pcall slows down your code significantly you're probably doing something wrong ;)

    function bench(f, n)
        local s = os.clock()
        for i = 1,n do f() end
        return os.clock() - s
    end
    
    -- placeholder for :send()
    function foo(n) for i = 1,n do i = i * i end end
    
    a = bench(function() foo(100) end, 100000)
    b = bench(function() pcall(foo, 100) end, 100000)
    print(b/a) --> something around 1.05
    
  4. criptych reporter

    I wasn't saying it does, just that I didn't know how much it would. It would be convenient to have another method, though, even if it just wraps pcall.

  5. Matthias Richter

    Marking wontfix because a trySend() would be inconsistent with the rest of the API. If you need to have it, you can implement it in Lua, i.e.:

    function trySend(effect, ...)
        return pcall(effect.send, effect, ...)
    end
    
  6. Log in to comment