10-29-2022, 10:30 PM
(10-29-2022, 07:44 PM)megamarc Wrote: Hi! Thanks for your suggestion.
However, it's not recommended to modify linked resources that have been loaded recursively. For example when you load a tileset or a bitmap, a palette is also loaded/created as a child reference, and the parent resource "owns" the palette, When you destroy the tileset or bitmap, its palette is also destroyed. If not, there would be a memory leak. If you change the palette of a bitmap or tileset, and then destroy the parent resource, the engine will destroy the wrong palette and leave the original palette "orphaned" and leaked. That's why is not a good idea to modify their palettes, instead, set the layer palette with TLN_SetLayerPalette()
This alwo happens with tilesets that are loaded and owned by a particular tilemap.
Effectively, I wrote this code :
Code:
bool TLN_SetTilesetPalette(TLN_Tileset tileset, TLN_Palette palette)
{
if (CheckBaseObject(tileset, OT_TILESET) && palette != NULL)
{
TLN_SetLastError(TLN_ERR_OK);
tileset->palette = palette;
return true;
}
else
return false;
}
and the old palette isn't cleaned up.
Can TLN_SetLayerPalette() deal with tilesets palettes? It wasn't a problem when you had only one tileset per layer to deal with, so only one palette. But now you can have up to 8 tilesets per layer, so up to 8 palettes to deal with.