<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body><div><div>Dear All,<br></div>
<div> </div>
</div>
<div>OS: Windows 10 x64<br></div>
<div>IDE: MS VS 2015 <br></div>
<div>VTK: 6.3.0 x64 build<br></div>
<div><div> </div>
<div>I am getting a "heap corruption" message when a vtkRenderWindow is closed and the vtkRenderWindowInteractor is stopped.<br></div>
<div>Specifically the line <br></div>
<div> </div>
<div><span style="line-height: 10.8333px;">renderWindowInteractor->TerminateApp();</span><br></div>
<div> </div>
<div>in a callback function<br></div>
<div> </div>
<div><span style="line-height: 10.8333px;">static void KeyPressCallbackFunction</span><br></div>
<div> </div>
<div>The relevant code fragments, appended below, are conventional texture mapping of an image to a plane.<br></div>
<div>This "heap corruption" did not occur in Windows 8.1 x64; MS VS 2010; VTK 5.10.1 x64 build<br></div>
<div> </div>
<div>From the call stack it appears to due to a problem with deleting an instantiation of vtkLoopupTable:<br></div>
<div> </div>
</div>
<div>vtkCommonCore-6.3.dll!vtkDataArrayTemplate<unsigned char>::DeleteArray() Line 214 C++<br></div>
<div>vtkCommonCore-6.3.dll!vtkDataArrayTemplate<unsigned char>::~vtkDataArrayTemplate<unsigned char>() Line 92 C++<br></div>
<div>vtkCommonCore-6.3.dll!vtkUnsignedCharArray::~vtkUnsignedCharArray() Line 37 C++<br></div>
<div>[External Code]<br></div>
<div>vtkCommonCore-6.3.dll!vtkObjectBase::UnRegisterInternal(vtkObjectBase * __formal, int check) Line 232 C++<br></div>
<div>vtkCommonCore-6.3.dll!vtkObject::UnRegisterInternal(vtkObjectBase * o, int check) Line 901 C++<br></div>
<div>vtkCommonCore-6.3.dll!vtkObjectBase::UnRegister(vtkObjectBase * o) Line 190 C++<br></div>
<div>vtkCommonCore-6.3.dll!vtkLookupTable::~vtkLookupTable() Line 89C++<br></div>
<div>[External Code]<br></div>
<div>vtkCommonCore-6.3.dll!vtkObjectBase::UnRegisterInternal(vtkObjectBase * __formal, int check) Line 232 C++<br></div>
<div>vtkCommonCore-6.3.dll!vtkObject::UnRegisterInternal(vtkObjectBase * o, int check) Line 901 C++<br></div>
<div>vtkCommonCore-6.3.dll!vtkObjectBase::UnRegister(vtkObjectBase * o) Line 190 C++<br></div>
<div>vtkCommonCore-6.3.dll!vtkSmartPointerBase::~vtkSmartPointerBase() Line 62 C++<br></div>
<div>[External Code]<br></div>
<div> </div>
<div>Any insight would be appreciated.<br></div>
<div> </div>
<div>Regards, </div>
<div> </div>
<div>Audrius</div>
<div> </div>
<div>//---------------------------------------<br></div>
<div><span style="line-height: 1.25;">// Start: relevant code fragment</span><br></div>
<div>//---------------------------------------<br></div>
<div> </div>
<div>{<br></div>
<div>. . .<br></div>
<div> </div>
<div><span style="line-height: 10.8333px;">vtkSmartPointer<vtkCamera> </span>camera_ = <span style="line-height: 10.8333px;">vtkSmartPointer<vtkCamera>::New();</span><br></div>
<div> </div>
<div>camera_->SetPosition( 0.0, 0.0, -1.0);<br></div>
<div>camera_->SetRoll(180.0);<br></div>
<div> </div>
<div>camera_->Zoom( zoomFactor_ );<br></div>
<div> </div>
<div><span style="line-height: 10.8333px;">//---------------</span><br></div>
<div><span style="line-height: 10.8333px;"><span style="line-height: 10.8333px;">vtkSmartPointer<vtkRenderer> </span>renderer_ = vtkSmartPointer<vtkRenderer>::New();</span><br></div>
<div><span style="line-height: 10.8333px;">renderer_->SetActiveCamera(camera_);</span><br></div>
<div><span style="line-height: 10.8333px;">renderer_->SetBackground( 0.0, 0.0, 0.0 );</span><br></div>
<div> </div>
<div><span style="line-height: 10.8333px;">//---------------</span><br></div>
<div><span style="line-height: 10.8333px;"><span style="line-height: 10.8333px;">vtkSmartPointer<vtkRenderWindow> </span>renderWindow_ = vtkSmartPointer<vtkRenderWindow>::New();</span><br></div>
<div><span style="line-height: 10.8333px;">renderWindow_->AddRenderer( renderer_ );</span><br></div>
<div><span style="line-height: 10.8333px;">renderWindow_->SetSize</span><br></div>
<div><span style="line-height: 10.8333px;">( winSizeX_</span><br></div>
<div><span style="line-height: 10.8333px;">, winSizeY_ );</span><br></div>
<div><span style="line-height: 10.8333px;">renderWindow_->SetPosition</span><br></div>
<div><span style="line-height: 10.8333px;">( winPosX_</span><br></div>
<div><span style="line-height: 10.8333px;">, winPosY_ );</span><br></div>
<div><span style="line-height: 10.8333px;">renderWindow_->SwapBuffersOn();</span><br></div>
<div> </div>
<div><span style="line-height: 10.8333px;">//---------------</span><br></div>
<div><span style="line-height: 10.8333px;"><span style="line-height: 10.8333px;">vtkSmartPointer<vtkRenderWindowInteractor> </span>renderWindowInteractor_ = vtkSmartPointer<vtkRenderWindowInteractor>::New();</span><br></div>
<div><span style="line-height: 10.8333px;">renderWindowInteractor_->SetRenderWindow( renderWindow_); </span><br></div>
<div> </div>
<div><span style="line-height: 10.8333px;"><span style="line-height: 10.8333px;">vtkSmartPointer<vtkCallbackCommand> </span>keyPressCallback_ = vtkSmartPointer<vtkCallbackCommand>::New();</span><br></div>
<div><span style="line-height: 10.8333px;">keyPressCallback_->SetCallback( advDiagnosticDisplay::KeyPressCallbackFunction);</span><br></div>
<div> </div>
<div><span style="line-height: 10.8333px;">renderWindowInteractor_->AddObserver</span><br></div>
<div><span style="line-height: 10.8333px;">( vtkCommand::KeyPressEvent</span><br></div>
<div><span style="line-height: 10.8333px;">, keyPressCallback_ );</span><br></div>
<div><div> </div>
<div><div><div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>// Build a colour map<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"><span style="line-height: 10.8333px;">vtkSmartPointer<vtkLookupTable> </span></span>colourMap_ = vtkSmartPointer<vtkLookupTable>::New();<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>InitializeColourMap(colourMap_);<br></div>
<div style="line-height: 10.8333px;"> </div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>// Apply the texture<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"><span style="line-height: 10.8333px;">vtkSmartPointer<vtkTexture> </span></span>texture_ = vtkSmartPointer<vtkTexture>::New();<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>if(interpolation_) <br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>texture_->InterpolateOn();<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>else<span class="Apple-tab-span" style="white-space: pre;"></span> <br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>texture_->InterpolateOff();<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>texture_->RepeatOff();<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>texture_->SetQualityTo32Bit();<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>texture_->MapColorScalarsThroughLookupTableOn();<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>texture_->SetInputData( imageReslice_->GetOutput());<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>texture_->SetLookupTable( colourMap_);<br></div>
<div style="line-height: 10.8333px;"> </div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>//---------------<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"><span style="line-height: 10.8333px;">vtkSmartPointer<vtkPlaneSource> </span></span>planeSource_ = vtkSmartPointer<vtkPlaneSource>::New();<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>planeSource_->SetResolution( 1, 1 );<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>planeSource_->SetPoint1( eX_, 0.0, 0.0);<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>planeSource_->SetPoint2( 0.0, eY_, 0.0);<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>planeSource_->SetCenter( centre_.data());<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>planeSource_->SetNormal( 0.0, 0.0, 1.0);<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>planeSource_->Update();<br></div>
<div style="line-height: 10.8333px;"> </div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>//---------------<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"><span style="line-height: 10.8333px;">vtkSmartPointer<vtkPolyDataMapper> </span></span>mapper_ = vtkSmartPointer<vtkPolyDataMapper>::New();<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>mapper_->ScalarVisibilityOff(); <br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>mapper_->SetInputData( planeSource_->GetOutput());<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>mapper_->Update();<br></div>
<div style="line-height: 10.8333px;"> </div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>//---------------<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"><span style="line-height: 10.8333px;">vtkSmartPointer<vtkProperty> </span></span>property_ = vtkSmartPointer<vtkProperty>::New();<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>property_->SetOpacity( opacity_);<br></div>
<div style="line-height: 10.8333px;"> </div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>//---------------<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"><span style="line-height: 10.8333px;">vtkSmartPointer<vtkActor> </span></span>actor_ = vtkSmartPointer<vtkActor>::New();<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>actor_->SetProperty( property_ );<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>actor_->SetTexture( texture_ );<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>actor_->SetMapper( mapper_ );<br></div>
<div style="line-height: 10.8333px;"> </div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>//---------------<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>renderer_->AddActor(actor_);<br></div>
<div style="line-height: 10.8333px;"> </div>
</div>
<div>renderer_->ResetCamera();<br></div>
</div>
</div>
<div> </div>
<div>renderWindow_->Render();<br></div>
<div>renderWindow_->SetWindowName( "Window name here");<br></div>
<div> </div>
<div>renderWindowInteractor_->Start();<br></div>
<div> </div>
<div><div><div><div><div><span style="line-height: 10.8333px;">. . .</span><br></div>
<div> </div>
<div><span style="line-height: 10.8333px;">}</span><br></div>
</div>
<div style="line-height: 10.8333px;"> </div>
<div style="line-height: 10.8333px;"><div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>void InitializeColourMap(vtkSmartPointer<vtkLookupTable>& colourMap)<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>{<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>//---------------<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>colourMap->SetNumberOfColors(nImageColours_ + 1);<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>colourMap->SetTableRange<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>(minScalar_<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>, maxScalar_);<br></div>
<div style="line-height: 10.8333px;"> </div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>if (colour_)<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>{<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>colourMap->SetHueRange(0.666667f, 0.0f);<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>colourMap->Build();<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>colourMap->SetTableValue(0, 0.0f, 0.0f, 0.0f, 0.0f);<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>}<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>else<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>{<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>colourMap->SetHueRange(0.5f, 0.5f);<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>colourMap->SetSaturationRange(0.0f, 1.0f);<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>colourMap->Build();<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>colourMap->SetTableValue(0, 0.0f, 0.0f, 0.0f, 0.0f);<br></div>
<div style="line-height: 10.8333px;"> </div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>for (int iC = 1; iC <= nImageColours_; ++iC)<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>{<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>const float val = static_cast<float>(iC) / static_cast<float>(nImageColours_ + 1);<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>colourMap->SetTableValue<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>(iC<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>, val<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>, val<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>, val<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>, 1.0f);<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>}<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>}<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>}<br></div>
<div style="line-height: 10.8333px;"> </div>
</div>
</div>
<div style="line-height: 10.8333px;"> </div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="line-height: 10.8333px; white-space: pre;"></span><span style="line-height: 10.8333px;">// </span><br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>// vtk callback function: stop rendering and close window<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="line-height: 10.8333px; white-space: pre;"></span><span style="line-height: 10.8333px;">// </span><br></div>
<div style="line-height: 10.8333px;"> </div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>static void KeyPressCallbackFunction<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>( vtkObject* caller<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>, long unsigned int vtkNotUsed(eventId)<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>, void* vtkNotUsed(clientData)<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>, void* vtkNotUsed(callData))<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>{<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>vtkRenderWindowInteractor* renderWindowInteractor = dynamic_cast<vtkRenderWindowInteractor*>(caller);<br></div>
<div style="line-height: 10.8333px;"> </div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="line-height: 10.8333px; white-space: pre;"></span>// Close the window<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>vtkRenderWindow* renderWindow = renderWindowInteractor->GetRenderWindow();<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>renderWindow->Finalize();<br></div>
<div style="line-height: 10.8333px;"> </div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>// Stop the interactor<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="line-height: 10.8333px; white-space: pre;"></span>// When the next line is executed, the heap corruption message is generated<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>renderWindowInteractor->TerminateApp();<br></div>
<div style="line-height: 10.8333px;"> </div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>std::cout << "Window closed." << std::endl;<br></div>
<div style="line-height: 10.8333px;"><span class="Apple-tab-span" style="white-space: pre;"></span>}<br></div>
</div>
</div>
<div> </div>
<div> </div>
<div> </div>
</body>
</html>