Skip to content

Commit

Permalink
BUG #16744: Resources are not removed for a renderer removed from the…
Browse files Browse the repository at this point in the history
… window.

A loop where the render window is kept around and everything in the pipeline is removed
and added at the next iteration leaks memory, in OpenGL, linux. For the OpenGL2 backend same
loop does not leak.
Two problems were fixed. First ReleaseGraphicsResources was not called when
a renderer was removed from a render window. Second, for a offscreen render window
Mapped was set to 0, which meant that no resources were released.
  • Loading branch information
danlipsa committed Jun 20, 2016
1 parent b985df4 commit d560ec8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 32 deletions.
23 changes: 0 additions & 23 deletions Rendering/Core/vtkRenderer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1245,32 +1245,9 @@ void vtkRenderer::ResetCameraClippingRange(double xmin, double xmax,
// no reference counting!
void vtkRenderer::SetRenderWindow(vtkRenderWindow *renwin)
{
vtkProp *aProp;

if (renwin != this->RenderWindow)
{
// This renderer is be dis-associated with its previous render window.
// this information needs to be passed to the renderer's actors and
// volumes so they can release and render window specific (or graphics
// context specific) information (such as display lists and texture ids)
vtkCollectionSimpleIterator pit;
this->Props->InitTraversal(pit);
for ( aProp = this->Props->GetNextProp(pit);
aProp != NULL;
aProp = this->Props->GetNextProp(pit) )
{
aProp->ReleaseGraphicsResources(this->RenderWindow);
}
// what about lights?
// what about cullers?

this->ReleaseGraphicsResources(this->RenderWindow);

if(this->BackgroundTexture != 0 && this->RenderWindow!=0)
{
this->BackgroundTexture->ReleaseGraphicsResources(this->RenderWindow);
}

this->VTKWindow = renwin;
this->RenderWindow = renwin;
}
Expand Down
8 changes: 6 additions & 2 deletions Rendering/OpenGL/vtkOpenGLRenderer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1217,9 +1217,13 @@ void vtkOpenGLRenderer::StartPick(unsigned int pickFromSize)

void vtkOpenGLRenderer::ReleaseGraphicsResources(vtkWindow *w)
{
if (w && this->Pass)
if (w)
{
this->Pass->ReleaseGraphicsResources(w);
vtkRenderer::ReleaseGraphicsResources(w);
if (this->Pass)
{
this->Pass->ReleaseGraphicsResources(w);
}
}
}

Expand Down
15 changes: 8 additions & 7 deletions Rendering/OpenGL/vtkXOpenGLRenderWindow.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ void vtkXOpenGLRenderWindow::CreateOffScreenWindow(int width, int height)
}
} // if not hardware offscreen
}
this->Mapped = 0;
this->Mapped = 1;
this->Size[0] = width;
this->Size[1] = height;

Expand Down Expand Up @@ -997,6 +997,7 @@ void vtkXOpenGLRenderWindow::DestroyOffScreenWindow()
}
}
}
this->Mapped = 0;
}

void vtkXOpenGLRenderWindow::ResizeOffScreenWindow(int width, int height)
Expand Down Expand Up @@ -1100,7 +1101,7 @@ void vtkXOpenGLRenderWindow::SetFullScreen(int arg)

if (this->FullScreen == arg) return;

if (!this->Mapped)
if (!this->Mapped || this->OffScreenRendering)
{
this->PrefFullScreen();
return;
Expand Down Expand Up @@ -1209,7 +1210,7 @@ void vtkXOpenGLRenderWindow::SetSize(int width,int height)
{
this->ResizeOffScreenWindow(width,height);
}
else if(this->WindowId && this->Mapped)
else if(this->WindowId && this->Mapped && ! this->OffScreenRendering)
{
XResizeWindow(this->DisplayId,this->WindowId,
static_cast<unsigned int>(width),
Expand Down Expand Up @@ -1496,7 +1497,7 @@ int *vtkXOpenGLRenderWindow::GetPosition(void)
Window child;

// if we aren't mapped then just return the ivar
if (!this->Mapped)
if (!this->Mapped || this->OffScreenRendering)
{
return this->Position;
}
Expand Down Expand Up @@ -1540,7 +1541,7 @@ Window vtkXOpenGLRenderWindow::GetWindowId()
void vtkXOpenGLRenderWindow::SetPosition(int x, int y)
{
// if we aren't mapped then just set the ivars
if (!this->Mapped)
if (!this->Mapped || this->OffScreenRendering)
{
if ((this->Position[0] != x)||(this->Position[1] != y))
{
Expand Down Expand Up @@ -1769,7 +1770,7 @@ void vtkXOpenGLRenderWindow::SetWindowName(const char * cname)

this->vtkOpenGLRenderWindow::SetWindowName( name );

if (this->Mapped)
if (this->Mapped && ! this->OffScreenRendering)
{
if( XStringListToTextProperty( &name, 1, &win_name_text_prop ) == 0 )
{
Expand Down Expand Up @@ -1824,7 +1825,7 @@ void vtkXOpenGLRenderWindow::Render()
// To avoid the expensive XGetWindowAttributes call,
// compute size at the start of a render and use
// the ivar other times.
if (this->Mapped)
if (this->Mapped && ! this->OffScreenRendering)
{
// Find the current window size
XGetWindowAttributes(this->DisplayId,
Expand Down

0 comments on commit d560ec8

Please sign in to comment.