Skip to content

Commit

Permalink
Removed a race_condition
Browse files Browse the repository at this point in the history
 - fixes #5126
 - `view->buffer` from `RenderJob` could be nullptr. when deleted by a different thread
  • Loading branch information
Febbe committed Oct 4, 2023
1 parent 2dd6c21 commit d8b9ea5
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/core/control/jobs/RenderJob.cpp
Expand Up @@ -22,6 +22,12 @@
#include "view/DocumentView.h" // for DocumentView
#include "view/Mask.h" // for Mask

#if defined(__has_cpp_attribute) && __has_cpp_attribute(likely)
#define XOJ_CPP20_UNLIKELY [[unlikely]]
#else
#define XOJ_CPP20_UNLIKELY
#endif

using xoj::util::Rectangle;

RenderJob::RenderJob(XojPageView* view): view(view) {}
Expand All @@ -45,8 +51,11 @@ void RenderJob::rerenderRectangle(Rectangle<double> const& rect) {
renderToBuffer(newMask.get());

std::lock_guard lock(this->view->drawingMutex);
assert(view->buffer.isInitialized());

if (!view->buffer.isInitialized()) {
// Todo: the buffer must not be uninitializable here, either by moving it into the job or by locking it at job
// creation a shared prt may also be suffice.
XOJ_CPP20_UNLIKELY return;
}
newMask.paintTo(view->buffer.get());
}

Expand Down

0 comments on commit d8b9ea5

Please sign in to comment.