Fix: gltf exporting memory leak
parent
2e56450984
commit
1cae51615f
|
@ -688,7 +688,9 @@ inline void Image::SetData(uint8_t* data, size_t length, Asset& r)
|
||||||
bufferView->byteOffset = b->AppendData(data, length);
|
bufferView->byteOffset = b->AppendData(data, length);
|
||||||
}
|
}
|
||||||
else { // text file: will be stored as a data uri
|
else { // text file: will be stored as a data uri
|
||||||
this->mData.reset(data);
|
uint8_t *temp = new uint8_t[length];
|
||||||
|
memcpy(temp, data, length);
|
||||||
|
this->mData.reset(temp);
|
||||||
this->mDataLength = length;
|
this->mDataLength = length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,17 +100,16 @@ glTFExporter::glTFExporter(const char* filename, IOSystem* pIOSystem, const aiSc
|
||||||
{
|
{
|
||||||
aiScene* sceneCopy_tmp;
|
aiScene* sceneCopy_tmp;
|
||||||
SceneCombiner::CopyScene(&sceneCopy_tmp, pScene);
|
SceneCombiner::CopyScene(&sceneCopy_tmp, pScene);
|
||||||
aiScene *sceneCopy(sceneCopy_tmp);
|
|
||||||
|
|
||||||
SplitLargeMeshesProcess_Triangle tri_splitter;
|
SplitLargeMeshesProcess_Triangle tri_splitter;
|
||||||
tri_splitter.SetLimit(0xffff);
|
tri_splitter.SetLimit(0xffff);
|
||||||
tri_splitter.Execute(sceneCopy);
|
tri_splitter.Execute(sceneCopy_tmp);
|
||||||
|
|
||||||
SplitLargeMeshesProcess_Vertex vert_splitter;
|
SplitLargeMeshesProcess_Vertex vert_splitter;
|
||||||
vert_splitter.SetLimit(0xffff);
|
vert_splitter.SetLimit(0xffff);
|
||||||
vert_splitter.Execute(sceneCopy);
|
vert_splitter.Execute(sceneCopy_tmp);
|
||||||
|
|
||||||
mScene = sceneCopy;
|
mScene.reset(sceneCopy_tmp);
|
||||||
|
|
||||||
mAsset.reset( new glTF::Asset( pIOSystem ) );
|
mAsset.reset( new glTF::Asset( pIOSystem ) );
|
||||||
|
|
||||||
|
@ -877,7 +876,7 @@ void glTFExporter::ExportMetadata()
|
||||||
|
|
||||||
// Copyright
|
// Copyright
|
||||||
aiString copyright_str;
|
aiString copyright_str;
|
||||||
if (mScene->mMetaData->Get(AI_METADATA_SOURCE_COPYRIGHT, copyright_str)) {
|
if (mScene->mMetaData != nullptr && mScene->mMetaData->Get(AI_METADATA_SOURCE_COPYRIGHT, copyright_str)) {
|
||||||
asset.copyright = copyright_str.C_Str();
|
asset.copyright = copyright_str.C_Str();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,7 +90,7 @@ namespace Assimp
|
||||||
|
|
||||||
const char* mFilename;
|
const char* mFilename;
|
||||||
IOSystem* mIOSystem;
|
IOSystem* mIOSystem;
|
||||||
const aiScene* mScene;
|
std::shared_ptr<const aiScene> mScene;
|
||||||
const ExportProperties* mProperties;
|
const ExportProperties* mProperties;
|
||||||
|
|
||||||
std::map<std::string, unsigned int> mTexturesByPath;
|
std::map<std::string, unsigned int> mTexturesByPath;
|
||||||
|
|
|
@ -752,6 +752,7 @@ inline uint8_t* Image::StealData()
|
||||||
return mData.release();
|
return mData.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Never take over the ownership of data whenever binary or not
|
||||||
inline void Image::SetData(uint8_t* data, size_t length, Asset& r)
|
inline void Image::SetData(uint8_t* data, size_t length, Asset& r)
|
||||||
{
|
{
|
||||||
Ref<Buffer> b = r.GetBodyBuffer();
|
Ref<Buffer> b = r.GetBodyBuffer();
|
||||||
|
@ -764,8 +765,10 @@ inline void Image::SetData(uint8_t* data, size_t length, Asset& r)
|
||||||
bufferView->byteOffset = b->AppendData(data, length);
|
bufferView->byteOffset = b->AppendData(data, length);
|
||||||
}
|
}
|
||||||
else { // text file: will be stored as a data uri
|
else { // text file: will be stored as a data uri
|
||||||
this->mData.reset(data);
|
uint8_t *temp = new uint8_t[length];
|
||||||
this->mDataLength = length;
|
memcpy(temp, data, length);
|
||||||
|
this->mData.reset(temp);
|
||||||
|
this->mDataLength = length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -352,10 +352,8 @@ void glTF2Exporter::GetMatTex(const aiMaterial* mat, Ref<Texture>& texture, aiTe
|
||||||
if (path[0] == '*') { // embedded
|
if (path[0] == '*') { // embedded
|
||||||
aiTexture* tex = mScene->mTextures[atoi(&path[1])];
|
aiTexture* tex = mScene->mTextures[atoi(&path[1])];
|
||||||
|
|
||||||
// copy data since lifetime control is handed over to the asset
|
// The asset has its own buffer, see Image::SetData
|
||||||
uint8_t* data = new uint8_t[tex->mWidth];
|
texture->source->SetData(reinterpret_cast<uint8_t*> (tex->pcData), tex->mWidth, *mAsset);
|
||||||
memcpy(data, tex->pcData, tex->mWidth);
|
|
||||||
texture->source->SetData(data, tex->mWidth, *mAsset);
|
|
||||||
|
|
||||||
if (tex->achFormatHint[0]) {
|
if (tex->achFormatHint[0]) {
|
||||||
std::string mimeType = "image/";
|
std::string mimeType = "image/";
|
||||||
|
|
Loading…
Reference in New Issue