[vtkusers] Segfault when using vtkSmartPointer<vtkImageViewer2> in a QVTKWidget
t1m
t1m at phrogstar.de
Tue Feb 28 09:10:40 EST 2012
Hello,
I have a problem with a vtkImageViewer2 instance in a QVTKWidget. It looks
like it has to do with the use of a vtkSmartPointer.
To illustrate the problem, I wrote the following code:
----- main.cpp ------
#include <qapplication.h>
#include <QString>
#include <QFileDialog>
#include <QObject>
#include <QVTKWidget.h>
#include <vtkTIFFReader.h>
#include <vtkImageViewer2.h>
#include <vtkRenderWindow.h>
#include <vtkSmartPointer.h>
#include <vtkImageActor.h>
int
main(int argv, char ** argc)
{
QApplication app(argv, argc);
QVTKWidget * tdisplay = new QVTKWidget();
//app.setMainWidget(tdisplay);
QString m_imageFileName =
QFileDialog::getOpenFileName(tdisplay,QObject::tr("Open
Image"),"",QObject::tr("*.tif *.tiff"));
std::cout << "m_imageFileName = " << m_imageFileName.toStdString() <<
std::endl;
if(!m_imageFileName.isEmpty()) {
vtkSmartPointer<vtkTIFFReader> vtkReader =
vtkSmartPointer<vtkTIFFReader>::New();
vtkReader->SetFileName(m_imageFileName.toStdString().c_str());
vtkReader->Update();
vtkSmartPointer<vtkImageViewer2> image_view =
vtkSmartPointer<vtkImageViewer2>::New();
image_view->SetInput(vtkReader->GetOutput());
image_view->GetImageActor()->InterpolateOff();
image_view->SetColorLevel(127);
image_view->SetColorWindow(255);
image_view->SetupInteractor(tdisplay->GetRenderWindow()->GetInteractor());
image_view->SetRenderWindow(tdisplay->GetRenderWindow());
tdisplay->show();
}
app.exec();
}
----- end of main.cpp ------
you can compile this with a short qt project file (change the INCLUDEPATH
and LIBS accordingly):
----- testQVTK.pro -----
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
CONFIG += qt opengl debug
# Input
SOURCES += vtkTest.cpp
INCLUDEPATH += /usr/local/include/vtk-5.8
LIBS += -L/usr/local/lib/vtk-5.8 -lQVTK -lvtkRendering -lvtkCommon -lvtkIO
-lvtkFiltering
----- end of testQVTK.pro -----
qmake; make;
fire up the programm, choose a tiff image and click into the window. It
crashes in both of my environments (Debian GNU/Linux amd64 and Mac OS X
10.6.8) with a segmentation fault.
So I debugged it, and (most of the time) it crashes at this line in the
function vtkImageViewer2Callback::Execute():
469 if (this->IV->GetInput() == NULL)
The strange thing is, that IV indeed points to the Object allocated in the
image_viewer vtkSmartPointer. But examining it further, I could see that
e.g. the RenderWindow pointer inside the vtkImageViewer2 pointer changes
after the call to app.exec().
So I tried a simple C++ pointer (vtkImageViewer2::New()) instead of the
vtkSmartPointer of vtkImageViewer2, and the problem vanished!
My question now is: Did I do sth wrong with the use of vtkSmartPointer, or
is this a bug?
I appreciate any help,
cheers,
Tim
--
View this message in context: http://vtk.1045678.n5.nabble.com/Segfault-when-using-vtkSmartPointer-vtkImageViewer2-in-a-QVTKWidget-tp5521934p5521934.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list