gamecreator Posted January 11, 2017 Share Posted January 11, 2017 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(); } } Quote Link to comment Share on other sites More sharing options...
Josh Posted January 11, 2017 Share Posted January 11, 2017 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. Quote 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 More sharing options...
gamecreator Posted January 11, 2017 Author Share Posted January 11, 2017 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. Quote Link to comment Share on other sites More sharing options...
Josh Posted January 11, 2017 Share Posted January 11, 2017 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. Quote 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 More sharing options...
gamecreator Posted January 11, 2017 Author Share Posted January 11, 2017 Suspend/resume worked. Thank you. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.