From 29df28d7d354dec485fcf2bc4e6a36d44fef0347 Mon Sep 17 00:00:00 2001 From: Pichas Date: Sat, 14 Mar 2026 17:57:22 -0500 Subject: [PATCH] Fix memory leak for USD importer (#6549) * initial commit * remove unused function --- code/AssetLib/USD/USDLoaderImplTinyusdz.cpp | 24 +++++++-------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/code/AssetLib/USD/USDLoaderImplTinyusdz.cpp b/code/AssetLib/USD/USDLoaderImplTinyusdz.cpp index 4f0513e2e..3fdfc71dd 100644 --- a/code/AssetLib/USD/USDLoaderImplTinyusdz.cpp +++ b/code/AssetLib/USD/USDLoaderImplTinyusdz.cpp @@ -511,14 +511,6 @@ void USDImporterImplTinyusdz::uvsForMesh( } } -static aiColor3D *ownedColorPtrFor(const std::array &color) { - aiColor3D *colorPtr = new aiColor3D(); - colorPtr->r = color[0]; - colorPtr->g = color[1]; - colorPtr->b = color[2]; - return colorPtr; -} - static std::string nameForTextureWithId(const RenderScene &render_scene, const int targetId) { std::stringstream ss; std::string texName; @@ -544,14 +536,14 @@ static void assignTexture( const int textureId, const int aiTextureType) { std::string name = nameForTextureWithId(render_scene, textureId); - aiString *texName = new aiString(); - texName->Set(name); + aiString texName; + texName.Set(name); std::stringstream ss; ss.str(""); ss << "assignTexture(): name: " << name; TINYUSDZLOGD(TAG, "%s", ss.str().c_str()); // TODO: verify hard-coded '0' index is correct - mat->AddProperty(texName, _AI_MATKEY_TEXTURE_BASE, aiTextureType, 0); + mat->AddProperty(&texName, _AI_MATKEY_TEXTURE_BASE, aiTextureType, 0); } void USDImporterImplTinyusdz::materials( @@ -575,18 +567,18 @@ void USDImporterImplTinyusdz::materials( TINYUSDZLOGD(TAG, "%s", ss.str().c_str()); aiMaterial *mat = new aiMaterial; - aiString *materialName = new aiString(); - materialName->Set(material.name); + aiString materialName; + materialName.Set(material.name); mat->AddProperty(materialName, AI_MATKEY_NAME); mat->AddProperty( - ownedColorPtrFor(material.surfaceShader.diffuseColor.value), + reinterpret_cast(material.surfaceShader.diffuseColor.value.data()), 1, AI_MATKEY_COLOR_DIFFUSE); mat->AddProperty( - ownedColorPtrFor(material.surfaceShader.specularColor.value), + reinterpret_cast(material.surfaceShader.specularColor.value.data()), 1, AI_MATKEY_COLOR_SPECULAR); mat->AddProperty( - ownedColorPtrFor(material.surfaceShader.emissiveColor.value), + reinterpret_cast(material.surfaceShader.emissiveColor.value.data()), 1, AI_MATKEY_COLOR_EMISSIVE); ss.str("");