I am trying slowly to discover the potential of ChangeQueue concept while I am building a simple custom renderer and after succeeding to have the all the scene geometry in a triangular mesh format I came across to a sync issue.
After initializing my scene, the renderer runs in a while loop loading the rendered buffer into the viewport via pChannel->SetValueRect
After rendering the initial scene I create lots of new instances in Rhino. There, I found out that when I do this the ChangeQueue::ApplyMeshInstanceChanges
is called again to calculate and feed the new geometry to the renderer (which runs on the while loop).
In this scenario isn’t there a sync issue? If the newly created geometry is big enough the renderer will not be able to access it consistently, should I use a mutex/cv mechanism to avoid this?
std::unique_lock<std::mutex> lock(_scene->mutex);
_scene->cv.wait(lock, [that]
{
return _scene->vertices_ready;
});
updateRendererGeometry(triangularMeshVertices);
lock.unlock();
_scene->vertices_ready = true;
_scene->vertices_processed = true;
_scene->cv.notify_one();