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

David Gobbi david.gobbi at gmail.com
Tue May 27 16:57:04 EDT 2014


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


More information about the vtkusers mailing list