[Libreoffice-commits] core.git: avmedia/source external/libgltf

Zolnai Tamás tamas.zolnai at collabora.com
Wed May 28 04:10:11 PDT 2014


 avmedia/source/opengl/oglplayer.cxx              |   20 +++++++
 external/libgltf/UnpackedTarball_libgltf.mk      |    1 
 external/libgltf/patches/free_file_buffers.patch |   58 -----------------------
 3 files changed, 19 insertions(+), 60 deletions(-)

New commits:
commit 32f60d78b15b5f2c677e8687720665f6814fef62
Author: Zolnai Tamás <tamas.zolnai at collabora.com>
Date:   Wed May 28 13:07:38 2014 +0200

    libgltf: solve this memory leak problem on a better way 2
    
    Handle those cases when file loading failes.
    Release *.json file on a different way since it is allocated
    by libgltf (inside the glTFHandle).
    
    (cherry picked from commit fafc1e29c1f060c1a44361a0445300f9786ad6f4)
    
    Change-Id: Idf6c6971a8ac1b342d89dc4f61a62624183e01d0

diff --git a/avmedia/source/opengl/oglplayer.cxx b/avmedia/source/opengl/oglplayer.cxx
index 79c78f1..4f17356 100644
--- a/avmedia/source/opengl/oglplayer.cxx
+++ b/avmedia/source/opengl/oglplayer.cxx
@@ -31,6 +31,13 @@ OGLPlayer::OGLPlayer()
 
 OGLPlayer::~OGLPlayer()
 {
+    for (size_t i = 0; i < m_pHandle->size; ++i)
+    {
+        if (m_pHandle->files[i].type != GLTF_JSON)
+        {
+            delete [] m_pHandle->files[i].buffer;
+        }
+    }
     gltf_renderer_release(m_pHandle);
 }
 
@@ -68,6 +75,8 @@ bool OGLPlayer::create( const OUString& rURL )
 
     m_pHandle = gltf_renderer_init(&aJsonFile);
 
+    delete [] aJsonFile.buffer;
+
     if( !m_pHandle || !m_pHandle->files )
     {
         SAL_WARN("avmedia.opengl", "gltf_renderer_init returned an invalid glTFHandle");
@@ -87,7 +96,14 @@ bool OGLPlayer::create( const OUString& rURL )
                 // Load images as bitmaps
                 GraphicFilter aFilter;
                 Graphic aGraphic;
-                aFilter.ImportGraphic(aGraphic, INetURLObject(sFilesURL));
+                if( aFilter.ImportGraphic(aGraphic, INetURLObject(sFilesURL)) != GRFILTER_OK )
+                {
+                    rFile.buffer = 0;
+                    rFile.imagewidth = 0;
+                    rFile.imageheight = 0;
+                    SAL_WARN("avmedia.opengl", "Can't load texture file: " + sFilesURL);
+                    return false;
+                }
                 BitmapEx aBitmapEx = aGraphic.GetBitmapEx();
                 aBitmapEx.Mirror(BMP_MIRROR_VERT);
                 rFile.buffer = (char*)OpenGLHelper::ConvertBitmapExToRGBABuffer(aBitmapEx);
@@ -98,6 +114,8 @@ bool OGLPlayer::create( const OUString& rURL )
             {
                 if( !lcl_LoadFile(&rFile, sFilesURL) )
                 {
+                    rFile.buffer = 0;
+                    rFile.size = 0;
                     SAL_WARN("avmedia.opengl", "Can't load glTF file: " + sFilesURL);
                     return false;
                 }
diff --git a/external/libgltf/UnpackedTarball_libgltf.mk b/external/libgltf/UnpackedTarball_libgltf.mk
index 65262ea..ce5ad79 100644
--- a/external/libgltf/UnpackedTarball_libgltf.mk
+++ b/external/libgltf/UnpackedTarball_libgltf.mk
@@ -19,7 +19,6 @@ $(eval $(call gb_UnpackedTarball_add_patches,libgltf,\
 	external/libgltf/patches/include_path_glew.patch \
 	external/libgltf/patches/include_path_freetype.patch \
 	external/libgltf/patches/openmp-disable.patch \
-	external/libgltf/patches/free_file_buffers.patch \
 	external/libgltf/patches/rgba_textures.patch \
 ))
 
diff --git a/external/libgltf/patches/free_file_buffers.patch b/external/libgltf/patches/free_file_buffers.patch
deleted file mode 100644
index 9f92da3..0000000
--- a/external/libgltf/patches/free_file_buffers.patch
+++ /dev/null
@@ -1,58 +0,0 @@
-diff -ur libgltf.org/src/LoadScene.cpp libgltf/src/LoadScene.cpp
---- libgltf.org/src/LoadScene.cpp	2014-05-26 21:46:51.986986538 +0200
-+++ libgltf/src/LoadScene.cpp	2014-05-26 21:47:28.206985004 +0200
-@@ -127,7 +127,7 @@
-     return gHandle;
- }
- 
--bool Parser::releaseFileName()
-+bool Parser::releaseFiles()
- {
-     glTFHandle* gHandle = pScene->getGltfHandle();
-     for (int i = (int)gHandle->size - 1 ; i >= 0 ; i--)
-@@ -137,6 +137,7 @@
-             free(gHandle->files[i].filename);
-             gHandle->files[i].filename = NULL;
-         }
-+        delete [] gHandle->files[i].buffer;
-     }
- 
-     if (gHandle->files != NULL)
-diff -ur libgltf.org/src/LoadScene.h libgltf/src/LoadScene.h
---- libgltf.org/src/LoadScene.h	2014-05-26 21:46:51.986986538 +0200
-+++ libgltf/src/LoadScene.h	2014-05-26 21:47:33.170984793 +0200
-@@ -26,7 +26,7 @@
- {
- public:
-     glTFHandle* getFileNameInJson(const std::string& jsonFile);
--    bool releaseFileName();
-+    bool releaseFiles();
-     int parseScene(Scene* pscene);
-     bool parseJsonFile();
-     void setJsonInfo(const std::string& sbuffer);
-@@ -81,4 +81,4 @@
-     bool is_json_in_buffer;
- };
- 
--#endif
-\ No newline at end of file
-+#endif
-diff -ur libgltf.org/src/RenderScene.cpp libgltf/src/RenderScene.cpp
---- libgltf.org/src/RenderScene.cpp	2014-05-26 21:46:51.986986538 +0200
-+++ libgltf/src/RenderScene.cpp	2014-05-26 21:47:39.358984531 +0200
-@@ -1426,7 +1426,7 @@
- 
- void RenderScene::releaseRender()
- {
--    mLoadJson.releaseFileName();
-+    mLoadJson.releaseFiles();
-     fbo.releaseFbo();
-     return;
- }
-@@ -1543,4 +1543,4 @@
- int  RenderScene::isAnimPlay()
- {
-     return this->mAnimationPlay ? 1 : 0;
--}
-\ No newline at end of file
-+}


More information about the Libreoffice-commits mailing list