Compositor: Fix crash when using empty input sources

It's the case of Image or Movie Clip node when not selecting any
source or an empty one.
Render methods expect an output buffer with size, only render
operations with resolution.
This commit is contained in:
Manuel Castilla 2021-07-22 18:35:08 +02:00
parent b1bf4c2a05
commit 1a91c57320
3 changed files with 30 additions and 4 deletions

View File

@ -20,6 +20,7 @@
#include "COM_Debug.h"
#include "COM_ExecutionGroup.h"
#include "COM_ReadBufferOperation.h"
#include "COM_ViewerOperation.h"
#include "COM_WorkScheduler.h"
#include "BLT_translation.h"
@ -100,11 +101,15 @@ void FullFrameExecutionModel::render_operation(NodeOperation *op)
const bool has_outputs = op->getNumberOfOutputSockets() > 0;
MemoryBuffer *op_buf = has_outputs ? create_operation_buffer(op) : nullptr;
Span<rcti> areas = active_buffers_.get_areas_to_render(op);
op->render(op_buf, areas, input_bufs);
if (op->getWidth() > 0 && op->getHeight() > 0) {
Span<rcti> areas = active_buffers_.get_areas_to_render(op);
op->render(op_buf, areas, input_bufs);
DebugInfo::operation_rendered(op, op_buf);
}
/* Even if operation has no resolution set the empty buffer. It will be clipped with a
* TranslateOperation from convert resolutions if linked to an operation with resolution. */
active_buffers_.set_rendered_buffer(op, std::unique_ptr<MemoryBuffer>(op_buf));
DebugInfo::operation_rendered(op, op_buf);
operation_finished(op);
}
@ -118,10 +123,16 @@ void FullFrameExecutionModel::render_operations()
WorkScheduler::start(this->context_);
for (eCompositorPriority priority : priorities_) {
for (NodeOperation *op : operations_) {
if (op->isOutputOperation(is_rendering) && op->getRenderPriority() == priority) {
const bool has_size = op->getWidth() > 0 && op->getHeight() > 0;
const bool is_priority_output = op->isOutputOperation(is_rendering) &&
op->getRenderPriority() == priority;
if (is_priority_output && has_size) {
render_output_dependencies(op);
render_operation(op);
}
else if (is_priority_output && !has_size && op->isActiveViewerOutput()) {
static_cast<ViewerOperation *>(op)->clear_display_buffer();
}
}
}
WorkScheduler::stop();

View File

@ -246,4 +246,17 @@ void ViewerOperation::update_memory_buffer_partial(MemoryBuffer *UNUSED(output),
updateImage(&area);
}
void ViewerOperation::clear_display_buffer()
{
BLI_assert(isActiveViewerOutput());
initImage();
size_t buf_bytes = (size_t)m_ibuf->y * m_ibuf->x * COM_DATA_TYPE_COLOR_CHANNELS * sizeof(float);
if (buf_bytes > 0) {
memset(m_outputBuffer, 0, buf_bytes);
rcti display_area;
BLI_rcti_init(&display_area, 0, m_ibuf->x, 0, m_ibuf->y);
updateImage(&display_area);
}
}
} // namespace blender::compositor

View File

@ -131,6 +131,8 @@ class ViewerOperation : public MultiThreadedOperation {
const rcti &area,
Span<MemoryBuffer *> inputs) override;
void clear_display_buffer();
private:
void updateImage(const rcti *rect);
void initImage();