fixed leaks, also see pbr example review required
This commit is contained in:
parent
65e942e5be
commit
5dd8ee76ba
|
|
@ -98,7 +98,17 @@ int main(void)
|
||||||
|
|
||||||
// De-Initialization
|
// De-Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
UnloadMaterial(model.materials[0]); // Unload material: shader and textures
|
//
|
||||||
|
|
||||||
|
// REQUIRES REVIEW
|
||||||
|
// as unload model removes *just* the maps now (user may be using shaders
|
||||||
|
// and textures elsewhere) when using a custom material you need to unload
|
||||||
|
// it then give the model a default model (to avoid double free)
|
||||||
|
// how ever this still results in a small leak....
|
||||||
|
|
||||||
|
UnloadMaterial(model.materials[0]);
|
||||||
|
model.materials[0] = LoadMaterialDefault();
|
||||||
|
|
||||||
UnloadModel(model); // Unload model
|
UnloadModel(model); // Unload model
|
||||||
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
|
|
|
||||||
13
src/models.c
13
src/models.c
|
|
@ -669,7 +669,8 @@ Model LoadModel(const char *fileName)
|
||||||
model.materials = (Material *)RL_CALLOC(model.materialCount, sizeof(Material));
|
model.materials = (Material *)RL_CALLOC(model.materialCount, sizeof(Material));
|
||||||
model.materials[0] = LoadMaterialDefault();
|
model.materials[0] = LoadMaterialDefault();
|
||||||
|
|
||||||
model.meshMaterial = (int *)RL_CALLOC(model.meshCount, sizeof(int));
|
// this is a double allocation, as LoadXXX should do it....
|
||||||
|
//model.meshMaterial = (int *)RL_CALLOC(model.meshCount, sizeof(int));
|
||||||
}
|
}
|
||||||
|
|
||||||
return model;
|
return model;
|
||||||
|
|
@ -2797,10 +2798,11 @@ static Model LoadOBJ(const char *fileName)
|
||||||
{
|
{
|
||||||
model.materialCount = materialCount;
|
model.materialCount = materialCount;
|
||||||
model.materials = (Material *)RL_CALLOC(model.materialCount, sizeof(Material));
|
model.materials = (Material *)RL_CALLOC(model.materialCount, sizeof(Material));
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
model.meshMaterial = (int *)RL_CALLOC(model.meshCount, sizeof(int));
|
model.meshMaterial = (int *)RL_CALLOC(model.meshCount, sizeof(int));
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// Multiple meshes data reference
|
// Multiple meshes data reference
|
||||||
// NOTE: They are provided as a faces offset
|
// NOTE: They are provided as a faces offset
|
||||||
|
|
@ -2915,12 +2917,17 @@ static Model LoadOBJ(const char *fileName)
|
||||||
if (materials[m].displacement_texname != NULL) model.materials[m].maps[MAP_HEIGHT].texture = LoadTexture(materials[m].displacement_texname); //char *displacement_texname; // disp
|
if (materials[m].displacement_texname != NULL) model.materials[m].maps[MAP_HEIGHT].texture = LoadTexture(materials[m].displacement_texname); //char *displacement_texname; // disp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (model.meshMaterial[0]==-1) {
|
||||||
|
model.meshMaterial[0] = 0; // will be given default material by LoadModel
|
||||||
|
}
|
||||||
|
|
||||||
tinyobj_attrib_free(&attrib);
|
tinyobj_attrib_free(&attrib);
|
||||||
tinyobj_shapes_free(meshes, meshCount);
|
tinyobj_shapes_free(meshes, meshCount);
|
||||||
tinyobj_materials_free(materials, materialCount);
|
tinyobj_materials_free(materials, materialCount);
|
||||||
RL_FREE(data); // oh ray how did you miss this...! :-p
|
RL_FREE(data); // oh ray how did you miss this...! :-p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// NOTE: At this point we have all model data loaded
|
// NOTE: At this point we have all model data loaded
|
||||||
TraceLog(LOG_INFO, "[%s] Model loaded successfully in RAM (CPU)", fileName);
|
TraceLog(LOG_INFO, "[%s] Model loaded successfully in RAM (CPU)", fileName);
|
||||||
|
|
||||||
|
|
@ -3251,6 +3258,8 @@ static Model LoadIQM(const char *fileName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
model.meshMaterial = (int *)RL_CALLOC(model.meshCount, sizeof(int));
|
||||||
|
|
||||||
fclose(iqmFile);
|
fclose(iqmFile);
|
||||||
RL_FREE(imesh);
|
RL_FREE(imesh);
|
||||||
RL_FREE(tri);
|
RL_FREE(tri);
|
||||||
|
|
|
||||||
|
|
@ -468,13 +468,17 @@ static void InitAudioBufferPool()
|
||||||
for (int i = 0; i < MAX_AUDIO_BUFFER_POOL_CHANNELS; i++)
|
for (int i = 0; i < MAX_AUDIO_BUFFER_POOL_CHANNELS; i++)
|
||||||
{
|
{
|
||||||
audioBufferPool[i] = InitAudioBuffer(DEVICE_FORMAT, DEVICE_CHANNELS, DEVICE_SAMPLE_RATE, 0, AUDIO_BUFFER_USAGE_STATIC);
|
audioBufferPool[i] = InitAudioBuffer(DEVICE_FORMAT, DEVICE_CHANNELS, DEVICE_SAMPLE_RATE, 0, AUDIO_BUFFER_USAGE_STATIC);
|
||||||
|
// Not needed (only the audiobuffer header) - leak prevention!
|
||||||
|
RL_FREE(audioBufferPool[i]->buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close the audio buffers pool
|
// Close the audio buffers pool
|
||||||
static void CloseAudioBufferPool()
|
static void CloseAudioBufferPool()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < MAX_AUDIO_BUFFER_POOL_CHANNELS; i++) RL_FREE(audioBufferPool[i]);
|
for (int i = 0; i < MAX_AUDIO_BUFFER_POOL_CHANNELS; i++) {
|
||||||
|
RL_FREE(audioBufferPool[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user