Git Product home page Git Product logo

Comments (3)

vrld avatar vrld commented on August 22, 2024

That's interesting. Can you provide a minimal example that produces the error or the relevant code snippets (cpuid.lua, etc) so I can try to reproduce the error?

from hump.

chtombleson avatar chtombleson commented on August 22, 2024

Thanks for the quick response :)
The source for the project is here, https://github.com/cribznetwork/jimcrib-hacker

from hump.

vrld avatar vrld commented on August 22, 2024

Ok, so here is what I think is going on:

-- cupid.lua:114
if game_funcs[v] and not paused then
    result = {select(1,xpcall(
        function() return game_funcs[v](unpack(arg)) end, cupid_error
    ))}
end

where game_funcs is a table that gets filled the following way:

-- cupid.lua:44
local game_funcs = {}
local protected_funcs = {'update','draw','keyreleased','keypressed','load'}
local function protector(table, key, value)
        for k,v in pairs(protected_funcs) do
        if ( v == key ) then
            game_funcs[key] = value  --< this line
            return
        end
    end
    rawset(table, key, value)
end

-- cupid.lua:94
setmetatable(wraped_love, {__index = cupid_stubs, __newindex = protector})
_love = love
love = wrapped_love

On the other hand, Gamestate.registerEvents() does this:

function GS.registerEvents(callbacks)
    callbacks = callbacks or all_callbacks
    for _, f in ipairs(callbacks) do
        registry[f] = love[f] --< and this line
        love[f] = function(...) return GS[f](...) end
    end
end

where GS[f](...) calls registry[f](...) and then the f on the current gamestate. Unfortunately this means that registry[f] calls itself, ad infinitum, causing the stack overflow.

In other words it's the interaction between registerEvents() and cupid.lua that caused the bug. Unfortunately I don't know how hump could detect such situations.

A possible workaround on the hump side of things is to omit calling registerEvents() and call the gamestate functions yourself, i.e.:

function love.load()
    Gamestate.switch(Menu)
end

function love.update(dt)
    Gamestate.update(dt)
end

function love.draw()
    Gamestate.draw()
end

-- etc.

from hump.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.