Game Development Community

GBitmap() copy does not support palette's

by James Urquhart · in Torque Game Engine · 12/18/2004 (12:00 am) · 3 replies

To put it simply, there is a nice AssertFatal in "GBitmap::GBitmap(const GBitmap& rCopy)" (dgl/gBitmap.cpp), as follows :

AssertFatal(rCopy.pPalette == NULL, "Cant copy bitmaps with palettes");

This assert is rarely called, as nothing really copies palette'd GBitmap's. However, to implement this rather simple functionality, the following should suffice :

if (rCopy.pPalette) {
      pPalette = new GPalette;
      pPalette->setPaletteType(rCopy.pPalette->getPaletteType());
      dMemcpy(rCopy.pPalette->getColors(), pPalette->getColors(), sizeof(ColorI)*256);
   } else pPalette = NULL;

And of course, remove this line at the end :

pPalette = NULL;

Since every GBitmap seems to need an individual palette object (as it is deleted on a per-GBitmap basis), i don't see any problem with this method of duplication.

#1
12/18/2004 (12:19 am)
Hey buddy, I got a problem with you... :P

This looks like a great fix. I assume you're using it in your own projects?

Anyway, I'll put this on my todo list. Thanks, James!
#2
12/18/2004 (12:38 am)
Ben,

I was messing about with the rather horrendous interior lightmap loading code; And for some reason, it tried to copy a GBitmap with a palette. No doubt there's a few memory crapups somewhere ;)
#3
03/14/2005 (11:16 pm)
Thanks, James. Fix is in.