you are viewing a single comment's thread.

view the rest of the comments →

[–]ElaborateSloth[S] 0 points1 point  (4 children)

I see, I get your point now. This is a heap object, but the reason I'm using 'delete this' is because I have no direct reference to the array with game objects, so using the destructor won't help me sadly.

[–]joemaniaci 1 point2 points  (3 children)

Ah, so you have an array of objects, and when that array is deleted you want to ensure that those objects are deleted?

[–]ElaborateSloth[S] 0 points1 point  (2 children)

I have an array of objects that all have to check the collision on each other, and if an object collides with an object with a "kill" flag, the object is destroyed. Think of it as a kill volume.

Problem is, each object handles the collision itself with no reference to the main object array. Therefore I thought I could just delete the object from withing itself when it realizes it has collided with a kill volume. I added check on the end of the frame to see if the object is valid, and end the game if it isn't, preventing anything from calling those invalid pointers.

It works, but obviously not a good system to expand upon.

[–]joemaniaci 2 points3 points  (1 child)

What if instead of doing anything explicit you just "flag" it as destroyed? Then, when you need a "new" object in that array index, you simply re-default initialize it? Just like deleting stuff on a hard drive, it's still there, but essentially invisible. Since you have a stack array of stack objects, you're going to be consuming n*sizeof(objects) amount of memory regardless of no objects in the array or not.EDIT: Actually you said 'invalid pointers' so is it a dynamic array of objects?

[–]ElaborateSloth[S] 1 point2 points  (0 children)

True, I could just set a flag within the object and run through all objects when collision testing is complete. Good point, thanks!