Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Vertical callback or per pixel callback : I understand/How does Tilengine work?
#15
(08-30-2023, 06:18 PM)megamarc Wrote: Hi,

As a general rule, there are two things to take into account when dealing with resources:

1. Don't delete a resource you don't own.

You own a resource when you explicitly create, load or clone it. You don't own a resource that has been chain-loaded and is a child of another resource. You should not do this:

Code:
TLN_Tilemap tilemap = TLN_LoadTilemap("tilemap.tmx", NULL); // load tilemap, you own it
TLN_Tileset tileset = TLN_GetTilemapTileset(tilemap); // gets chain-loaded tileset, you don't own it
TLN_DeleteTileset(tileset); // wrong! you don't own the tileset

2. Don't delete a resource that is currently assigned to the renderer.

Also applies to child resources, when you delete an owned resource, all of its owned child resources get deleted with it

Code:
TLN_Tileset tileset = TLN_LoadTileset("tileset.tsx"); // loads tileset
TLN_Palette palette = TLN_GetTilesetPalette(tileset); // gets palette of tileset
TLN_SetLayerPalette(0, palette); // assigns child palette to layer renderer
TLN_DeleteTileset(tileset); // wrong! tileset's palette is still atached to layer 0 but gets destroyed

Hi!
Makes sense!
Now I only delete tilemaps from layers, I don't touch their tilesets nor their palettes and so on.
so I just can do 

TLN_Tilemap tilemap = TLN_GetLayerTilemap(myLayer);
TLN_DeleteTilemap(tilemap);
tilemap = NULL;

?
Reply


Messages In This Thread
RE: Vertical callback or per pixel callback : I understand/How does Tilengine work? - by System64 - 08-30-2023, 08:38 PM

Forum Jump:


Users browsing this thread: 6 Guest(s)