fixed seg faults and leaks
This commit is contained in:
parent
08f66e867c
commit
2188c2efdf
16
src/models.c
16
src/models.c
|
|
@ -3341,10 +3341,11 @@ static unsigned char *DecodeBase64(char *input, int *size)
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Texture LoadTextureFromCGLTFTextureView(cgltf_texture_view* view, Color tint, char* texPath)
|
//static Texture LoadTextureFromCGLTFTextureView(cgltf_texture_view* view, Color tint, char* texPath)
|
||||||
|
static Texture LoadTextureFromCGLTFTextureView(cgltf_image* image, Color tint, const char* texPath)
|
||||||
{
|
{
|
||||||
Texture texture = {0};
|
Texture texture = {0};
|
||||||
cgltf_image *image = view->texture->image;
|
//cgltf_image *image = view->texture->image;
|
||||||
|
|
||||||
if (image->uri)
|
if (image->uri)
|
||||||
{
|
{
|
||||||
|
|
@ -3413,6 +3414,8 @@ static Texture LoadTextureFromCGLTFTextureView(cgltf_texture_view* view, Color t
|
||||||
ImageColorTint(&rimage, tint);
|
ImageColorTint(&rimage, tint);
|
||||||
texture = LoadTextureFromImage(rimage);
|
texture = LoadTextureFromImage(rimage);
|
||||||
UnloadImage(rimage);
|
UnloadImage(rimage);
|
||||||
|
free(raw);
|
||||||
|
free(data);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -3515,8 +3518,11 @@ static Model LoadGLTF(const char *fileName)
|
||||||
float roughness = data->materials[i].pbr_metallic_roughness.roughness_factor;
|
float roughness = data->materials[i].pbr_metallic_roughness.roughness_factor;
|
||||||
float metallic = data->materials[i].pbr_metallic_roughness.metallic_factor;
|
float metallic = data->materials[i].pbr_metallic_roughness.metallic_factor;
|
||||||
|
|
||||||
|
if (model.materials[i].name && data->materials[i].name) {
|
||||||
strcpy(model.materials[i].name, data->materials[i].name);
|
strcpy(model.materials[i].name, data->materials[i].name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// shouldn't these be *255 ???
|
||||||
tint.r = (unsigned char)(data->materials[i].pbr_metallic_roughness.base_color_factor[0]*255.99f);
|
tint.r = (unsigned char)(data->materials[i].pbr_metallic_roughness.base_color_factor[0]*255.99f);
|
||||||
tint.g = (unsigned char)(data->materials[i].pbr_metallic_roughness.base_color_factor[1]*255.99f);
|
tint.g = (unsigned char)(data->materials[i].pbr_metallic_roughness.base_color_factor[1]*255.99f);
|
||||||
tint.b = (unsigned char)(data->materials[i].pbr_metallic_roughness.base_color_factor[2]*255.99f);
|
tint.b = (unsigned char)(data->materials[i].pbr_metallic_roughness.base_color_factor[2]*255.99f);
|
||||||
|
|
@ -3526,14 +3532,20 @@ static Model LoadGLTF(const char *fileName)
|
||||||
|
|
||||||
//tint isn't need for other textures.. pass null or clear?
|
//tint isn't need for other textures.. pass null or clear?
|
||||||
tint = (Color){ 0.0f, 0.0f, 0.0f, 0.0f };
|
tint = (Color){ 0.0f, 0.0f, 0.0f, 0.0f };
|
||||||
|
if (data->materials[i].pbr_metallic_roughness.metallic_roughness_texture.texture) {
|
||||||
model.materials[i].maps[MAP_ROUGHNESS].texture = LoadTextureFromCGLTFTextureView(data->materials[i].pbr_metallic_roughness.metallic_roughness_texture.texture->image, tint, texPath);
|
model.materials[i].maps[MAP_ROUGHNESS].texture = LoadTextureFromCGLTFTextureView(data->materials[i].pbr_metallic_roughness.metallic_roughness_texture.texture->image, tint, texPath);
|
||||||
|
}
|
||||||
model.materials[i].maps[MAP_ROUGHNESS].value = roughness;
|
model.materials[i].maps[MAP_ROUGHNESS].value = roughness;
|
||||||
model.materials[i].maps[MAP_METALNESS].value = metallic;
|
model.materials[i].maps[MAP_METALNESS].value = metallic;
|
||||||
|
|
||||||
|
if (data->materials[i].normal_texture.texture) {
|
||||||
model.materials[i].maps[MAP_NORMAL].texture = LoadTextureFromCGLTFTextureView(data->materials[i].normal_texture.texture->image, tint, texPath);
|
model.materials[i].maps[MAP_NORMAL].texture = LoadTextureFromCGLTFTextureView(data->materials[i].normal_texture.texture->image, tint, texPath);
|
||||||
|
}
|
||||||
|
if (data->materials[i].occlusion_texture.texture) {
|
||||||
model.materials[i].maps[MAP_OCCLUSION].texture = LoadTextureFromCGLTFTextureView(data->materials[i].occlusion_texture.texture->image, tint, texPath);
|
model.materials[i].maps[MAP_OCCLUSION].texture = LoadTextureFromCGLTFTextureView(data->materials[i].occlusion_texture.texture->image, tint, texPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
model.materials[model.materialCount - 1] = LoadMaterialDefault();
|
model.materials[model.materialCount - 1] = LoadMaterialDefault();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user