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