From 6aa21ed7526cafbd873a85d9230e44cc9bf29ec7 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Thu, 14 Mar 2024 17:09:33 +0100 Subject: [PATCH] Fix: incorrect GPU ownership after IMB_dupImBuf The IMB_dupImBuf() function does not copy the GPU texture as it might not be possible if the GPU context is not active, but it also was not clearing the pointer in the result ImBuf. This could potentially lead to situation when the texture gets freed via IMB_freeImBuf of either original or copied image buffer, leaving the other pointing to a freed GPU texture. It is not known whether it ever was an actual problem for artists, but it is nice to avoid such possibility. Pull Request: https://projects.blender.org/blender/blender/pulls/119469 --- source/blender/imbuf/intern/allocimbuf.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source/blender/imbuf/intern/allocimbuf.cc b/source/blender/imbuf/intern/allocimbuf.cc index ad70196a8c8..1c5f9ab5b79 100644 --- a/source/blender/imbuf/intern/allocimbuf.cc +++ b/source/blender/imbuf/intern/allocimbuf.cc @@ -635,6 +635,10 @@ ImBuf *IMB_dupImBuf(const ImBuf *ibuf1) tbuf.display_buffer_flags = nullptr; tbuf.colormanage_cache = nullptr; + /* GPU textures can not be easily copied, as it is not guaranteed that this function is called + * from within an active GPU context. */ + tbuf.gpu.texture = nullptr; + *ibuf2 = tbuf; return ibuf2;