Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Help with VTK + Qt: DICOM Application Crashes After Scrolling First Slice

Help with VTK + Qt: DICOM Application Crashes After Scrolling First Slice

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 2 Posters 156 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xava
    wrote on 27 Mar 2025, 13:35 last edited by xava
    #1

    Hello Qt community,

    I am integrating VTK with a Qt application to load and display DICOM series, but I'm facing an issue where the program crashes after displaying the first slice of a DICOM series. The application seems to work for a short while, displaying the DICOM images, but crashes shortly after showing the first slice.

    Here is the output I get before the crash:

    13:21:16: Starte appVTKQTIntegration.exe...
    QML debugging is enabled. Only use this in a safe environment.
    Slicer: Min = 0, Max = 431
    MoveSliceForward::Slice = 1
    13:21:36: Der Prozess ist abgestürzt.
    

    I am using the following example from VTK for reading and displaying DICOM series: VTK Read DICOM Series Example. My application is integrated with Qt and QML, and I use vtkGenericOpenGLRenderWindow for rendering. However, the application crashes after the first slice is displayed.

    Could anyone help me identify what might be causing the crash? Here’s the relevant code where I initialize the VTK pipeline and load DICOM files:

    VTKRendererItem::initializeVTK Method

    QQuickVTKItem::vtkUserData VTKRendererItem::initializeVTK(vtkRenderWindow *renderWindow) {
        if (!renderWindow) {
            qWarning() << "Invalid render window!";
            return nullptr;
        }
    
        m_RenderWindow = vtkGenericOpenGLRenderWindow::SafeDownCast(renderWindow);
        m_Renderer = vtkSmartPointer<vtkRenderer>::New();
        renderWindow->AddRenderer(m_Renderer);
    
        m_Transform = vtkSmartPointer<vtkTransform>::New();
        m_Actor = vtkSmartPointer<vtkActor>::New();
    
        // Create interaction class
        m_Interaction = new VTKInteraction(m_Actor, m_Transform, m_RenderWindow);
    
        emit signalVtkItemInitialized();
    
        return nullptr;
    }
    

    VTKRendererItem::loadFolder Method

    void VTKRendererItem::loadFolder(const QString &folderPath) {
        std::string inputFoldername = folderPath.toStdString();
    
        // Read all the DICOM files in the specified directory.
        vtkNew<vtkDICOMImageReader> reader;
        reader->SetDirectoryName(inputFoldername.c_str());
        reader->Update();
    
        vtkNew<vtkImageViewer2> imageViewer;
        imageViewer->SetInputConnection(reader->GetOutputPort());
    
        if (m_Interaction) {
            m_Interaction->visualizeSliceData(imageViewer);
        }
    }
    

    VTKInteraction::visualizeSliceData Method

    void VTKInteraction::visualizeSliceData(vtkSmartPointer<vtkImageViewer2> imageViewer) {
        if (!m_RenderWindow) {
            qWarning() << "visualizeSliceData: No valid render window!";
            return;
        }
    
        // Removed slice and usage text actors for simplicity
    
        if (m_RenderWindow) {
            m_RenderWindow->MakeCurrent();
        }
    
        imageViewer->SetRenderWindow(m_RenderWindow);
    
        vtkRenderer *viewerRenderer = imageViewer->GetRenderer();
        // viewerRenderer->AddActor2D(sliceTextActor); // Commented out
        // viewerRenderer->AddActor2D(usageTextActor); // Commented out
    
        vtkRenderWindowInteractor *renderWindowInteractor = m_RenderWindow->GetInteractor(); // output: QVTKInteractor cannot control the event loop.
        vtkNew<myVtkInteractorStyleImage> myInteractorStyle;
        myInteractorStyle->SetImageViewer(imageViewer);
        // myInteractorStyle->SetStatusMapper(sliceTextMapper); // Commented out
    
        imageViewer->SetupInteractor(renderWindowInteractor);
        renderWindowInteractor->SetInteractorStyle(myInteractorStyle);
    
        imageViewer->Render();
        m_RenderWindow->Render();
        viewerRenderer->ResetCamera();
        imageViewer->Render();
    }
    

    Question:

    • The program works initially, but after rendering the first slice, it crashes.
    • I'm using vtkGenericOpenGLRenderWindow for rendering, and I’ve followed the example provided in the VTK Read DICOM Series Example.
    • Any help with resolving this issue would be greatly appreciated.

    J 1 Reply Last reply 27 Mar 2025, 13:54
    0
    • X xava deleted this topic on 27 Mar 2025, 13:36
    • X xava restored this topic on 27 Mar 2025, 13:38
    • X xava
      27 Mar 2025, 13:35

      Hello Qt community,

      I am integrating VTK with a Qt application to load and display DICOM series, but I'm facing an issue where the program crashes after displaying the first slice of a DICOM series. The application seems to work for a short while, displaying the DICOM images, but crashes shortly after showing the first slice.

      Here is the output I get before the crash:

      13:21:16: Starte appVTKQTIntegration.exe...
      QML debugging is enabled. Only use this in a safe environment.
      Slicer: Min = 0, Max = 431
      MoveSliceForward::Slice = 1
      13:21:36: Der Prozess ist abgestürzt.
      

      I am using the following example from VTK for reading and displaying DICOM series: VTK Read DICOM Series Example. My application is integrated with Qt and QML, and I use vtkGenericOpenGLRenderWindow for rendering. However, the application crashes after the first slice is displayed.

      Could anyone help me identify what might be causing the crash? Here’s the relevant code where I initialize the VTK pipeline and load DICOM files:

      VTKRendererItem::initializeVTK Method

      QQuickVTKItem::vtkUserData VTKRendererItem::initializeVTK(vtkRenderWindow *renderWindow) {
          if (!renderWindow) {
              qWarning() << "Invalid render window!";
              return nullptr;
          }
      
          m_RenderWindow = vtkGenericOpenGLRenderWindow::SafeDownCast(renderWindow);
          m_Renderer = vtkSmartPointer<vtkRenderer>::New();
          renderWindow->AddRenderer(m_Renderer);
      
          m_Transform = vtkSmartPointer<vtkTransform>::New();
          m_Actor = vtkSmartPointer<vtkActor>::New();
      
          // Create interaction class
          m_Interaction = new VTKInteraction(m_Actor, m_Transform, m_RenderWindow);
      
          emit signalVtkItemInitialized();
      
          return nullptr;
      }
      

      VTKRendererItem::loadFolder Method

      void VTKRendererItem::loadFolder(const QString &folderPath) {
          std::string inputFoldername = folderPath.toStdString();
      
          // Read all the DICOM files in the specified directory.
          vtkNew<vtkDICOMImageReader> reader;
          reader->SetDirectoryName(inputFoldername.c_str());
          reader->Update();
      
          vtkNew<vtkImageViewer2> imageViewer;
          imageViewer->SetInputConnection(reader->GetOutputPort());
      
          if (m_Interaction) {
              m_Interaction->visualizeSliceData(imageViewer);
          }
      }
      

      VTKInteraction::visualizeSliceData Method

      void VTKInteraction::visualizeSliceData(vtkSmartPointer<vtkImageViewer2> imageViewer) {
          if (!m_RenderWindow) {
              qWarning() << "visualizeSliceData: No valid render window!";
              return;
          }
      
          // Removed slice and usage text actors for simplicity
      
          if (m_RenderWindow) {
              m_RenderWindow->MakeCurrent();
          }
      
          imageViewer->SetRenderWindow(m_RenderWindow);
      
          vtkRenderer *viewerRenderer = imageViewer->GetRenderer();
          // viewerRenderer->AddActor2D(sliceTextActor); // Commented out
          // viewerRenderer->AddActor2D(usageTextActor); // Commented out
      
          vtkRenderWindowInteractor *renderWindowInteractor = m_RenderWindow->GetInteractor(); // output: QVTKInteractor cannot control the event loop.
          vtkNew<myVtkInteractorStyleImage> myInteractorStyle;
          myInteractorStyle->SetImageViewer(imageViewer);
          // myInteractorStyle->SetStatusMapper(sliceTextMapper); // Commented out
      
          imageViewer->SetupInteractor(renderWindowInteractor);
          renderWindowInteractor->SetInteractorStyle(myInteractorStyle);
      
          imageViewer->Render();
          m_RenderWindow->Render();
          viewerRenderer->ResetCamera();
          imageViewer->Render();
      }
      

      Question:

      • The program works initially, but after rendering the first slice, it crashes.
      • I'm using vtkGenericOpenGLRenderWindow for rendering, and I’ve followed the example provided in the VTK Read DICOM Series Example.
      • Any help with resolving this issue would be greatly appreciated.

      J Online
      J Online
      jsulm
      Lifetime Qt Champion
      wrote on 27 Mar 2025, 13:54 last edited by
      #2

      @xava said in Help with VTK + Qt: DICOM Application Crashes After Scrolling First Slice:

      it crashes

      What does stack trace in debugger say?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      X 1 Reply Last reply 28 Mar 2025, 08:05
      0
      • J jsulm
        27 Mar 2025, 13:54

        @xava said in Help with VTK + Qt: DICOM Application Crashes After Scrolling First Slice:

        it crashes

        What does stack trace in debugger say?

        X Offline
        X Offline
        xava
        wrote on 28 Mar 2025, 08:05 last edited by
        #3

        @jsulm

        The crash happens in InteractorStyleSlices.h, line 76, when calling:

        _ImageViewer->SetSlice(_Slice);
        

        with an access violation (0xc0000005).
        Here is the stack trace from the debugger:

        1   myVtkInteractorStyleImage::MoveSliceForward     InteractorStyleSlices.h        76   0x7ff7aaf6f473  
        2   myVtkInteractorStyleImage::OnMouseWheelForward  InteractorStyleSlices.h       129  0x7ff7aaf69a04  
        3   vtkInteractorStyle::ProcessEvents              vtkInteractorStyle.cxx        1196 0x7fff492d6fa0  
        4   vtkCallbackCommand::Execute                    vtkCallbackCommand.cxx         30   0x7fff42d4acae  
        5   vtkSubjectHelper::InvokeEvent                  vtkObject.cxx                  638  0x7fff42f0a0f5  
        6   vtkObject::InvokeEvent                         vtkObject.cxx                  807  0x7fff42f07485  
        7   QVTKInteractorAdapter::ProcessEvent            QVTKInteractorAdapter.cxx      339  0x7fff3ecd1e1d  
        8   QQuickVTKInteractorAdapter::ProcessEvent       QQuickVTKInteractorAdapter.cxx 81   0x7fff76f35a7d  
        9   QQuickVTKItem::event lambda operator()         QQuickVTKItem.cxx              583  0x7fff76f37a93  
        10  std::invoke                                    type_traits                    1706 0x7fff76f3b6cd  
        11  std::_Func_impl_no_alloc::_Do_call             functional                      879  0x7fff76f382cf  
        12  std::_Func_class::operator()                   functional                      925  0x7fff76f3edee  
        13  QQuickVTKItem::updatePaintNode                 QQuickVTKItem.cxx              325  0x7fff76f37070  
        14  QQuickWindowPrivate::updateDirtyNode           qquickwindow.cpp               2271 0x7fff4cab686a  
        15  QQuickWindowPrivate::updateDirtyNodes          qquickwindow.cpp               2014 0x7fff4cab552b  
        16  QQuickWindowPrivate::syncSceneGraph            qquickwindow.cpp                568  0x7fff4cab44bb  
        17  QSGRenderThread::sync                          qsgthreadedrenderloop.cpp       554  0x7fff4d00462d  
        18  QSGRenderThread::syncAndRender                 qsgthreadedrenderloop.cpp       719  0x7fff4d003b09  
        19  QSGRenderThread::run                           qsgthreadedrenderloop.cpp       979  0x7fff4d002a41  
        20  QThreadPrivate::start                          qthread_win.cpp                 273  0x7fff49cfdf90  
        
        J 1 Reply Last reply 28 Mar 2025, 08:34
        0
        • X xava
          28 Mar 2025, 08:05

          @jsulm

          The crash happens in InteractorStyleSlices.h, line 76, when calling:

          _ImageViewer->SetSlice(_Slice);
          

          with an access violation (0xc0000005).
          Here is the stack trace from the debugger:

          1   myVtkInteractorStyleImage::MoveSliceForward     InteractorStyleSlices.h        76   0x7ff7aaf6f473  
          2   myVtkInteractorStyleImage::OnMouseWheelForward  InteractorStyleSlices.h       129  0x7ff7aaf69a04  
          3   vtkInteractorStyle::ProcessEvents              vtkInteractorStyle.cxx        1196 0x7fff492d6fa0  
          4   vtkCallbackCommand::Execute                    vtkCallbackCommand.cxx         30   0x7fff42d4acae  
          5   vtkSubjectHelper::InvokeEvent                  vtkObject.cxx                  638  0x7fff42f0a0f5  
          6   vtkObject::InvokeEvent                         vtkObject.cxx                  807  0x7fff42f07485  
          7   QVTKInteractorAdapter::ProcessEvent            QVTKInteractorAdapter.cxx      339  0x7fff3ecd1e1d  
          8   QQuickVTKInteractorAdapter::ProcessEvent       QQuickVTKInteractorAdapter.cxx 81   0x7fff76f35a7d  
          9   QQuickVTKItem::event lambda operator()         QQuickVTKItem.cxx              583  0x7fff76f37a93  
          10  std::invoke                                    type_traits                    1706 0x7fff76f3b6cd  
          11  std::_Func_impl_no_alloc::_Do_call             functional                      879  0x7fff76f382cf  
          12  std::_Func_class::operator()                   functional                      925  0x7fff76f3edee  
          13  QQuickVTKItem::updatePaintNode                 QQuickVTKItem.cxx              325  0x7fff76f37070  
          14  QQuickWindowPrivate::updateDirtyNode           qquickwindow.cpp               2271 0x7fff4cab686a  
          15  QQuickWindowPrivate::updateDirtyNodes          qquickwindow.cpp               2014 0x7fff4cab552b  
          16  QQuickWindowPrivate::syncSceneGraph            qquickwindow.cpp                568  0x7fff4cab44bb  
          17  QSGRenderThread::sync                          qsgthreadedrenderloop.cpp       554  0x7fff4d00462d  
          18  QSGRenderThread::syncAndRender                 qsgthreadedrenderloop.cpp       719  0x7fff4d003b09  
          19  QSGRenderThread::run                           qsgthreadedrenderloop.cpp       979  0x7fff4d002a41  
          20  QThreadPrivate::start                          qthread_win.cpp                 273  0x7fff49cfdf90  
          
          J Online
          J Online
          jsulm
          Lifetime Qt Champion
          wrote on 28 Mar 2025, 08:34 last edited by
          #4

          @xava said in Help with VTK + Qt: DICOM Application Crashes After Scrolling First Slice:

          myVtkInteractorStyleImage::MoveSliceForward InteractorStyleSlices.h

          Check what you're doing in that line

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          3/4

          28 Mar 2025, 08:05

          • Login

          • Login or register to search.
          3 out of 4
          • First post
            3/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved