Share cameras between threads

Hi all,

I have two renderers one for a VR application and one as a standart 3D view in an QT GUI. I want to display these two vtkCamera via two vtkCameraActor and pass them to the other renderer.
The two applications run in their respective QThreads and the goal is to show the VR user the location of the desktop user’s camera and vice versa.

For a short time both vtkCameraActors move correctly in both renderers and then the application crashes with an exception in vtkAbstractTransform.cxx in the method void vtkTransformConcatenation::Concatenate(const double elements[16]) because of this->PreMatrix was nullptr.

Is there any particular technique that should be followed when displaying a camera in different renderers?

Thanks to all!


My two cents: I don’t think it has to do with different renderers. Rather, it has to do with calling thread-unsafe methods from different threads. Maybe you could prevent that crash by defining a critical section (e.g. with a mutex) around the offending call. Not all of VTK API is thread safe.

take care,



Thanks for the good idea, I will try that!

Here’s how I do it (in this case to make thread-safe calls to fftw, which are not thread-safe):

Declare a static (global) mutex object:

std::mutex myMutex;

In your context that can be called in multiple threads:

void Foo::myThreadSafeMethod( const ..., const ..., const...) const
	std::unique_lock<std::mutex> lck (myMutex, std::defer_lock);

        (thread safe code)

	for( ... )

       (thread safe code)
		//calls to fftw are not thread safe
		lck.lock();                   //
           index out_fft_size = M / 2 + 1;
           fftw_array_raw out_fft
               = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * out_fft_size);
           fftw_plan p_fft;
           p_fft = fftw_plan_dft_r2c_1d(M, in, out_fft, FFTW_ESTIMATE_PATIENT);
           out.set_data(out_fft, M / 2 + 1);
		lck.unlock();                 //

       (thread safe code)


I hope this helps,