<div dir="ltr">Hi Audrius,<div><br></div><div>That is indeed suspicious. I don't immediately see anything in your code that would explain the crash. Would you mind attaching a compilable example program with accompanying CMakeLists.txt file? That will make it easier to take a look.</div><div><br></div><div>Thanks,</div><div>Cory</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Nov 5, 2015 at 11:19 PM, Audrius Stundzia <span dir="ltr"><<a href="mailto:audrius@tomographix.com" target="_blank">audrius@tomographix.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><u></u>




<div><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 style="white-space:pre-wrap"></span>// Build a colour map<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"><span style="line-height:10.8333px">vtkSmartPointer<vtkLookupTable> </span></span>colourMap_ = vtkSmartPointer<vtkLookupTable>::New();<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>InitializeColourMap(colourMap_);<br></div>
<div style="line-height:10.8333px"> </div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>// Apply the texture<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"><span style="line-height:10.8333px">vtkSmartPointer<vtkTexture> </span></span>texture_ = vtkSmartPointer<vtkTexture>::New();<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>if(interpolation_) <br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>texture_->InterpolateOn();<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>else<span style="white-space:pre-wrap"></span> <br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>texture_->InterpolateOff();<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>texture_->RepeatOff();<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>texture_->SetQualityTo32Bit();<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>texture_->MapColorScalarsThroughLookupTableOn();<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>texture_->SetInputData( imageReslice_->GetOutput());<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>texture_->SetLookupTable( colourMap_);<br></div>
<div style="line-height:10.8333px"> </div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>//---------------<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"><span style="line-height:10.8333px">vtkSmartPointer<vtkPlaneSource> </span></span>planeSource_ = vtkSmartPointer<vtkPlaneSource>::New();<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>planeSource_->SetResolution( 1, 1 );<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>planeSource_->SetPoint1( eX_, 0.0, 0.0);<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>planeSource_->SetPoint2( 0.0, eY_, 0.0);<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>planeSource_->SetCenter( centre_.data());<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>planeSource_->SetNormal( 0.0, 0.0, 1.0);<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>planeSource_->Update();<br></div>
<div style="line-height:10.8333px"> </div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>//---------------<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"><span style="line-height:10.8333px">vtkSmartPointer<vtkPolyDataMapper> </span></span>mapper_ = vtkSmartPointer<vtkPolyDataMapper>::New();<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>mapper_->ScalarVisibilityOff(); <br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>mapper_->SetInputData( planeSource_->GetOutput());<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>mapper_->Update();<br></div>
<div style="line-height:10.8333px"> </div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>//---------------<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"><span style="line-height:10.8333px">vtkSmartPointer<vtkProperty> </span></span>property_ = vtkSmartPointer<vtkProperty>::New();<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>property_->SetOpacity( opacity_);<br></div>
<div style="line-height:10.8333px"> </div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>//---------------<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"><span style="line-height:10.8333px">vtkSmartPointer<vtkActor> </span></span>actor_ = vtkSmartPointer<vtkActor>::New();<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>actor_->SetProperty( property_ );<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>actor_->SetTexture( texture_ );<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>actor_->SetMapper( mapper_ );<br></div>
<div style="line-height:10.8333px"> </div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>//---------------<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></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 style="white-space:pre-wrap"></span>void InitializeColourMap(vtkSmartPointer<vtkLookupTable>& colourMap)<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>{<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>//---------------<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>colourMap->SetNumberOfColors(nImageColours_ + 1);<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>colourMap->SetTableRange<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>(minScalar_<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>, maxScalar_);<br></div>
<div style="line-height:10.8333px"> </div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>if (colour_)<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>{<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>colourMap->SetHueRange(0.666667f, 0.0f);<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>colourMap->Build();<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>colourMap->SetTableValue(0, 0.0f, 0.0f, 0.0f, 0.0f);<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>}<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>else<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>{<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>colourMap->SetHueRange(0.5f, 0.5f);<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>colourMap->SetSaturationRange(0.0f, 1.0f);<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>colourMap->Build();<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></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 style="white-space:pre-wrap"></span>for (int iC = 1; iC <= nImageColours_; ++iC)<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>{<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>const float val = static_cast<float>(iC) / static_cast<float>(nImageColours_ + 1);<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>colourMap->SetTableValue<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>(iC<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>, val<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>, val<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>, val<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>, 1.0f);<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>}<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>}<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></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 style="line-height:10.8333px;white-space:pre-wrap"></span><span style="line-height:10.8333px">// </span><br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>// vtk callback function: stop rendering and close window<br></div>
<div style="line-height:10.8333px"><span style="line-height:10.8333px;white-space:pre-wrap"></span><span style="line-height:10.8333px">// </span><br></div>
<div style="line-height:10.8333px"> </div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>static void KeyPressCallbackFunction<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>( vtkObject* caller<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>, long unsigned int vtkNotUsed(eventId)<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>, void* vtkNotUsed(clientData)<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>, void* vtkNotUsed(callData))<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>{<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>vtkRenderWindowInteractor* renderWindowInteractor = dynamic_cast<vtkRenderWindowInteractor*>(caller);<br></div>
<div style="line-height:10.8333px"> </div>
<div style="line-height:10.8333px"><span style="line-height:10.8333px;white-space:pre-wrap"></span>// Close the window<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>vtkRenderWindow* renderWindow = renderWindowInteractor->GetRenderWindow();<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>renderWindow->Finalize();<br></div>
<div style="line-height:10.8333px"> </div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>// Stop the interactor<br></div>
<div style="line-height:10.8333px"><span style="line-height:10.8333px;white-space:pre-wrap"></span>// When the next line is executed, the heap corruption message is generated<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>renderWindowInteractor->TerminateApp();<br></div>
<div style="line-height:10.8333px"> </div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>std::cout << "Window closed." << std::endl;<br></div>
<div style="line-height:10.8333px"><span style="white-space:pre-wrap"></span>}<br></div>
</div>
</div>
<div> </div>
<div> </div>
<div> </div>
</div>

<br>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" rel="noreferrer" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Search the list archives at: <a href="http://markmail.org/search/?q=vtkusers" rel="noreferrer" target="_blank">http://markmail.org/search/?q=vtkusers</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/vtkusers" rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/vtkusers</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Cory Quammen<br>R&D Engineer<br>Kitware, Inc.</div>
</div>