summaryrefslogtreecommitdiff
path: root/src/state.c
diff options
context:
space:
mode:
authorjussi2022-04-05 01:38:03 +0300
committerjussi2022-04-05 01:38:03 +0300
commitfbfe1e0cb6207b6c8afd42457cb1304c7264734f (patch)
treebeb8e4725b6e9842fee5f929ad3f3b24663a26d2 /src/state.c
parent2a46afbf91c17463b1360faf7773a9aeb69b4e46 (diff)
downloadreilua-enhanced-fbfe1e0cb6207b6c8afd42457cb1304c7264734f.tar.gz
reilua-enhanced-fbfe1e0cb6207b6c8afd42457cb1304c7264734f.tar.bz2
reilua-enhanced-fbfe1e0cb6207b6c8afd42457cb1304c7264734f.zip
Lights.
Diffstat (limited to 'src/state.c')
-rw-r--r--src/state.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/state.c b/src/state.c
index d9b2ad4..cd7629b 100644
--- a/src/state.c
+++ b/src/state.c
@@ -61,6 +61,10 @@ bool stateInit( const char *exePath ) {
state->shaderAlloc = ALLOC_PAGE_SIZE;
state->shaderCount = 0;
state->shaders = malloc( state->shaderAlloc * sizeof( Shader* ) );
+ /* Lights. */
+ state->lightAlloc = ALLOC_PAGE_SIZE;
+ state->lightCount = 0;
+ state->lights = malloc( state->lightAlloc * sizeof( Light* ) );
for ( int i = 0; i < ALLOC_PAGE_SIZE; i++ ) {
state->images[i] = NULL;
@@ -72,6 +76,7 @@ bool stateInit( const char *exePath ) {
state->models[i] = NULL;
state->animations[i] = NULL;
state->shaders[i] = NULL;
+ state->lights[i] = NULL;
/* The ones we want to save the first. */
if ( 0 < i ) {
@@ -152,6 +157,9 @@ void stateFree() {
}
for ( int i = 0; i < state->materialCount; ++i ) {
if ( state->materials[i] != NULL ) {
+ /* Prevent unloading shader that would result in double free when freeing shaders. */
+ state->materials[i]->shader.id = rlGetShaderIdDefault();
+
UnloadMaterial( *state->materials[i] );
free( state->materials[i] );
}
@@ -168,6 +176,11 @@ void stateFree() {
free( state->shaders[i] );
}
}
+ for ( int i = 0; i < state->lightCount; ++i ) {
+ if ( state->lights[i] != NULL ) {
+ free( state->lights[i] );
+ }
+ }
if ( IsAudioDeviceReady() ) {
CloseAudioDevice();
@@ -190,5 +203,6 @@ void stateFree() {
free( state->models );
free( state->animations );
free( state->shaders );
+ free( state->lights );
free( state );
}