瀏覽代碼

Copy texture data before handing on to asset which then handles freeing of the memory. This prevents the memory being released twice which was throwing an error. Fixes issue #2714.

Paul Arden 6 年之前
父節點
當前提交
9aa9238e7e
共有 1 個文件被更改,包括 3 次插入1 次删除
  1. 3 1
      code/glTF2/glTF2Exporter.cpp

+ 3 - 1
code/glTF2/glTF2Exporter.cpp

@@ -320,7 +320,9 @@ 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])];
 
 
-                        uint8_t* data = reinterpret_cast<uint8_t*>(tex->pcData);
+                        // copy data since lifetime control is handed over to the asset
+                        uint8_t* data = new uint8_t[tex->mWidth];
+                        memcpy(data, tex->pcData, tex->mWidth);
                         texture->source->SetData(data, tex->mWidth, *mAsset);
                         texture->source->SetData(data, tex->mWidth, *mAsset);
 
 
                         if (tex->achFormatHint[0]) {
                         if (tex->achFormatHint[0]) {