Skip to content

Commit

Permalink
Don't delete textures that were never loaded on a model
Browse files Browse the repository at this point in the history
  • Loading branch information
stuarthayhurst committed Jul 29, 2024
1 parent 1f448a0 commit ac75e50
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/ammonite/graphics/textures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ namespace ammonite {
}

/*
- Create a texture with from the data given, return its ID
- Create a texture from the data given, return its ID
- This doesn't generate the mipmaps, but allocates space for them
- externalSuccess is written to on failure
*/
Expand Down
9 changes: 7 additions & 2 deletions src/ammonite/models/models.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,13 @@ namespace ammonite {
if (modelObjectData->refCount < 1) {
//Reduce reference count on textures
for (unsigned int i = 0; i < modelObjectData->meshes.size(); i++) {
ammonite::textures::internal::deleteTexture(modelObject->textureIds[i].diffuseId);
ammonite::textures::internal::deleteTexture(modelObject->textureIds[i].specularId);
if (modelObject->textureIds[i].diffuseId != -1) {
ammonite::textures::internal::deleteTexture(modelObject->textureIds[i].diffuseId);
}

if (modelObject->textureIds[i].specularId != -1) {
ammonite::textures::internal::deleteTexture(modelObject->textureIds[i].specularId);
}
}

//Free the data if it hasn't been already
Expand Down

0 comments on commit ac75e50

Please sign in to comment.