[vtkusers] multiple instances of subclass allocated by factory when unrelated class New() is called

Alex Malyushytskyy alexmalvtk at gmail.com
Wed Nov 4 19:43:00 EST 2009


Hi,

I am using VTK 5.4.2 compiled as dlls with QT 4 support. Language used is C++.

I derived my class BuidingPolyData from vtkPolyData according to the
VTK User's Guide.
Factory is installed with RegisterFactory. according to the same guide
(case when  factory is compiled in application).

On the first glance code works, but if you start looking deeper you
find very strange and scary things happening.

In model3dView (model3dView.cpp) constructor my code instantiate
pipeline , mapper , actors and a few widgets.
There is no BuidingPolyData instances supposed to be created by me
yet. It will be created later when user read data from stl file.

But ::New() calls for other classes lead to the
VTK_CREATE_CREATE_FUNCTION( BuildingPolyData ); macro execution.

These objects are not only created, most of them persist until program exit.

I put counters in the BuildingPolyData constructor. One shows how many
instances are currently allocated, another shows how many instances
still remain.

For example call to:

vtkAxesActor* testActor = vtkAxesActor::New();
will create 16 additional instances of BuildingPolyData ( see debug.out)

By the time all objects are initialized  there are like 38 instances
of BuidingPolyData  created.
NONE of them are created by me yet. All are results of the function
New calls for unrelated classes.

Could anybody  give me an idea why this may  happen,  what can be
wrong, how it could be fixed?
There are files in attachment. I tried to remove unrelated code to
make it simple.

Thanks in advance and best regards,
          Alex
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vtkBuildingPolyDataFactory.h
Type: application/octet-stream
Size: 455 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20091104/25e9df70/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: BuildingPolyData.cpp
Type: application/octet-stream
Size: 1144 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20091104/25e9df70/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: BuildingPolyData.h
Type: application/octet-stream
Size: 726 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20091104/25e9df70/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: model3dView.cpp
Type: application/octet-stream
Size: 5636 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20091104/25e9df70/attachment-0003.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: model3dView.h
Type: application/octet-stream
Size: 1650 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20091104/25e9df70/attachment-0004.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vtkBuildingPolyDataFactory.cpp
Type: application/octet-stream
Size: 1224 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20091104/25e9df70/attachment-0005.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: debug.out
Type: application/octet-stream
Size: 6315 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20091104/25e9df70/attachment-0006.obj>


More information about the vtkusers mailing list