From fff74145f175174d1fc5c1c925647781d1e5d29b Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 3 Oct 2023 17:09:04 +0200 Subject: [PATCH] Fix #113186: The Render Result attribute "has_data" is always False Caused by d579ac2b3f This change restores the behavior of the flag to how it was prior to the refactor which used ImBuf for storage in the RenderResult. This flag still has issues with configurations when there are multiple scenes in the .blend file, and that it is only "valid" when the image is actually displayed. However, these limitations and quirks already existed prior to the refactor commit. Pull Request: https://projects.blender.org/blender/blender/pulls/113199 --- source/blender/blenkernel/intern/image.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/source/blender/blenkernel/intern/image.cc b/source/blender/blenkernel/intern/image.cc index 1ece13d4ce3..31ec1a79778 100644 --- a/source/blender/blenkernel/intern/image.cc +++ b/source/blender/blenkernel/intern/image.cc @@ -4385,6 +4385,24 @@ static ImBuf *image_get_render_result(Image *ima, ImageUser *iuser, void **r_loc } } + /* Put an empty image buffer to the cache so that the Image.has_data detects that some data + * has been loaded for this Image data-block. + * + * Surely there are all the design questions about scene-dependent Render Result image datablock, + * and the behavior of the flag dependent on wheter the Render Result image was ever shown on + * screen. The purpose of this code is to preserve the Python API behavior to the level prior to + * the RenderResult refactor to use ImBuf which happened for Blender 4.0. */ + if (ima->cache == nullptr) { + ImBuf *empty_ibuf = IMB_allocImBuf(0, 0, 0, 0); + image_assign_ibuf(ima, empty_ibuf, IMA_NO_INDEX, 0); + + /* The cache references the image buffer, and the freeing only happens if the buffer has 0 + * references at the time when the IMB_freeImBuf() is called. This particular image buffer is + * to be freed together with the cache, without any extra reference counting done by any image + * pixel accessor. */ + IMB_freeImBuf(empty_ibuf); + } + if (pass_ibuf) { /* TODO(sergey): Perhaps its better to assign dither when ImBuf is allocated for the render * result. It will avoid modification here, and allow comparing render results with different