Game Development Community

TGE's memory management

by Samme Ng · in Torque Game Engine · 08/03/2004 (6:25 pm) · 5 replies

For a reason, I have to disable the TGE's memory management: using TORQUE_DISABLE_MEMORY_MANAGER.

After building the executable, the program fault at the following with "<<<<<"
while(mNotifyList)
   {
      Notify *note = mNotifyList;
      mNotifyList = note->next;
      
      AssertFatal(note->type != Notify::ClearNotify, "Clear notes should be all gone.");
      
      if(note->type == Notify::DeleteNotify)
      {
         SimObject *obj = (SimObject *) note->ptr;
         Notify *cnote = obj->removeNotify((void *)this, Notify::ClearNotify);
         obj->onDeleteNotify(this);
         freeNotify(cnote);
      }
      else
      {
         // it must be an object ref - a pointer refs this object
         [b]*((SimObject **) note->ptr) = NULL; <<<<<<<<[/b]
      }
      freeNotify(note);
   }

It is the notification list of ParticleData. The notification is registered by:
void ParticleData::initializeParticle(Particle* init, const Point3F& inheritVelocity)
{
   init->dataBlock = this;  <<<<<<<

   // Calculate the constant accleration...
   init->vel += inheritVelocity * inheritedVelFactor;
   init->acc  = init->vel * constantAcceleration;

However, there is no init->dataBlock = 0 to unregister it while removing.
void ParticleEmitter::advanceTime(F32 dt)
{
   Parent::advanceTime(dt);

   mElapsedTimeMS += (S32)(dt * 1000.0f);

   U32 numMSToUpdate = (U32)(dt * 1000.0f);
   if (numMSToUpdate == 0)
      return;

   Particle** ppProbe = &mParticleListHead;
   while (*ppProbe != NULL) {
      (*ppProbe)->currentAge += numMSToUpdate;
      if ((*ppProbe)->currentAge >= (*ppProbe)->totalLifetime) {
         // Remove this particle
         Particle* remove   = *ppProbe;
		 [b]remove->dataBlock = 0;  <<<<< ADDED <<<<<[/b]
         *ppProbe           = remove->nextInList;
         remove->nextInList = NULL;
         sgParticleEngine->releaseParticle(remove);
      } else {
         ppProbe = &((*ppProbe)->nextInList);
      }
   }

It is no problem if using TGE's memory management. Should I have to change lot of codes if I need to disable the TGE's MM?

#1
08/05/2004 (8:49 am)
I'm a little confused. Does adding that line fix the crash when TGE's MM is enabled? Or only when it is not? It seems like this is a fix that should be in HEAD. :)

TGE's MM is a drop in replacement for the existing memory manager. It allocated memory in large chunks then divvies out what is needed, rather than the traditional approach of asking the OS for every request. You can disable it without changing anything else.
#2
08/05/2004 (6:09 pm)
When TGE'MM enable, it is no crash even no "remove->dataBlock = 0", however, it will crash if no "remove->dataBlock = 0".

I am not sure if the latest HEAD will fix, as I didn't find this line in latest CVS download.

I am not sure if no "remove->dataBlock = 0" when MM is enable, is a automatic handling feature for memory.
#3
08/06/2004 (9:50 am)
I'm not sure the problem is related to the memory manager. Is it crashing when you exit Torque?

FYI, I've re-written a bunch of the particle code in TSE to be more efficient. Including getting rid of the particle linked list which occupies a lot of the code you posted above.
#4
08/06/2004 (4:25 pm)
So much that I don't know about.........
#5
12/24/2010 (3:31 am)
This should be flagged as a bug report if it's not already - I just verified that using this and disabling the MM at the top of platform.h, the engine will crash if you quit the mission while a particle emitter is going. This doesn't happen with the MM enabled.

I still have the crash with the line noted above added, though.