Fair enough, however that is ancillary to my problem.<br><br><div class="gmail_quote">On Tue, Feb 28, 2012 at 3:14 PM, Alex Malyushytskyy <span dir="ltr"><<a href="mailto:alexmalvtk@gmail.com">alexmalvtk@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The line below will crush the program. cause :widget will be deleted<br>
twice, one time by parent ,<br>
one time when going out of scope.<br>
<br>
MyQVTKWidget2 widget(imageViewer);<br>
<br>
<br>
You should never do such thing with Qt widget( and any QObject derived classes<br>
Use new operator to instantiate children.<br>
<br>
Alex<br>
<div><div class="h5"><br>
<br>
<br>
On Fri, Feb 24, 2012 at 2:25 PM, Jonathan Morra <<a href="mailto:jonmorra@gmail.com">jonmorra@gmail.com</a>> wrote:<br>
> OK, here is a small example that shows the problem. I'm monitoring the<br>
> memory using task manager. When the render line is commented out the memory<br>
> stays constant as you mouse over the image. However, if that line is<br>
> uncommented then then memory climbs rapidly. The program crashes when you<br>
> exit, but that doesn't concern me right now, I'm focused on the memory leak.<br>
><br>
> Thanks<br>
><br>
> #include <QtGui/QApplication><br>
><br>
> #include <QMainWindow><br>
><br>
> #include <QVTKWidget2.h><br>
><br>
> #include <vtkImageViewer2.h><br>
><br>
> #include <vtkImageData.h><br>
><br>
> #include <vtkPointData.h><br>
><br>
> #include <vtkGenericOpenGLRenderWindow.h><br>
><br>
> class MyQVTKWidget2 : public QVTKWidget2 {<br>
><br>
> public:<br>
><br>
> MyQVTKWidget2 (vtkImageViewer2 *imageViewer, QWidget *parent = 0) :<br>
> QVTKWidget2(parent) {<br>
><br>
> this->imageViewer = imageViewer;<br>
><br>
> }<br>
><br>
> virtual ~MyQVTKWidget2() {<br>
><br>
> imageViewer->Delete();<br>
><br>
> }<br>
><br>
> void mouseMoveEvent(QMouseEvent *) {<br>
><br>
> // Comment out this line to see the memory stay constant<br>
><br>
> imageViewer->Render();<br>
><br>
> }<br>
><br>
> private:<br>
><br>
> vtkImageViewer2 *imageViewer;<br>
><br>
> };<br>
><br>
> int main(int argc, char *argv[]) {<br>
><br>
> QApplication a(argc, argv);<br>
><br>
> vtkImageData *imageData = vtkImageData::New();<br>
><br>
> imageData->SetExtent(0, 100, 0, 100, 0, 100);<br>
><br>
> imageData->SetOrigin(0, 0, 0);<br>
><br>
> imageData->SetSpacing(1, 1, 1);<br>
><br>
> imageData->AllocateScalars();<br>
><br>
> imageData->GetPointData()->GetScalars()->FillComponent(0, 0);<br>
><br>
> vtkImageViewer2 *imageViewer = vtkImageViewer2::New();<br>
><br>
> imageViewer->SetInput(imageData);<br>
><br>
> MyQVTKWidget2 widget(imageViewer);<br>
><br>
> imageViewer->SetRenderWindow(widget.GetRenderWindow());<br>
><br>
> QMainWindow mainWindow;<br>
><br>
> mainWindow.setGeometry(200, 200, 300, 300);<br>
><br>
> mainWindow.setCentralWidget(&widget);<br>
><br>
> mainWindow.show();<br>
><br>
> imageData->Delete();<br>
><br>
> return a.exec();<br>
><br>
> }<br>
><br>
><br>
> On Fri, Feb 24, 2012 at 1:36 PM, Jonathan Morra <<a href="mailto:jonmorra@gmail.com">jonmorra@gmail.com</a>> wrote:<br>
>><br>
>> I will spend some time and try and put together a small self contained<br>
>> test.<br>
>><br>
>><br>
>> On Fri, Feb 24, 2012 at 1:29 PM, Clinton Stimpson <<a href="mailto:clinton@elemtech.com">clinton@elemtech.com</a>><br>
>> wrote:<br>
>>><br>
>>> On Friday, February 24, 2012 02:19:59 pm Jonathan Morra wrote:<br>
>>> > I have recently converted my app from using QVTKWidget to QVTKWidget2<br>
>>> > so<br>
>>> > that I could paint on the QVTKWidget2 (which I was able to successfully<br>
>>> > do). After this conversion my app started to leak memory terribly. I<br>
>>> > followed the memory leak around, and found the culprit is the following<br>
>>> > line<br>
>>> ><br>
>>> > glTexImage2D(GL_TEXTURE_2D, 0, internalFormat,<br>
>>> ><br>
>>> > xsize, ysize, 0, format,<br>
>>> ><br>
>>> > GL_UNSIGNED_BYTE, static_cast<const GLvoid<br>
>>> > *>(data));<br>
>>> ><br>
>>> ><br>
>>> > Which is in the following function<br>
>>> ><br>
>>> ><br>
>>> > void vtkOpenGLImageSliceMapper::RenderTexturedPolygon(<br>
>>> ><br>
>>> > vtkRenderer *ren, vtkImageProperty *property,<br>
>>> ><br>
>>> > vtkImageData *input, int extent[6], bool recursive)<br>
>>> ><br>
>>> ><br>
>>> > I am using a build that I got from git on January 10th. I have a 64<br>
>>> > bit Windows 7 machine, but have built VTK with Microsoft Visual<br>
>>> > Studios 2008 32 bit.<br>
>>> ><br>
>>> ><br>
>>> > This bug is manifested everytime I call render on a QVTKWidget2 that I<br>
>>> > have placed a vtkImageViewer2 in. This is a very critical bug for us<br>
>>> > as now our program runs out of memory very quickly because there are<br>
>>> > situations where render is called on every mouse move which means the<br>
>>> > program will die extremely fast. Any help would be appreciated.<br>
>>> ><br>
>>><br>
>>> Ok, I see the cause of the problem.<br>
>>><br>
>>> QVTKWidget2::Start() calls OpenGLInit(), which resets the context<br>
>>> creation<br>
>>> time and the vtkOpenGLImageSliceMapper reloads them thinking its a new<br>
>>> context.<br>
>>><br>
>>> It would helpful if you can provide a minimal test case to demonstrate<br>
>>> this.<br>
>>><br>
>>> --<br>
>>> Clinton Stimpson<br>
>>> Elemental Technologies, Inc<br>
>>> Computational Simulation Software, LLC<br>
>>> <a href="http://www.csimsoft.com" target="_blank">www.csimsoft.com</a><br>
>><br>
>><br>
><br>
><br>
</div></div>> _______________________________________________<br>
> Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
><br>
> Visit other Kitware open-source projects at<br>
> <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
><br>
> Please keep messages on-topic and check the VTK FAQ at:<br>
> <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> <a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
><br>
</blockquote></div><br>