Game Development Community

Atlas Bug

by John Carroll · in Torque Game Engine Advanced · 07/07/2008 (8:26 am) · 1 replies

Hi, in atlasResourceTOC.h the following code block is incorrect:

static S32 updateStubSortFunc(const void *a, const void *b)
   {
      const StubType *aS = (const StubType*)a;
      const StubType *bS = (const StubType*)b;

      return (aS->mPriority > bS->mPriority ? 1 : -1);
   }

the following explains why it is incorrect, and the fix....

// serious problem!!! this function is called by the standard implementation
// of qsort... the compare function returns pointers to the elements to 
// the compared... since our elements are in a Vector<StubType*>, we 
// are comparing pointers to StubTypes. This means that a and b are
// pointers TO pointers OF stubs... NOT pointers of stubs!
   static S32 updateStubSortFunc(const void *a, const void *b)
   {
      const StubType *aS = *(const StubType**)a;
      const StubType *bS = *(const StubType**)b;

      return (aS->mPriority > bS->mPriority ? 1 : -1);
   }

About the author

Working on using Torque as an Image Generator for Tactical Simulations under laser and live fire conditions, for Law Enforcement/Military applications.


#1
07/07/2008 (3:41 pm)
Good find!

For complete correctness, the function should also return zero on equality.