diff --git a/src/load_anim_data.c b/src/load_anim_data.c index 08c0c95..031e4ef 100644 --- a/src/load_anim_data.c +++ b/src/load_anim_data.c @@ -2,7 +2,8 @@ #include -struct Animation *g_libsm64_mario_animations; +static uint32_t s_num_entries = 0; +struct Animation *g_libsm64_mario_animations = NULL; #define ANIM_DATA_ADDRESS 0x004EC000 @@ -34,12 +35,12 @@ void load_mario_anims_from_rom( uint8_t *rom ) #define GET_SIZE( n ) (read_u32_be(&((struct OffsetSizePair*)( rom + ANIM_DATA_ADDRESS + 8 + (n)*8 ))->size )) uint8_t *read_ptr = rom + ANIM_DATA_ADDRESS; - uint32_t num_entries = read_u32_be( read_ptr ); + s_num_entries = read_u32_be( read_ptr ); - g_libsm64_mario_animations = malloc( num_entries * sizeof( struct Animation )); + g_libsm64_mario_animations = malloc( s_num_entries * sizeof( struct Animation )); struct Animation *anims = g_libsm64_mario_animations; - for( int i = 0; i < num_entries; ++i ) + for( int i = 0; i < s_num_entries; ++i ) { read_ptr = rom + ANIM_DATA_ADDRESS + GET_OFFSET(i); @@ -81,7 +82,13 @@ void load_mario_anims_from_rom( uint8_t *rom ) void unload_mario_anims( void ) { - // TODO free index and values arrays + for( int i = 0; i < s_num_entries; ++i ) + { + free( g_libsm64_mario_animations[i].index ); + free( g_libsm64_mario_animations[i].values ); + } + free( g_libsm64_mario_animations ); g_libsm64_mario_animations = NULL; + s_num_entries = 0; } \ No newline at end of file