d954mas / defold-box2d

defold-box2d bindings
MIT License
32 stars 3 forks source link

Destroying listeners #20

Open einarnordengren opened 6 months ago

einarnordengren commented 6 months ago

Is there any way to destroy contact listeners or destruction listeners? It looks like the references to them are destroyed in the world's Destroy() function, but the number of LuaRefs keeps increasing every time I reinitalize the world.

d954mas commented 6 months ago

If you set nil, Listener should be destroyed

https://github.com/d954mas/defold-box2d/blob/bb6ca239b14b7350e6ff9b0ca223dcf42c48e926/box2d/native/src/world.cpp#L67

d954mas commented 6 months ago

I look at code. It looks like listeners removed when world is destroyed.

https://github.com/d954mas/defold-box2d/blob/bb6ca239b14b7350e6ff9b0ca223dcf42c48e926/box2d/native/src/world.cpp#L736

einarnordengren commented 6 months ago

Right, so it should work by just destroying the world. However, if I add

self.world:SetContactListener({
    BeginContact = function() end,
    EndContact = function() end,
    PreSolve = function() end,
    PostSolve = function() end
})

in the init function of the dominos_scene.script, the number LuaRefs increases (checked in the web profiler) every time I press restart even if the world is destroyed in final.