VolumeData not thread safe even after copy[SOLVED]
-
On 01/02/2016 at 17:09, xxxxxxxx wrote:
User Information:
Cinema 4D Version:
Platform:
Language(s) :---------
Hello! I want to implement multi processing for my VideoPostData plugin. It uses
VolumeData::TraceGeometryEnhanced() and VolumeData::GetSurfaceData(). I tried
to create a copy of the VolumeData before using these functions in the thread, but
I still get access violations when I don't synchronize calls to these functions using a lock.// Create a copy of the VolumeData, it can not be accessed from // several threads simultaneously. lock_.Lock(); AutoAlloc<VolumeData> vd; if (!vd) { lock_.Unlock(); GePrint("Could not allocate VolumeData."); return; } info.vps->vd->CopyTo(vd); // XXX does not return a value? How to check for success? lock_.Unlock();
And later in the code
lock_.Lock(); vd->GetSurfaceData(&sd, false, false, false, true, &ray, si); // <-- access violation if locking is removed lock_.Unlock();
It used to work in a single threaded process. How do I correctly clone a VolumeData?
Thanks in advance!
Niklas -
On 02/02/2016 at 01:32, xxxxxxxx wrote:
Hello,
the Render class has the GetInitialVolumeData() function that apparently needs to be used to get the VolumeData structures for multiple threads.
Best wishes,
Sebastian -
On 02/02/2016 at 01:49, xxxxxxxx wrote:
Thanks Sebastian, that's exactly what I needed. Sorry for not seeing it myself. :^)
Could you provide some information on the "cpu_index" parameter of GetInitialVolumeData()? Like, is there
a maximum value? Or will it just accept any value and make sure there is a unique VolumeData for that index?At the moment, I use vps->vd->GetCPUCount() and create that many threads and retrieve that many
VolumeData's using GetInitialVolumeData() and that seems to work fine.Thanks,
Niklas -
On 02/02/2016 at 05:58, xxxxxxxx wrote:
Also VolumeData that was returned by GetInitialVolumeData() is not the same as vps->vd and is required by InitRende() for example.
What would be interesting is to if one can clone them using CopyTo().
-
On 03/02/2016 at 01:29, xxxxxxxx wrote:
Hello,
the CPU index must be smaller than the number of initiated threads. GetInitialVolumeData() does not create new copies of the VolumeData but provides access to already existing instances.
The number of threads depends on the CPU count that can be obtained with VolumeData::GetCPUCount().
Best wishes,
Sebastian