Jump to content

Deleting entities


Rick
 Share

Recommended Posts

In my game I call Release() on an entity from inside the player script Collision function. So when the player collides with this entity it gets released. Sometimes this seems to cause a crash of the game (no error message just Assert failed). If I just Hide() the entity I don't seem to get a crash (tried like 20 times and no crash).

I thought it was sounds I would play in this collision function at first but it doesn't seem to be that. With some system prints I see it makes it all the way to the end of the collision function just fine so it goes over the Play() functions for the sounds. It's almost like in some situations LE is trying to do something with the passed in entity and since I've released it it would cause a crash since it's trying to access something where the object in memory doesn't exist anymore.

 

Does LE do anything with the passed in entity variable to the collision function after the function is called? Are these entities in a list and me deleting it causes that iterator to get messed up or something?

Link to comment
Share on other sites

Are you assuming the collision is only happening once? More than likely when a collision occurs, its triggered multiple times. A box falling on the ground is not just a single collision. If you are not performing a check to prevent it, the second reported collision will try to release an entity that has been already released by the first reported collision. Without example code, we can only guess what you are doing wrong.

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

I guess I would think/expect if I release an entity inside here, LE wouldn't call this function again with a released entity. Perhaps that assumption is incorrect? I know the call to entity:Release() inside does execute and comes back as a system print shows execution reaches the end of the Collision() function even on a crash.

I guess in this post I was more looking for the guidelines to releasing a passed in entity in the Collision function. Should it be avoided, is there a recommended way to handle that idea or should it work and it's something I'm doing and can dig into myself? I (what I consider) worked around the issue currently so I think it's good. Was just curious if there were any recommendations around the idea of releasing an entity during a collision.

Link to comment
Share on other sites

This will cause a crash in 4.5.

I moved the Lua function call into a GCSuspend / Resume block so this will probably be okay in the next update (4.6).

I recommend hiding these entities. It doesn't hurt anything and it is safer.

  • Upvote 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Ok thanks for the recommendation. That was my workaround. It also required setting a flag on the entity and checking that flag as well since collision can be called multiple times for the same entity per loop. I noticed just hiding resulted in my counter increasing more than just once. I guess I could have checked for hiddden instead of making a flag too (just thought about that).

What I did Then is inside that entity script in UpdateWorld, check if this flag is set and if so release self.entity and that seems safer.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...