Game crashes when I send "play_animation" message or I do something else

I am not sure it is a bug in Defold or I do something wrong. Anyway I would like to see detailed message what goes wrong.

To details:

In my asset I have “left_fan” animation group with four images in it. And “right_fan” animation with the same images, but flipped.
One of these images I use in “idle” animation groups, “left_fan_idle” and “right_fan_idle” (also flipped).

I have two game objects “right_fan” and “left_fan” that have only one Sprite component.

In another game object (“block”), I do the following code:

local left_fan_playing_animation = false
local right_fan_playing_animation = false

function final(self)
    if right_fan_playing_animation then
        msg.post("right_fan#sprite", "play_animation", {id = hash("right_fan_idle")})
    end
    if left_fan_playing_animation then
        msg.post("left_fan#sprite", "play_animation", {id = hash("left_fan_idle")})
    end
end

function left_fan(self)
    air_force_cur_value = air_force_cur_value - self.air_force_value
    if not left_fan_playing_animation then
        msg.post("left_fan#sprite", "play_animation", {id = hash("left_fan")})
        left_fan_playing_animation = true
    end
end

function right_fan(self)
    air_force_cur_value = air_force_cur_value + self.air_force_value
    if not right_fan_playing_animation then 
        msg.post("right_fan#sprite", "play_animation", {id = hash("right_fan")})
        right_fan_playing_animation = true
    end
end

function on_input(self, action_id, action)
    if action_id == hash("left_fan") and not action.released then
        left_fan(self)
    elseif action_id == hash("left_fan") and action.released then
        msg.post("left_fan#sprite", "play_animation", {id = hash("left_fan_idle")})
        left_fan_playing_animation = false
    elseif action_id == hash("right_fan")  and not action.released then
        right_fan(self)
    elseif action_id == hash("right_fan")  and action.released then
        msg.post("right_fan#sprite", "play_animation", {id = hash("right_fan_idle")})
        right_fan_playing_animation = false
        ...
    end
end

Almost in any times, when block is deleted, my game crashes.
I am not sure that the cause of crash is “play_animation”, because, untill block “live”, releasing actions starts idle animations without crashes.

Does anybody have any ideas what is wrong.

UPD:

When I run HTML5 version in Firefox, its console shows the following:

uncaught exception: Assertion failed: version != 0, at: ../src/dlib/message.cpp,250,IsSocketValid at jsStackTrace@http://localhost:8080/build/default/__htmlLaunchDir/blowin-in-the-wind/blowin-in-the-wind.js:1:21724
stackTrace@http://localhost:8080/build/default/__htmlLaunchDir/blowin-in-the-wind/blowin-in-the-wind.js:1:21907
___assert_fail@http://localhost:8080/build/default/__htmlLaunchDir/blowin-in-the-wind/blowin-in-the-wind.js:1:1406372
Uba@http://localhost:8080/build/default/__htmlLaunchDir/blowin-in-the-wind/blowin-in-the-wind.js:8:1
js@http://localhost:8080/build/default/__htmlLaunchDir/blowin-in-the-wind/blowin-in-the-wind.js:22:1
mj@http://localhost:8080/build/default/__htmlLaunchDir/blowin-in-the-wind/blowin-in-the-wind.js:15:1
Ig@http://localhost:8080/build/default/__htmlLaunchDir/blowin-in-the-wind/blowin-in-the-wind.js:15:1
Pg@http://localhost:8080/build/default/__htmlLaunchDir/blowin-in-the-wind/blowin-in-the-wind.js:15:1
rAa@http://localhost:8080/build/default/__htmlLaunchDir/blowin-in-the-wind/blowin-in-the-wind.js:28:1
Runtime.dynCall@http://localhost:8080/build/default/__htmlLaunchDir/blowin-in-the-wind/blowin-in-the-wind.js:1:5743
Browser_mainLoop_runner/<@http://localhost:8080/build/default/__htmlLaunchDir/blowin-in-the-wind/blowin-in-the-wind.js:1:1411429
Browser.mainLoop.runIter@http://localhost:8080/build/default/__htmlLaunchDir/blowin-in-the-wind/blowin-in-the-wind.js:1:1413005
Browser_mainLoop_runner@http://localhost:8080/build/default/__htmlLaunchDir/blowin-in-the-wind/blowin-in-the-wind.js:1:1411363

I hope it’ll help.

The right_fan() and left_fan() functions are declared as global (ie not prefixed with the local keyword). This means that if you have multiple instances of the script attached to different block objects you’ll run the risk of getting unexpected results. You should make a habit of using local functions and variables, unless you are really certain that you need a global function (typically a utility function of some kind). And even in that case I’d recommend that you put utility/global functions in a Lua module for easy reuse in several scripts.

PS I’m not sure if this is what’s causing the bug though

Oh…yes. I just missed them, but it did not help. However it seems, that crashes occur rarely now.

Does it crash in a desktop build as well? It’s easier to debug that way. You will probably get a better error message in the console.

Actually, I started with testing desktop build. There is no any error messages as usual. Only those, that I post by using pprint.
Maybe, there is a way to get a dump when it crashes?

Hmm, ok, I took a look at the code references in the stack trace (messages.cpp #250) but I’m a bit certain why it behaves as it does. @sven, any idea?