From c2dfa1a0667af15a379bcada986e947bebdf0909 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Mon, 31 Jul 2023 11:17:14 +0200 Subject: [PATCH] Fix crash in GPU compositor when viewer size changes This change fixes crash which happens when a viewer node is used for backdrop, and the scene render size is modified. After the modification the render size and the texture size gets out of sync since the texture was never adapting for the size change. Pull Request: https://projects.blender.org/blender/blender/pulls/110590 --- source/blender/render/intern/compositor.cc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/source/blender/render/intern/compositor.cc b/source/blender/render/intern/compositor.cc index 69ca8a1631c..de283821f73 100644 --- a/source/blender/render/intern/compositor.cc +++ b/source/blender/render/intern/compositor.cc @@ -193,8 +193,20 @@ class Context : public realtime_compositor::Context { /* TODO: support outputting previews. * TODO: just a temporary hack, needs to get stored in RenderResult, * once that supports GPU buffers. */ + const int2 size = get_render_size(); + + /* Re-create texture if the viewer size changes. */ + if (viewer_output_texture_) { + const int current_width = GPU_texture_width(viewer_output_texture_); + const int current_height = GPU_texture_height(viewer_output_texture_); + + if (current_width != size.x || current_height != size.y) { + GPU_TEXTURE_FREE_SAFE(viewer_output_texture_); + viewer_output_texture_ = nullptr; + } + } + if (viewer_output_texture_ == nullptr) { - const int2 size = get_render_size(); viewer_output_texture_ = GPU_texture_create_2d("compositor_viewer_output_texture", size.x, size.y,