From 6c483479b82fc4795f71e0edfcb691b2e7074b29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Thu, 27 Jan 2022 16:13:44 +0100 Subject: [PATCH] GLFramebuffer: Add assert to check if framebuffer has the expected data It came to light that there is no error checking when trying to read a framebuffer plane without anything attached to it. --- source/blender/gpu/opengl/gl_framebuffer.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/source/blender/gpu/opengl/gl_framebuffer.cc b/source/blender/gpu/opengl/gl_framebuffer.cc index 13f03195437..106a12bfefd 100644 --- a/source/blender/gpu/opengl/gl_framebuffer.cc +++ b/source/blender/gpu/opengl/gl_framebuffer.cc @@ -429,8 +429,15 @@ void GLFrameBuffer::read(eGPUFrameBufferBits plane, switch (plane) { case GPU_DEPTH_BIT: format = GL_DEPTH_COMPONENT; + BLI_assert_msg( + this->attachments_[GPU_FB_DEPTH_ATTACHMENT].tex != nullptr || + this->attachments_[GPU_FB_DEPTH_STENCIL_ATTACHMENT].tex != nullptr, + "GPUFramebuffer: Error: Trying to read depth without a depth buffer attached."); break; case GPU_COLOR_BIT: + BLI_assert_msg( + mode != GL_NONE, + "GPUFramebuffer: Error: Trying to read a color slot without valid attachment."); format = channel_len_to_gl(channel_len); /* TODO: needed for selection buffers to work properly, this should be handled better. */ if (format == GL_RED && type == GL_UNSIGNED_INT) {