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 :
This assert is rarely called, as nothing really copies palette'd GBitmap's. However, to implement this rather simple functionality, the following should suffice :
And of course, remove this line at the end :
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.
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.
About the author
Associate Kyle Carter
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!