[Bf-blender-cvs] [fd35aa48d15] blender-v3.1-release: Workaround for VSE memory leak.

Jeroen Bakker noreply at git.blender.org
Wed Feb 2 14:20:35 CET 2022


Commit: fd35aa48d154283617ce6f33857b5783599d2d08
Author: Jeroen Bakker
Date:   Wed Feb 2 14:16:09 2022 +0100
Branches: blender-v3.1-release
https://developer.blender.org/rBfd35aa48d154283617ce6f33857b5783599d2d08

Workaround for VSE memory leak.

This is a temp fix for a memory leak where the VSE isn't aware that a
float representation of the image could exist. The VSE somehow doens't
clears it (refcounter is still 1).

The work around is just to let the image engine clean up all the data it
created. Potential this would add more overhead when buffers are needed
more than once.

===================================================================

M	source/blender/draw/engines/image/image_drawing_mode.hh

===================================================================

diff --git a/source/blender/draw/engines/image/image_drawing_mode.hh b/source/blender/draw/engines/image/image_drawing_mode.hh
index 4cb0023ccb9..a355b42d66c 100644
--- a/source/blender/draw/engines/image/image_drawing_mode.hh
+++ b/source/blender/draw/engines/image/image_drawing_mode.hh
@@ -211,7 +211,7 @@ template<typename TextureMethod> class ScreenSpaceDrawingMode : public AbstractD
       if (iterator.tile_data.tile_buffer == nullptr) {
         continue;
       }
-      ensure_float_buffer(*iterator.tile_data.tile_buffer);
+      const bool float_buffer_created = ensure_float_buffer(*iterator.tile_data.tile_buffer);
       const float tile_width = static_cast<float>(iterator.tile_data.tile_buffer->x);
       const float tile_height = static_cast<float>(iterator.tile_data.tile_buffer->y);
 
@@ -314,6 +314,10 @@ template<typename TextureMethod> class ScreenSpaceDrawingMode : public AbstractD
                                0);
         imb_freerectImbuf_all(&extracted_buffer);
       }
+
+      if (float_buffer_created) {
+        imb_freerectfloatImBuf(iterator.tile_data.tile_buffer);
+      }
     }
   }
 
@@ -367,12 +371,19 @@ template<typename TextureMethod> class ScreenSpaceDrawingMode : public AbstractD
 
   /**
    * \brief Ensure that the float buffer of the given image buffer is available.
+   *
+   * Returns true when a float buffer was created. Somehow the VSE cache increases the ref
+   * counter, but might use a different mechanism for destructing the image, that doesn't free the
+   * rect_float as the refcounter isn't 0. To work around this we destruct any created local
+   * buffers ourself.
    */
-  void ensure_float_buffer(ImBuf &image_buffer) const
+  bool ensure_float_buffer(ImBuf &image_buffer) const
   {
     if (image_buffer.rect_float == nullptr) {
       IMB_float_from_rect(&image_buffer);
+      return true;
     }
+    return false;
   }
 
   void do_full_update_texture_slot(const IMAGE_InstanceData &instance_data,
@@ -383,7 +394,7 @@ template<typename TextureMethod> class ScreenSpaceDrawingMode : public AbstractD
   {
     const int texture_width = texture_buffer.x;
     const int texture_height = texture_buffer.y;
-    ensure_float_buffer(tile_buffer);
+    const bool float_buffer_created = ensure_float_buffer(tile_buffer);
 
     /* IMB_transform works in a non-consistent space. This should be documented or fixed!.
      * Construct a variant of the info_uv_to_texture that adds the texel space
@@ -418,6 +429,10 @@ template<typename TextureMethod> class ScreenSpaceDrawingMode : public AbstractD
                   IMB_FILTER_NEAREST,
                   uv_to_texel,
                   crop_rect_ptr);
+
+    if (float_buffer_created) {
+      imb_freerectfloatImBuf(&tile_buffer);
+    }
   }
 
  public:



More information about the Bf-blender-cvs mailing list