Error Render while mapping image to color

When I use the following program to perform window rendering, OpenGL errors and warnings appear. Without using the colormap in the program, the program returns to normal. I don’t know how to solve this problem or if there are other ways to display color sliced images

    vtkSmartPointer<vtkImageReslice> reslice = vtkSmartPointer<vtkImageReslice>::New();
    reslice->SetInputData(m_vtkImageData);
    reslice->SetOutputDimensionality(2);  
    reslice->SetResliceAxes(resliceAxes);
    reslice->SetInterpolationModeToLinear();
    reslice->Update();

    vtkSmartPointer<vtkImageMapToColors> colorMapper = vtkSmartPointer<vtkImageMapToColors>::New();
    colorMapper->SetInputConnection(reslice->GetOutputPort());
    colorMapper->SetOutputFormatToRGBA();
    vtkSmartPointer<vtkLookupTable> lookupTable = vtkSmartPointer<vtkLookupTable>::New();
    vtkSmartPointer < vtkColorTransferFunction>color = vtkSmartPointer < vtkColorTransferFunction>::New();
    color->AddRGBPoint(m_minValue, 0, 0.00, 0.00);
    color->AddRGBPoint(m_maxValue, 0.9, 0, 0);
    colorMapper->SetLookupTable(color);
    colorMapper->Update();
    m_imageActor->GetMapper()->SetInputConnection(colorMapper->GetOutputPort());

OpenGL Errors and Warnings:

Generic Warning: In vtkOpenGLState.cxx, line 255
Error in cache state for GL_COLOR_CLEAR_VALUE

Generic Warning: In vtkOpenGLState.cxx, line 263
at stack loc
 at vtksys::SystemInformationImplementation::GetProgramStack in D:\VTK\VTK-9.3.1\Utilities\KWSys\vtksys\SystemInformation.cxx line 3987
 at vtksys::SystemInformation::GetProgramStack in D:\VTK\VTK-9.3.1\Utilities\KWSys\vtksys\SystemInformation.cxx line 829
 at vtkOpenGLState::CheckState in D:\VTK\VTK-9.3.1\Rendering\OpenGL2\vtkOpenGLState.cxx line 262
 at vtkOpenGLState::vtkglBindFramebuffer in D:\VTK\VTK-9.3.1\Rendering\OpenGL2\vtkOpenGLState.cxx line 488
 at vtkOpenGLState::vtkBindFramebuffer in D:\VTK\VTK-9.3.1\Rendering\OpenGL2\vtkOpenGLState.cxx line 483
 at vtkOpenGLFramebufferObject::Bind in D:\VTK\VTK-9.3.1\Rendering\OpenGL2\vtkOpenGLFramebufferObject.cxx line 736
 at vtkOpenGLFramebufferObject::Bind in D:\VTK\VTK-9.3.1\Rendering\OpenGL2\vtkOpenGLFramebufferObject.cxx line 719
 at vtkOpenGLFramebufferObject::PopulateFramebuffer in D:\VTK\VTK-9.3.1\Rendering\OpenGL2\vtkOpenGLFramebufferObject.cxx line 1492
 at vtkTextureObject::CopyFromFrameBuffer in D:\VTK\VTK-9.3.1\Rendering\OpenGL2\vtkTextureObject.cxx line 2052
 at vtkDualDepthPeelingPass::CopyOpaqueDepthBuffer in D:\VTK\VTK-9.3.1\Rendering\OpenGL2\vtkDualDepthPeelingPass.cxx line 1086
 at vtkDualDepthPeelingPass::Prepare in D:\VTK\VTK-9.3.1\Rendering\OpenGL2\vtkDualDepthPeelingPass.cxx line 1055
 at vtkDualDepthPeelingPass::Render in D:\VTK\VTK-9.3.1\Rendering\OpenGL2\vtkDualDepthPeelingPass.cxx line 92
 at vtkOpenGLRenderer::DeviceRenderTranslucentPolygonalGeometry in D:\VTK\VTK-9.3.1\Rendering\OpenGL2\vtkOpenGLRenderer.cxx line 613
 at vtkOpenGLRenderer::UpdateGeometry in D:\VTK\VTK-9.3.1\Rendering\OpenGL2\vtkOpenGLRenderer.cxx line 398
 at vtkOpenGLRenderer::DeviceRender in D:\VTK\VTK-9.3.1\Rendering\OpenGL2\vtkOpenGLRenderer.cxx line 292
 at vtkRenderer::Render in D:\VTK\VTK-9.3.1\Rendering\Core\vtkRenderer.cxx line 374
 at vtkRendererCollection::Render in D:\VTK\VTK-9.3.1\Rendering\Core\vtkRendererCollection.cxx line 42
 at vtkRenderWindow::DoStereoRender in D:\VTK\VTK-9.3.1\Rendering\Core\vtkRenderWindow.cxx line 347
 at vtkRenderWindow::Render in D:\VTK\VTK-9.3.1\Rendering\Core\vtkRenderWindow.cxx line 306
 at vtkOpenGLRenderWindow::Render in D:\VTK\VTK-9.3.1\Rendering\OpenGL2\vtkOpenGLRenderWindow.cxx line 2766
 at vtkGenericOpenGLRenderWindow::Render in D:\VTK\VTK-9.3.1\Rendering\OpenGL2\vtkGenericOpenGLRenderWindow.cxx line 211
 at vtkSetConfig::setColor in D:\C++Proj\DeepInsight\code1\src\NiReconstruction\test\vtkWidgetShow.cpp line 470
 at demo3::update3DViewState in D:\C++Proj\DeepInsight\code1\src\NiReconstruction\test\demo3.cpp line 1651
 at QtPrivate::FunctorCall<QtPrivate::IndexesList<0>,QtPrivate::List<int>,void,void (__cdecl demo3::*)(int)>::call in D:\QT\5.15.2\msvc2019_64\include\QtCore\qobjectdefs_impl.h line 152
 at QtPrivate::FunctionPointer<void (__cdecl demo3::*)(int)>::call<QtPrivate::List<int>,void> in D:\QT\5.15.2\msvc2019_64\include\QtCore\qobjectdefs_impl.h line 186
 at QtPrivate::QSlotObject<void (__cdecl demo3::*)(int),QtPrivate::List<int>,void>::impl in D:\QT\5.15.2\msvc2019_64\include\QtCore\qobjectdefs_impl.h line 419
 at QTextStream::realNumberPrecision
 at QTextStream::realNumberPrecision
 at QTextStream::realNumberPrecision
 at Set3DViewConfig::sigStateChange in D:\C++Proj\DeepInsight\code1\src\NiReconstruction\test\x64\Debug\moc\moc_set_3dview_config.cpp line 169
 at <lambda_941b06bfddaf40785632dc042dbef55e>::operator() in D:\C++Proj\DeepInsight\code1\src\NiReconstruction\test\set3DViewConfig.cpp line 34
 at QtPrivate::FunctorCall<QtPrivate::IndexesList<>,QtPrivate::List<>,void,<lambda_941b06bfddaf40785632dc042dbef55e> >::call in D:\QT\5.15.2\msvc2019_64\include\QtCore\qobjectdefs_impl.h line 146
 at QtPrivate::Functor<<lambda_941b06bfddaf40785632dc042dbef55e>,0>::call<QtPrivate::List<>,void> in D:\QT\5.15.2\msvc2019_64\include\QtCore\qobjectdefs_impl.h line 257
 at QtPrivate::QFunctorSlotObject<<lambda_941b06bfddaf40785632dc042dbef55e>,0,QtPrivate::List<>,void>::impl in D:\QT\5.15.2\msvc2019_64\include\QtCore\qobjectdefs_impl.h line 449
 at QTextStream::realNumberPrecision
 at QTextStream::realNumberPrecision
 at QTextStream::realNumberPrecision
 at QStyleAnimation::frameRate
 at QStyleAnimation::frameRate
 at QStyleAnimation::frameRate
 at QStyleAnimation::frameRate
 at QStyleAnimation::frameRate
 at QStyleAnimation::frameRate
 at QStyleAnimation::frameRate
 at QStyleAnimation::frameRate
 at QStyleAnimation::frameRate
 at QStyleAnimation::frameRate
 at QTextStream::realNumberPrecision
 at QTextStream::realNumberPrecision
 at QStyleAnimation::frameRate
 at QStyleAnimation::frameRate
 at QStyleAnimation::frameRate
 at QStyleAnimation::frameRate
 at QStyleAnimation::frameRate
 at QTextStream::realNumberPrecision
 at QTextStream::realNumberPrecision
 at QOpenGLFunctions_4_3_Compatibility::glLightModeli
 at QOpenGLFunctions_4_3_Compatibility::glLightModeli
 at QOpenGLFunctions_4_3_Compatibility::glLightModeli
 at qt_plugin_instance
 at QTextStream::realNumberPrecision
 at qt_plugin_instance
 at QTextStream::realNumberPrecision
 at QTextStream::realNumberPrecision
 at QTextStream::realNumberPrecision
 at QOpenGLFunctions_4_3_Compatibility::glLightModeli
 at QStyleAnimation::frameRate
 at main in D:\C++Proj\DeepInsight\code1\src\NiReconstruction\test\main.cpp line 44
 at invoke_main in D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl line 79
 at __scrt_common_main_seh in D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl line 288
 at __scrt_common_main in D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl line 331
 at mainCRTStartup in D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_main.cpp line 17
 at BaseThreadInitThunk
 at RtlUserThreadStart

