Jump to content

World Entity Release


gamecreator
 Share

Recommended Posts

I have the following code which crashes as soon as it tries to Release the first tentacle entity. However, if I switch the for loops to remove the tentacles first, then the rocks, it works fine. Does anyone see why this could be? Am I releasing world entities incorrectly?

 


// REMOVE ROCKS

printf("world entity count: %d\n", world->CountEntities()); // 2231

for(i=world->CountEntities() - 1; i>0; i--)

{

if(world->GetEntity(i)->GetKeyValue("name").compare(0, 4, "rock") == 0)

{

world->GetEntity(i)->Release();

}

}

 

// REMOVE TENTACLES

printf("world entity count: %d\n", world->CountEntities()); // 2129

for (i=world->CountEntities() - 1; i>0; i--)

{

if (world->GetEntity(i)->GetKeyValue("name").compare(0, 8, "tentacle") == 0)

{

world->GetEntity(i)->Release();

}

}

Link to comment
Share on other sites

Could one of those entities be a parent of another? You might be freeing more than one entity when you do that.

 

Also, check to make sure GetEntity() isn't returning NULL.

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

I threw this line in before release

printf("tentacle info: %d, %d\n", i, world->GetEntity(i));

but it isn't NULL.

 

The tentacle is an animated model with bones and a collision mesh. The rock is just a model with a collision mesh (no bones). Neither are parented to anything or by anything otherwise. The above code happens pretty much right after I load the map. I'm going through the map entities and replacing them with my own.

Link to comment
Share on other sites

When you delete the last entity in the list you are deleting its children, causing more than one entity to get deleted.

 

However, GetEntity would return NULL if the index is bigger than the entity list.

 

Another option is to call System::GCSuspend() before the loop and System::GCResume() after it. This will prevent objects from getting deleted even when their ref count goes to zero, and then the resume call will clean everything up.

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

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...