love2d / love

LÖVE is an awesome 2D game framework for Lua.
https://love2d.org
Other
5.05k stars 401 forks source link

table overflow error when using love with luamqtt #2115

Open dov opened 4 hours ago

dov commented 4 hours ago

I have a small gaming console, Anbernic RG40XXV, and I'd like to write a love2d program for it which fetches messages through mqtt, and based on the messages show some graphics, or start an audio file. However, when trying to combine love2d with luamqtt, the program crashes.

I opened the following bug at https://github.com/xHasKx/luamqtt/issues/49, but the author of luamqtt thought it was a bug in love2d's use of luajit.

While trying to run luamqtt under love2d on a small gaming console (Anbernic rg40xxv), I got the following error and stacktrace:

Error

/usr/local/share/lua/5.1/mqttprotocol.lua:415:table overflow

Traceback

[love "callbacks.lua"]:228: in function 'handler'
/usr/local/share/lua/5.1/mqtt/protocol.lua:415: in function 'combine'
/usr/local/share/lua/5.1/mqtt/protocol4.lua:99: in function '_make_packet'
/usr/local/share/lua/5.1/client.lua:760: in function 'send_connect'
/usr/local/share/lua/5.1/client.lua:672: in function 'start_connecting'
/usr/local/share/lua/5.1/client.lua:919: in function '_ioloop_iteration'
/usr/local/share/lua/5.1/ioloop.lua:113: in function 'iteration'
main.lua:44: in function 'update'
[love "callbacks.lua"]:162: in function <love "callbacks.lua"]:144> 
[C]: in function 'xpcall'

Here is my love main.lua script:

local mqtt = require("mqtt")

local client
local ioloop
local info = "Waiting for message..."

function love.load()
  print('love.load()')
  client = mqtt.client{ uri = "192.168.1.11", clean = true }
  ioloop = mqtt:get_ioloop()
  ioloop:add(client)
  print('got client')

  -- assign MQTT client event handlers
  client:on{
      connect = function(connack)
          if connack.rc ~= 0 then
              print("connection to broker failed:", connack:reason_string(), connack)
              return
          end
          print('connection established')

          -- connection established, now subscribe to test topic and publish a message after
          assert(client:subscribe{ topic="luamqtt/#", qos=1, callback=function()
              assert(client:publish{ topic = "luamqtt/simpletest", payload = "hello" })
          end})
      end,

      message = function(msg)
          assert(client:acknowledge(msg))

          -- receive one message and disconnect
          print("received message", msg)

          -- Set variable to be displayed
          info = msg.payload
  --        client:disconnect()
      end,
  }
end

function love.update(dt)
    -- Poll the MQTT client to process incoming messages
  ioloop:iteration()
end

function love.draw()
  love.graphics.print(info, 10, 10)
end

What is strange to me is that the following script, without love, works on the same platform with luajit simple-mqtt.lua:

-- load mqtt library
local mqtt = require("mqtt")
local socket = require("socket")

local client = mqtt.client{ uri = "192.168.1.11", clean = true }

-- assign MQTT client event handlers
client:on{
    connect = function(connack)
        if connack.rc ~= 0 then
            print("connection to broker failed:", connack:reason_string(), connack)
            return
        end
        print('connection established')

        -- connection established, now subscribe to test topic and publish a message after
        assert(client:subscribe{ topic="luamqtt/#", qos=1, callback=function()
            assert(client:publish{ topic = "luamqtt/simpletest", payload = "hello" })
        end})
    end,

    message = function(msg)
        assert(client:acknowledge(msg))

        -- receive one message and disconnect
        print("received message", msg)
--        client:disconnect()
    end,
}

function sleep(sec)
    socket.select(nil, nil, sec)
end

-- run ioloop for client
ioloop = mqtt:get_ioloop()
print('got loop')
ioloop:add(client)
while true do
--  mqtt.run_ioloop(client)
  ioloop:iteration()
  sleep(0.2)  
end  

I installed luamqtt by the command luarocks-5.1 install luamqtt, and the output from the installation was:

root@ANBERNIC:/home/dov/learning/lua# luarocks-5.1 install luamqtt
Installing https://luarocks.org/luamqtt-3.4.3-1.rockspec
Cloning into 'luamqtt'...
remote: Enumerating objects: 1482, done.
remote: Counting objects: 100% (490/490), done.
remote: Compressing objects: 100% (69/69), done.
remote: Total 1482 (delta 459), reused 421 (delta 421), pack-reused 992 (from 1)
Receiving objects: 100% (1482/1482), 316.62 KiB | 3.68 MiB/s, done.
Resolving deltas: 100% (942/942), done.
Note: switching to '579c90bb8679dcaf29ad5a0864ab18e5271a061d'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

luamqtt 3.4.3-1 depends on lua >= 5.1, <= 5.4 (5.1-1 provided by VM)
luamqtt 3.4.3-1 depends on luasocket >= 3.0rc1-2 (3.1.0-1 installed)
luamqtt 3.4.3-1 is now installed in /usr/local (license: MIT)
slime73 commented 4 hours ago

which version of love are you using? Also, can you post the results of print(jit.version) when run from within love?

dov commented 3 hours ago

I'm running love-11.5 and my jit.version outputs LuaJIT 2.1.0-beta3.

slime73 commented 3 hours ago

That's a pretty old LuaJIT version - the official love downloads include a much newer one which uses rolling releases. Can you try building the latest luajit source? Maybe it'll change things.

dov commented 3 hours ago

Ok, thanks, I'll try.

I actually tried, but SDL no longer initializes, with my newly compiled version. To be continued....