View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0015901VTK(No Category)public2015-12-22 07:482016-08-12 09:55
ReporterStephan Rademacher 
Assigned ToDavid Gobbi 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionmoved 
PlatformOSOS Version
Product Version6.2.0 
Target VersionFixed in Version 
Summary0015901: Uninitialized information variables in image filters are causing crashes
DescriptionvtkImageResliceMapper has several uninitialized variables, for example in the GetIndexMatrix function. There the variables inOrigin, inSpacing, outOrigin and outSpacing are declared and then filled via inInfo->Get(vtkDataObject::SPACING(), inSpacing) and so on. These calls don't succeed in every case though, so that some of the variables can be left uninitialized. The same thing can happen in the RequestInformation function (inSpacing, inOrigin, inWholeExt, outSpacing, outOrigin, outWholeExt, maxBounds).

Leaving the variables in an uninitialized state causes the filter to misbehave. The following program demonstrates this:

#include "vtkBMPWriter.h"
#include "vtkCommand.h"
#include "vtkImageReslice.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkSmartPointer.h"
#include "vtkSmartVolumeMapper.h"
#include "vtkStructuredPointsReader.h"
#include "vtkVolume.h"
#include "vtkWindowToImageFilter.h"

class MyCallBack: public vtkCommand
{
public:

    static MyCallBack *New()
    {
        return new MyCallBack;
    }

    virtual void Execute(vtkObject* caller, unsigned long eventId, void* callData)
    {
        if (eventId != vtkCommand::KeyPressEvent) return;

        vtkRenderWindowInteractor* interactor = static_cast<vtkRenderWindowInteractor*>(caller);
        if (interactor == NULL) return;
        
        char* pressedKey = interactor->GetKeySym();

        if (strcmp(pressedKey, "9") == 0)
        {
            windowToImageFilter->Modified();
            bitmapWriter->SetFileName("ImageResliceBug.bmp");
            bitmapWriter->Write();
        }
    }

    vtkSmartPointer<vtkWindowToImageFilter> windowToImageFilter;
    vtkSmartPointer<vtkBMPWriter> bitmapWriter;
};

int main()
{
    vtkSmartPointer<vtkStructuredPointsReader> pointsReader = vtkSmartPointer<vtkStructuredPointsReader>::New();
    pointsReader->SetFileName("ironProt.vtk");
    pointsReader->Update();

    vtkSmartPointer<vtkSmartVolumeMapper> smartMapper = vtkSmartPointer<vtkSmartVolumeMapper>::New();
    smartMapper->SetInputConnection(pointsReader->GetOutputPort());

    vtkSmartPointer<vtkVolume> volume = vtkSmartPointer<vtkVolume>::New();
    volume->SetMapper(smartMapper);
    
    vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
    vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
    vtkSmartPointer<vtkRenderWindowInteractor> interactor= vtkSmartPointer<vtkRenderWindowInteractor>::New();
    
    renderWindow->AddRenderer(renderer);
    renderWindow->SetSize(500, 300);
    renderWindow->SetPosition(100, 100);
    interactor->SetRenderWindow(renderWindow);
    
    renderer->AddActor(volume);
    renderer->SetBackground(1.0, 1.0, 1.0);

    vtkSmartPointer<vtkWindowToImageFilter> windowToImageFilter = vtkSmartPointer<vtkWindowToImageFilter>::New();
    windowToImageFilter->SetInput(renderWindow);

    vtkSmartPointer<vtkImageReslice> imageReslice = vtkSmartPointer<vtkImageReslice>::New();
    imageReslice->SetInputConnection(windowToImageFilter->GetOutputPort());
    
    vtkSmartPointer<vtkBMPWriter> bitmapWriter = vtkSmartPointer<vtkBMPWriter>::New();
    bitmapWriter->SetInputConnection(imageReslice->GetOutputPort());

    vtkSmartPointer<MyCallBack> callback = vtkSmartPointer<MyCallBack>::New();
    callback->bitmapWriter = bitmapWriter;
    callback->windowToImageFilter = windowToImageFilter;
    
    interactor->AddObserver("KeyPressEvent", callback);

    // Let's go
    renderWindow->Render();
    interactor->Start();
}

Pressing '9' will attempt to write a bitmap to file and crashes with an access violation in vtkWindowToImageFilter.cxx on line 484 on my machine (I'm using VTK 6.2 on windows using the OpenGL2 backend).

I suspect this crash doesn't happen if you set the spacing/origin etc in the reslice filter, but this wasn't necessary in VTK 5.10. Even if this is now required, forgetting this shouldn't cause a crash. Initializing the values to things like {0.0, 0.0, 0.0} for the origin and {1.0, 1.0, 1.0} for the spacing etc fixes the problem for me.

When you try to reproduce this issue, don't use a debug build of VTK, because then the variables are automatically initialized to sane values and don't contain random values (at least on windows).
TagsNo tags attached.
ProjectTBD
Typeincorrect functionality
Attached Files

 Relationships

  Notes
(0035670)
David Gobbi (developer)
2016-01-21 11:51

I have changed the summary because this isn't a vtkImageResliceMapper bug (was that a typo?), it's a bug in vtkImageReslice and probably in at least a dozen other VTK imaging filters.

My best guess is that this bug appeared in VTK 6 after the VTK pipeline changes. In VTK 5, the SPACING, ORIGIN, etc. were copied from the vtkImageData Origin, Spacing which were guaranteed to always exist.

It is also a problem that vtkWindowToImageFilter does not add SPACING, ORIGIN to the pipeline information.
(0035671)
Stephan Rademacher (reporter)
2016-01-21 12:33

Yes that was a stupid typo, thank you for fixing the summary.
(0035672)
David Gobbi (developer)
2016-01-21 12:52

I have confirmed that in VTK 5.10, the input information to vtkImageReslice for this test code has ORIGIN and SPACING, but in VTK 7 (and VTK 6, I assume) the ORIGIN and SPACING are missing.

Even a direct call to windowToImage->Update() does not cause the ORIGIN and SPACING to be added to the pipeline.
(0035701)
David Gobbi (developer)
2016-02-07 09:40

Notes from mailing list:

http://public.kitware.com/pipermail/vtk-developers/2016-January/033034.html [^]
(0037440)
Kitware Robot (administrator)
2016-08-12 09:55

Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current VTK Issues page linked in the banner at the top of this page.

 Issue History
Date Modified Username Field Change
2015-12-22 07:48 Stephan Rademacher New Issue
2016-01-21 11:51 David Gobbi Note Added: 0035670
2016-01-21 11:51 David Gobbi Reproducibility have not tried => always
2016-01-21 11:51 David Gobbi Summary Uninitialized variables in vtkImageResliceMapper are causing crashes => Uninitialized information variables in image filters are causing crashes
2016-01-21 12:33 Stephan Rademacher Note Added: 0035671
2016-01-21 12:52 David Gobbi Note Added: 0035672
2016-02-07 09:40 David Gobbi Note Added: 0035701
2016-02-07 09:40 David Gobbi Assigned To => David Gobbi
2016-08-12 09:55 Kitware Robot Note Added: 0037440
2016-08-12 09:55 Kitware Robot Status backlog => closed
2016-08-12 09:55 Kitware Robot Resolution open => moved


Copyright © 2000 - 2018 MantisBT Team