bkacjios / lua-mumble

A lua module to connect to a mumble server and interact with it
MIT License
23 stars 4 forks source link

Crash in timer.lua example script #7

Closed Phazeus closed 4 years ago

Phazeus commented 4 years ago

With adding "mumble:loop()" at the end of "timer.lua" example and running, it crashes after first iteration after 15 seconds. Is it normal?

1 2 3 Stopping timer.. free(): invalid pointer

With empty "OnServerSync" hook the same:

local mumble = require("mumble")
local client = assert(mumble.connect("druha.su", 64738, "bot.pem", "bot.key"))
client:auth("Mumble-Bot")
client:hook("OnServerSync", function(event)
  print("tick")
end)
mumble.loop()
bkacjios commented 4 years ago

Sounds to me like it's crashing when sending a ping to the server for some reason. I'm running my test script and it's been going strong for 5 minutes now with no crashes.

local mumble = require("mumble")

local client = assert(mumble.connect("::1", 64738, "cert.pem", "key.pem"))

client:auth("TestBot")

client:hook("OnServerVersion", function(event)
    print("OnServerVersion", event)
end)

client:hook("OnServerReject", function(event)
    print("OnServerReject", event)
end)

client:hook("OnUserStartSpeaking", function(user)
    print("OnUserStartSpeaking", user)
end)

client:hook("OnUserStopSpeaking", function(user)
    print("OnUserStopSpeaking", user)
end)

client:hook("OnUserSpeak", function(event)
end)

client:hook("OnServerSync", function(event)
    print("OnServerSync", event)

    local timer = mumble.timer()

    local i = 0

    -- A timer that will start after 1 second and repeat every 1 second thereafter
    -- Once our counter hits 3, stop the timer
    timer:start(function(t)
        i = i + 1

        print(i)

        if i >= 3 then
            print("Stopping timer..")
            t:stop()
        end
    end, 1, 1)
end)

client:hook("OnClientPing", function(event)
    print("OnClientPing", event)
end)

client:hook("OnServerPing", function(event)
    print("OnServerPing", event)
end)

client:hook("OnChannelRemove", function(channel)
    print("OnChannelRemove", channel)
end)

client:hook("OnChannelState", function(channel)
    print("OnChannelState", channel)
end)

client:hook("OnUserRemove", function(event)
    print("OnUserRemove", event)
end)

client:hook("OnUserState", function(event)
    print("OnUserState", event)
end)

client:hook("OnMessage", function(event)
    print("OnMessage", event)
    print(client:play("shine.ogg", 1, 2))
end)

client:hook("OnPermissionDenied", function(event)
    print("OnPermissionDenied", event)
end)

client:hook("OnCodecVersion", function(event)
    print("OnCodecVersion", event)
end)

client:hook("OnUserStats", function(event)
    print("OnUserStats", event)
end)

client:hook("OnServerConfig", function(event)
    print("OnServerConfig", event)
end)

client:hook("OnSuggestConfig", function(event)
    print("OnSuggestConfig", event)
end)

client:hook("OnAudioFinished", function(channel)
    print("OnAudioFinished", channel)
end)

client:hook("OnAudioStreamEnd", function()
    print("OnAudioStreamEnd")
end)

client:hook("OnDisconnect", function()
    print("OnDisconnect")
end)

client:hook("OnError", function(err)
end)

mumble.loop()

Image

I would first suggest doing a clean build of the module with make clean && make all

If it's still crashing, you can try making a debug build with make clean && make debug then running it with a debugger such as gdb.

gdb --args luajit test.lua

When it crashes, you can get a stack trace and see where exactly it's crashing with line numbers and everything.

Phazeus commented 4 years ago

I run new lib in my old worked script and got the same crash... Hmmm....

bkacjios commented 4 years ago

Try using gdb to see where it is crashing.

sudo apt-get install gdb

gdb --args luajit test.lua

When it crashes, enter bt into the command line

Phazeus commented 4 years ago

Oh sorry my dear comrade, I ran it with luajit instead of lua5.1 and it seems works now :)

bkacjios commented 4 years ago

Strange! But glad you got it working.

Phazeus commented 4 years ago

Thanks a lot for timer!

bkacjios commented 4 years ago

You're welcome!