Delete Materials
by Ronald J Nelson · in Torque Game Engine Advanced · 09/24/2008 (10:24 pm) · 5 replies
Hi in my game I am allowing players to join using custom paints. When they join a material is created on the fly for their texture and based upon the vehicle's datablock they are going to use. This all works very well. However, I want to be able to delete the material when the client leaves as well as their custom paint texture. I have the texture deletion handled but I need a way to delete a material.
Any ideas?
Any ideas?
#2
Furthermore, you need to clear the material from the material list or you'll run into it eventually and access the wrong pointer. Bad. Take a look at Material::getMaterialSet () and its contents, you can see how to access the list there.
09/25/2008 (9:37 am)
This has nothing to do with destructors. Not having a destructor doesn't mean you can't delete the datatype in question.Furthermore, you need to clear the material from the material list or you'll run into it eventually and access the wrong pointer. Bad. Take a look at Material::getMaterialSet () and its contents, you can see how to access the list there.
#3
09/25/2008 (9:48 am)
You mean the material list should be reordered ?
#4
09/25/2008 (8:02 pm)
Interesting so what you are saying Stefan, and I am relating this to an area of the code I am more familiar with, that much like the decal list system I will have to search the list, find the material I want to remove, remove it, and then reorder the list?
#5
On the other hand, a quick glance at the search shows no cases where this list is used. I could be wrong, but it seems it previously was used to pack materials from client to server. But, better be safe than sorry!
You don't have to order the list.
09/26/2008 (2:41 pm)
Just call SimGroup::removeObject () and pass it the pointer of your material. Then you should be able to safely delete the material from memory, should be enough. Make sure you do that right before you exit the scope the function you're doing it from, and make sure you're not manipulating it in any way afterwards or you'll access garbage and at best, crash.On the other hand, a quick glance at the search shows no cases where this list is used. I could be wrong, but it seems it previously was used to pack materials from client to server. But, better be safe than sorry!
You don't have to order the list.
Torque Owner Ivan Mandzhukov
Liman3D
It sounds complex, but i believe it is not difficult to add it and assign via a pointer as old IBM style.
class SimObject .... { .... virtual ~SimObject(); //base destructor ... } class Material: public SimObject { public: Material(){.....} ~Material(){.....} //the new destructor of derived class }; //and then: SimObject* temp = new Material(); delete temp;Because the SimObject class Destructor is made virtual, both the destructors will be called in order.
That one is called "virtual mechanism".