The code snipped that you posted looks fine. I even tried similar code on my own computer to be sure. From the warning message “Error in cache state”, I’m 100% certain that the cause of the problem is not vtkImageMapToColors.

The problem is probably Qt + VTK. If the Qt OpenGL context is not ready when VTK tries to render, then you will see errors like this. Can you show the code where you link VTK and Qt?

Thank you for your answer. I also think it’s a problem with vtk+QT, but after removed colorMapper, the program runs normally, which makes me very confused. Does colorApper change the rendering order of vtk? Here is the code that links Qt windows with VTK

    m_ren = vtkSmartPointer<vtkOpenGLRenderer>::New();
    m_ren->SetBackground(0.07, 0.26, 0.37);
    m_ren->GetActiveCamera()->SetPosition(0, 0, 100);
    m_ren->SetOcclusionRatio(0.1);   
    m_ren->SetMaximumNumberOfPeels(100); 
    m_ren->UseDepthPeelingForVolumesOn();  
    m_ren->UseDepthPeelingOn();

    m_renderWindow3D = vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();
    m_renderWindow3D->SetWindowName("RenderWindowNoUIFile");
    m_renderWindow3D->AddRenderer(m_ren);

    m_vtkWidget3D = new QVTKOpenGLNativeWidget();  
    m_vtkWidget3D->setRenderWindow(m_renderWindow3D);

    m_renderWindowInteractor = vtkSmartPointer<QVTKInteractor>::New();
    vtkSmartPointer<CustomInteractorStyle> style = vtkSmartPointer<CustomInteractorStyle>::New();    
    m_renderWindow3D->SetInteractor(m_renderWindowInteractor);
    m_renderWindowInteractor->Initialize();
    m_renderWindowInteractor->SetInteractorStyle(style);

    QVBoxLayout* frameLayout = new QVBoxLayout(ui.widget);
	ui.widget->setLayout(frameLayout);
	ui.widget->layout()->addWidget(m_vtkWidget3D );