Game Development Community

Torque 1.4 HEAD guiTreeViewCtlr.cc

by Gregory "Centove" McLean · in Torque Game Engine · 10/23/2005 (6:10 pm) · 4 replies

This may only affect the linux/gcc combination...

None of the tree icons were loading and I was getting loads of 'Could not locate texture: com' in the log.

In the guiTreeViewCtrl.cc file around line 990
char *buf = (char*)txtBuff.alloc(sizeof(char) * 64);
   char* token = dStrtok( drawText, ":" );

   // Count the number of icons and store them.
   while (token && numIcons < MaxIcons)
   {
      dSprintf( buf, sizeof( buf ), "%s", token );
      mIconTable[numIcons] = TextureHandle( buf, BitmapKeepTexture );
      token = dStrtok( NULL, ":" );
      numIcons++;
   }
On linux that 'sizeof( buf )' turns out to be 4. So we were passing to the resource manager to load 'com' which it dutifly reported it couldn't load.

Also, what happens if by some odd chance the path of an icon is more then 64 chars?

Proposed fix:
char *buf;
   char* token = dStrtok( drawText, ":" );

   // Count the number of icons and store them.
   while (token && numIcons < MaxIcons)
   {
      buf = (char *)txtBuff.alloc(sizeof(char) * (dStrlen(token) + 1));
      dSprintf( buf, dStrlen(token) + 1, "%s", token );
      mIconTable[numIcons] = TextureHandle( buf, BitmapKeepTexture );
      token = dStrtok( NULL, ":" );
      numIcons++;
   }

This works here on the linux build. And I now see icons, and in case some nut out there wants icon paths to be
'/some/really/really/long/path/to/the/icons/just/cause/we/can/and/watch/things/blow/up'
It won't puke on it. Seeing as its using the FrameAllocator it shouldn't thrash memory to bad.

#1
10/31/2005 (8:09 am)
Actually after staring at this a bit more, I'm not so sure that all that copying is needed?

while (token && numIcons < MaxIcons)
   {
 
      mIconTable[numIcons] = TextureHandle( token , BitmapKeepTexture );
      token = dStrtok( NULL, ":" );
      numIcons++;
   }

Seems to work just as well.
#2
11/05/2005 (12:03 pm)
This change will be added to my 1.4.0 update today

-Ron
#3
12/09/2005 (7:53 pm)
Fixed and pushed to SVN
#4
01/25/2006 (9:48 pm)
There's an almost identical big around line 200 of the same file (guiTreeViewCtrl.cc), in a call to dSprintf().

dSprintf(prefix, sizeof(prefix), "%s%s%s%s",