Game Development Community

ResManager::add() problem

by James Urquhart · in Torque Game Engine · 12/21/2004 (12:44 pm) · 4 replies

There seems to be something missing in "bool ResManager::add (const char *name, ResourceInstance * addInstance, bool extraLock)"

The code sets the ResourceObject's instance to the supplied addInstance. However, it never sets the ResourceInstance's "mSourceResource" to the ResourceObject.

To fix this, add in the following line :

...
   dictionary.pushBehind (obj,
          ResourceObject::File | ResourceObject::VolumeBlock);
   obj->mInstance = addInstance;
   addInstance->mSourceResource = obj; // << Add this line
   obj->lockCount = extraLock ? 2 : 1;
   ...

#1
12/21/2004 (5:18 pm)
What sort of bugs does this snafu cause? (Duly noted in todo list, btw.)
#2
12/24/2004 (7:11 am)
Ben,

A problem would only arise if one wanted to use a ResourceInstance object added via ResManager::add, either through using the one passed on, or via grabbing the instance via ResManager::load.
The ResourceInstance would not be able to get its "mSourceResource", if it relied on it to, say, open a new stream (via ResManager::openStream()).

Example Code:
ResourceInstance *myInst = new ResourceInstance();
ResourceManager->add("my_file.txt", myInst, false);
AssertFatal(myInst->mSourceResource, "We don't know our own resource!");

InteriorInstance *inst = new InteriorInstance();
ResourceManager->add("my_interior.dif", inst, false);

// Now load the instance again, which should load the one we have just added
inst = ResourceManager->load("my_interior.dif");
AssertFatal(inst->mSourceResource, "We don't know our own resource!");
#3
12/24/2004 (7:31 am)
I wonder if this explains Thomas' problem with working with resource manager from a while ago...I can't remember the exact topic name, but he was having problems with openStream() IIRC...
#4
03/14/2005 (11:32 pm)
Ok, fix is in. Thank you both very much!