Handmade Hero»Forums»Code
Roderic Bos
70 posts
Day 243 question about deallocate
Instead of needing an asset_header_type and checking for bitmap couldn't you just check to see if you have a non zero Bitmap and a non zero TextureHandle and then call release? Or can there be a scenario that this will fail?

Furthermore FinalizeAsset_Bitmap is never set on the asset so the textureload is never called yet.
Mārtiņš Možeiko
2559 posts / 2 projects
Day 243 question about deallocate
Edited by Mārtiņš Možeiko on
Chcecking handle for nonzero won't work, because loaded assets are stored in union:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
struct asset_memory_header
{
    asset_memory_header *Next;
    asset_memory_header *Prev;
   
    u32 AssetIndex;
    u32 TotalSize;
    u32 GenerationID;
    union
    {
        loaded_bitmap Bitmap;
        loaded_sound Sound;
        loaded_font Font;
    };
};

If asset is something other that bitmap, then Bitmap.TextureHandle value can be nonzero, but it will contain complete garbage.
Roderic Bos
70 posts
Day 243 question about deallocate
Ah yeah that makes loads of sense, thanks!