[vtkusers] CRITICAL Memory leak with vtkInteractorStyleRubberBandZoom
Denis Shamonin
dshamoni at science.uva.nl
Wed Nov 5 10:10:24 EST 2003
Hi Amy,
There is critical memory leak with vtkInteractorStyleRubberBandZoom.
Always happen very soon during playing with
vtkInteractorStyleRubberBandZoom in combination Reset View.
To get it try this:
1) Run simple example (below) with vtkInteractorStyleRubberBandZoom
2) Start zoom and ResetView ("r" in vtkRenderWindowInteractor) in
different combinations.
In my case less than 100 operation will give you memory leak.
One more, after around 50 such exercises, zooming will stop working at
all (Zoom = Pan).
Result:
1) Very soon swap will be empty, computer will slow down.
I am not happy with it. :(
Example for testing:
===========================================================================
#include <vtkConeSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkCamera.h>
#include <vtkActor.h>
#include <vtkRenderer.h>
#include "vtkInteractorStyleTrackballCamera.h"
#include "vtkInteractorStyleJoystickCamera.h"
#include "vtkInteractorStyleTerrain.h"
#include "vtkInteractorStyleRubberBandZoom.h"
#include <unistd.h>
void usage() {
fprintf(stderr, "style: (testing for different interaction styles)\n\n");
fprintf(stderr, "usage: style [-s style] [-h]\n\n");
fprintf(stderr, "-s 1 : InteractorStyleTrackballCamera\n");
fprintf(stderr, "-s 2 : InteractorStyleJoystickCamera\n");
fprintf(stderr, "-s 3 : InteractorStyleTerrain\n");
fprintf(stderr, "-s 4 : InteractorStyleRubberBandZoom\n");
fprintf(stderr, "-h : this (help) message\n");
fprintf(stderr, "\nusage examples:\n"
" $style -s 1\n\n");
}
int main( int argc, char *argv[] )
{
int StyleId = 0; // Style for testing
extern char *optarg;
extern int optind;
char *options = "s:h";
int o, err = 0;
// If no arguments, just print help and exit
if (argc == 1) { usage(); exit(0);}
// Parse command line options
while ((o = getopt(argc,argv,options)) != -1) {
switch(o) {
case 's':
StyleId = atoi((const char*)optarg);
break;
case 'h':
usage();
exit(0);
default:
usage();
err = 1;
}
}
vtkInteractorStyle *style = NULL;
switch(StyleId)
{
case 1:
style = vtkInteractorStyleTrackballCamera::New();
break;
case 2:
style = vtkInteractorStyleJoystickCamera::New();
break;
case 3:
style = vtkInteractorStyleTerrain::New();
break;
case 4:
style = vtkInteractorStyleRubberBandZoom::New();
break;
default:
usage();
exit(0);
}
// Main staff
vtkRenderer *ren = vtkRenderer::New();
vtkConeSource *cone = vtkConeSource::New();
cone->SetHeight( 3.0 );
cone->SetRadius( 1.0 );
cone->SetResolution( 10 );
vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New();
coneMapper->SetInput( cone->GetOutput() );
vtkActor *coneActor = vtkActor::New();
coneActor->SetMapper( coneMapper );
ren->AddActor( coneActor );
ren->SetBackground( 0.5, 0.5, 0.5 );
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer( ren );
renWin->SetSize( 300, 300 );
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
iren->SetInteractorStyle(style);
iren->Initialize();
iren->Start();
cone->Delete();
coneMapper->Delete();
coneActor->Delete();
ren->Delete();
renWin->Delete();
iren->Delete();
return 0;
}
===========================================================================
--
Denis Shamonin
Section Computational Science
University of Amsterdam
Kruislaan 403, 1098 SJ Amsterdam
the Netherlands
http://carol.wins.uva.nl/~dshamoni/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20031105/7b452465/attachment.htm>
More information about the vtkusers
mailing list