[vtkusers] Fwd: multiple instances of subclass allocated by factory when unrelated class New() is called
Alex Malyushytskyy
alexmalvtk at gmail.com
Wed Nov 4 20:58:43 EST 2009
Sorry for replying directly, forwarding it to the mailing list,
Alex
---------- Forwarded message ----------
From: Alex Malyushytskyy <alexmalvtk at gmail.com>
Date: Wed, Nov 4, 2009 at 5:56 PM
Subject: Re: [vtkusers] multiple instances of subclass allocated by
factory when unrelated class New() is called
To: David E DeMarle <dave.demarle at kitware.com>
David,
Your comments were very helpful.
I overrided CreateObject(const char* vtkclassname ) instead of using
RegisterOverride and now it behaves the way I wanted .
Many thanks,
Alex
> this->RegisterOverride("vtkPolyData",
> "BuildingPolyData",
> "Building Poly Data",
> 1,
> vtkObjectFactoryCreateBuildingPolyData);
>
On Wed, Nov 4, 2009 at 4:56 PM, David E DeMarle
<dave.demarle at kitware.com> wrote:
> this->RegisterOverride("vtkPolyData",
> "BuildingPolyData",
> "Building Poly Data",
> 1,
> vtkObjectFactoryCreateBuildingPolyData);
>
> Means that that every time the application calls vtkPolyData:New(),
> BuildingPolyData() is called instead. vtkPolyData's are made inside
> VTK in many places (grep for vtkPolyData::New()).
>
> The intended use for object overriding is to make a specialization of
> a generic class. For instance vtkRenderWindow::New makes
> vtkX11OpenGLRenderWindows on Linux or vtkCarbonRenderWindows on Macs
> etc. Once created the objects persist until the reference count goes
> to zero.
>
> David E DeMarle
> Kitware, Inc.
> R&D Engineer
> 28 Corporate Drive
> Clifton Park, NY 12065-8662
> Phone: 518-371-3971 x109
>
>
>
> On Wed, Nov 4, 2009 at 7:43 PM, Alex Malyushytskyy <alexmalvtk at gmail.com> wrote:
>> 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
>>
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtkusers
>>
>>
>
More information about the vtkusers
mailing list