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
This commit is contained in:
Sergey Sharybin 2023-10-03 17:09:04 +02:00 committed by Sergey Sharybin
parent 8562cecf1b
commit fff74145f1
1 changed files with 18 additions and 0 deletions

View File

@ -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