Dont leak memory when calling load surfaces multiple times
This commit is contained in:
+3
-1
@@ -5,4 +5,6 @@
|
|||||||
/test/level.h
|
/test/level.h
|
||||||
run-test
|
run-test
|
||||||
*.z64
|
*.z64
|
||||||
*.so
|
*.so
|
||||||
|
compile_commands.json
|
||||||
|
/.cache/
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <stdio.h> // For printf before exit, TODO remove
|
||||||
|
|
||||||
#include "../shim.h"
|
#include "../shim.h"
|
||||||
#include "../include/PR/os_cont.h"
|
#include "../include/PR/os_cont.h"
|
||||||
|
|||||||
+3
-3
@@ -122,9 +122,9 @@ SM64_LIB_FN void sm64_static_surfaces_load( const struct SM64Surface *surfaceArr
|
|||||||
surfaces_load_static( surfaceArray, numSurfaces );
|
surfaces_load_static( surfaceArray, numSurfaces );
|
||||||
}
|
}
|
||||||
|
|
||||||
SM64_LIB_FN uint32_t sm64_mario_create( int16_t x, int16_t y, int16_t z )
|
SM64_LIB_FN int32_t sm64_mario_create( int16_t x, int16_t y, int16_t z )
|
||||||
{
|
{
|
||||||
uint32_t marioIndex = obj_pool_alloc_index( &s_mario_instance_pool, sizeof( struct MarioInstance ));
|
int32_t marioIndex = obj_pool_alloc_index( &s_mario_instance_pool, sizeof( struct MarioInstance ));
|
||||||
struct MarioInstance *newInstance = s_mario_instance_pool.objects[marioIndex];
|
struct MarioInstance *newInstance = s_mario_instance_pool.objects[marioIndex];
|
||||||
|
|
||||||
newInstance->globalState = global_state_create();
|
newInstance->globalState = global_state_create();
|
||||||
@@ -241,4 +241,4 @@ SM64_LIB_FN void sm64_surface_object_delete( uint32_t objectId )
|
|||||||
}
|
}
|
||||||
|
|
||||||
surfaces_unload_object( objectId );
|
surfaces_unload_object( objectId );
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -74,7 +74,7 @@ extern SM64_LIB_FN void sm64_global_terminate( void );
|
|||||||
|
|
||||||
extern SM64_LIB_FN void sm64_static_surfaces_load( const struct SM64Surface *surfaceArray, uint32_t numSurfaces );
|
extern SM64_LIB_FN void sm64_static_surfaces_load( const struct SM64Surface *surfaceArray, uint32_t numSurfaces );
|
||||||
|
|
||||||
extern SM64_LIB_FN uint32_t sm64_mario_create( int16_t x, int16_t y, int16_t z );
|
extern SM64_LIB_FN int32_t sm64_mario_create( int16_t x, int16_t y, int16_t z );
|
||||||
extern SM64_LIB_FN void sm64_mario_tick( uint32_t marioId, const struct SM64MarioInputs *inputs, struct SM64MarioState *outState, struct SM64MarioGeometryBuffers *outBuffers );
|
extern SM64_LIB_FN void sm64_mario_tick( uint32_t marioId, const struct SM64MarioInputs *inputs, struct SM64MarioState *outState, struct SM64MarioGeometryBuffers *outBuffers );
|
||||||
extern SM64_LIB_FN void sm64_mario_delete( uint32_t marioId );
|
extern SM64_LIB_FN void sm64_mario_delete( uint32_t marioId );
|
||||||
|
|
||||||
|
|||||||
@@ -223,6 +223,9 @@ struct Surface *loaded_surface_iter_get_at_index( uint32_t groupIndex, uint32_t
|
|||||||
|
|
||||||
void surfaces_load_static( const struct SM64Surface *surfaceArray, uint32_t numSurfaces )
|
void surfaces_load_static( const struct SM64Surface *surfaceArray, uint32_t numSurfaces )
|
||||||
{
|
{
|
||||||
|
if( s_static_surface_list != NULL )
|
||||||
|
free( s_static_surface_list );
|
||||||
|
|
||||||
s_static_surface_count = numSurfaces;
|
s_static_surface_count = numSurfaces;
|
||||||
s_static_surface_list = malloc( sizeof( struct Surface ) * numSurfaces );
|
s_static_surface_list = malloc( sizeof( struct Surface ) * numSurfaces );
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user