vrld / HC

General purpose collision detection library for the use with LÖVE.
http://hc.readthedocs.org/
402 stars 48 forks source link

Problems with hc.removeFromGroup #4

Closed andreadellacorte closed 12 years ago

andreadellacorte commented 12 years ago

Hi!

I noticed that using hc.remove to remove from the collision system a shape that was added in a group, is causing a memory leak.

if ( shape_a.sprite == enemy_sprite and shape_b.sprite == ammo_sprite) then
    text[#text+1] = string.format("Colliding Enemy-Ammo %d", i)     
    HC.removeFromGroup("enemy_team", shape_a)       
    HC.remove(shape_a)
    HC.removeFromGroup("player_team", shape_b)  
    HC.remove(shape_b)  
    return
end

Unfortunately when removeFromGroup is getting called, I get the following error:

hardoncollider/init.lua:292: Shape was not created by main module

I did the following to solve this problem: I added a mark for removal boolean into every object, which is updated into the collide callback and they are not anymore removed from HC into this callback, but into the update function.

Thanks, Andrea

vrld commented 12 years ago

This issue is somewhat puzzling, since the collision callbacks are only called after searching for all colliding shapes. Are you using the stop-colliding callback?

andreadellacorte commented 12 years ago

No, how does that works?

Thanks

vrld commented 12 years ago

I meant the second callback in setCallbacks(). Can you provide me with a complete example if the error is still present with the latest version?