[vtkusers] GetRange(double rng[2]) crashes in execute of threaded image algorithm.

Maarten Beek beekmaarten at yahoo.com
Wed May 28 10:18:47 EDT 2014


Thanks David!
This seems to solve the crash.

Maarten



On Tuesday, May 27, 2014 4:57:25 PM, David Gobbi <david.gobbi at gmail.com> wrote:
 


Calling GetRange() can actually cause the range to be computed (i.e.
iterating over all elements in the array), so it's generally not a
good thing to call from the multi-threaded part of your image filter.
As for whether it is thread safe, I've looked at the code, and I would
say "no, it's not".

The documentation for vtkDataSet::GetScalarRange(double range[2])
gives a bit more info:

  // THIS METHOD IS THREAD SAFE IF FIRST CALLED FROM A SINGLE THREAD AND
  // THE DATASET IS NOT MODIFIED
  virtual void GetScalarRange(double range[2]);

The above advice applies to GetRange() as well: if you call GetRange()
once before you split the threads, then it's fine to call it again
after you split the threads, because there is a timestamp to make sure
that the internal ComputerRange() code will not be re-executed.

  - David




On Tue, May 27, 2014 at 2:31 PM, Maarten Beek <beekmaarten at yahoo.com> wrote:
> Hi all,
>
> I have been struggling with the following:
>
> I have derived an image algorithm form vtkThreadedImageAlgorithm in which I
> need to know the range of the scalars of the input image.
>
> inData->GetPointData()->GetScalars()->GetRange(rng);
> inData->GetPointData()->GetScalars()->GetInformation()->Get(vtkDataArray::COMPONENT_RANGE(),
> rng));
> both crash in the template execute function (I used vtkImageHSVToRGB as
> example).
> The crash only seems to be happening in Release build.
>
> When I use SetNumberOfThreads(1), the algorithm works fine.
> When I hard-code the range (double rng[2] = { 0.0, 808000}; ), the algorithm
> works fine.
>
> Is GetRange() not thread-safe? Should I get the range from the input before
> it is spread across threads?
>
> Thanks - Maarten
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140528/91b2c167/attachment.html>


More information about the vtkusers mailing list