Deleting unknown object: vtkObject - vector of pointers?

View: New views
18 Messages — Rating Filter:   Alert me  

Deleting unknown object: vtkObject - vector of pointers?

by David Doria-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I am trying to make a vector of vector of pointers to my class. When this small demo enters the inner loop for the second time, I get a whole bunch of "Deleting unknown object: vtkObject".

Does anyone see a problem with this code? Or is there potentially a problem inside one of my vtkRay or vtkLidarPoint? I'm assuming something is happening when one of these is going out of scope since the errors occur on the loop entrance, but I don't see the problem with what is done here.

#include "vtkLidarPoint.h"
#include "vtkRay.h"

#include "vtkSmartPointer.h"

#include <vector>

int main()
{

  vtkstd::cout << "Deleting unknown object example2:" << vtkstd::endl;
 
  vtkstd::vector<vtkstd::vector<vtkLidarPoint*> > OutputGrid;
  OutputGrid.resize(10);
 
  for(unsigned int thetaCounter = 0; thetaCounter < 10; thetaCounter++)
  {
    vtkstd::vector<vtkLidarPoint*> Column;
    Column.clear();
    Column.resize(10);
 
    for(unsigned int phiCounter = 0; phiCounter < 10; phiCounter++) //THIS LINE
    {
      vtkSmartPointer<vtkRay> Ray = vtkSmartPointer<vtkRay>::New();
     
      vtkSmartPointer<vtkLidarPoint> LidarPoint = vtkSmartPointer<vtkLidarPoint>::New();
      LidarPoint->SetRay(Ray);
     
      Column[phiCounter] = LidarPoint;
 
    }
 
    OutputGrid[thetaCounter] = Column;
  }
 
  return 0;
}

Any comments?

Thanks,

David

_______________________________________________
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

Re: Deleting unknown object: vtkObject - vector of pointers?

by Bill Lorensen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

David,


Try printing the reference count of each LidarPoint before and after
std::cout << "Ref Before: " << LidarPoint->GetReferenceCount() << std::endl;
Column[phiCounter] = LidarPoint;
std::cout << "Ref After: " << LidarPoint->GetReferenceCount() << std::endl;

And outside the end of the inner loop:
std::cout << "Ref outside loop: " <<
OutputGrid[0]-.GetReferenceCount() << std::endl;

On Fri, Nov 6, 2009 at 7:51 AM, David Doria <daviddoria+vtk@...> wrote:

> I am trying to make a vector of vector of pointers to my class. When this
> small demo enters the inner loop for the second time, I get a whole bunch of
> "Deleting unknown object: vtkObject".
>
> Does anyone see a problem with this code? Or is there potentially a problem
> inside one of my vtkRay or vtkLidarPoint? I'm assuming something is
> happening when one of these is going out of scope since the errors occur on
> the loop entrance, but I don't see the problem with what is done here.
>
> #include "vtkLidarPoint.h"
> #include "vtkRay.h"
>
> #include "vtkSmartPointer.h"
>
> #include <vector>
>
> int main()
> {
>
>   vtkstd::cout << "Deleting unknown object example2:" << vtkstd::endl;
>
>   vtkstd::vector<vtkstd::vector<vtkLidarPoint*> > OutputGrid;
>   OutputGrid.resize(10);
>
>   for(unsigned int thetaCounter = 0; thetaCounter < 10; thetaCounter++)
>   {
>     vtkstd::vector<vtkLidarPoint*> Column;
>     Column.clear();
>     Column.resize(10);
>
>     for(unsigned int phiCounter = 0; phiCounter < 10; phiCounter++) //THIS
> LINE
>     {
>       vtkSmartPointer<vtkRay> Ray = vtkSmartPointer<vtkRay>::New();
>
>       vtkSmartPointer<vtkLidarPoint> LidarPoint =
> vtkSmartPointer<vtkLidarPoint>::New();
>       LidarPoint->SetRay(Ray);
>
>       Column[phiCounter] = LidarPoint;
>
>     }
>
>     OutputGrid[thetaCounter] = Column;
>   }
>
>   return 0;
> }
>
> Any comments?
>
> Thanks,
>
> David
>
> _______________________________________________
> 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
>
>
_______________________________________________
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

Re: Deleting unknown object: vtkObject - vector of pointers?

by David Doria-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, Nov 6, 2009 at 8:27 AM, Bill Lorensen <bill.lorensen@...> wrote:
David,


Try printing the reference count of each LidarPoint before and after
std::cout << "Ref Before: " << LidarPoint->GetReferenceCount() << std::endl;
Column[phiCounter] = LidarPoint;
std::cout << "Ref After: " << LidarPoint->GetReferenceCount() << std::endl;

And outside the end of the inner loop:
std::cout << "Ref outside loop: " <<
OutputGrid[0]-.GetReferenceCount() << std::endl;


Both before and after Column[phiCounter] = LidarPoint;, the reference count is 1.

I changed
vtkstd::vector<vtkLidarPoint*> Column;
to
vtkstd::vector<vtkSmartPointer<vtkLidarPoint> > Column;
so that the reference count increases to 2 after Column[phiCounter] = LidarPoint;

I also changed
vtkstd::vector<vtkstd::vector<vtkLidarPoint*> > OutputGrid;
to
vtkstd::vector<vtkstd::vector<vtkSmartPointer<vtkLidarPoint> > > OutputGrid;
based on the same logic.

I now get many less errors, but I still get a single
Deleting unknown object: vtkObject
every time the inner loop is entered.

I'm assuming it is because the vtkRay is going out of scope at the end of the loop and I haven't made LidarPoint::SetRay accept a smart pointer?

Is all of this the correct way to approach storing these objects?

Thanks,

David

_______________________________________________
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

Re: Deleting unknown object: vtkObject - vector of pointers?

by Bill Lorensen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Does SetRay increment the reference count of the Ray? Using
this->Ray->Register(this)

I tried your example with two vtk objects and it worked as expected.

Bill

On Fri, Nov 6, 2009 at 8:52 AM, David Doria <daviddoria+vtk@...> wrote:

> On Fri, Nov 6, 2009 at 8:27 AM, Bill Lorensen <bill.lorensen@...>
> wrote:
>>
>> David,
>>
>>
>> Try printing the reference count of each LidarPoint before and after
>> std::cout << "Ref Before: " << LidarPoint->GetReferenceCount() <<
>> std::endl;
>> Column[phiCounter] = LidarPoint;
>> std::cout << "Ref After: " << LidarPoint->GetReferenceCount() <<
>> std::endl;
>>
>> And outside the end of the inner loop:
>> std::cout << "Ref outside loop: " <<
>> OutputGrid[0]-.GetReferenceCount() << std::endl;
>>
>
> Both before and after Column[phiCounter] = LidarPoint;, the reference count
> is 1.
>
> I changed
> vtkstd::vector<vtkLidarPoint*> Column;
> to
> vtkstd::vector<vtkSmartPointer<vtkLidarPoint> > Column;
> so that the reference count increases to 2 after Column[phiCounter] =
> LidarPoint;
>
> I also changed
> vtkstd::vector<vtkstd::vector<vtkLidarPoint*> > OutputGrid;
> to
> vtkstd::vector<vtkstd::vector<vtkSmartPointer<vtkLidarPoint> > > OutputGrid;
> based on the same logic.
>
> I now get many less errors, but I still get a single
> Deleting unknown object: vtkObject
> every time the inner loop is entered.
>
> I'm assuming it is because the vtkRay is going out of scope at the end of
> the loop and I haven't made LidarPoint::SetRay accept a smart pointer?
>
> Is all of this the correct way to approach storing these objects?
>
> Thanks,
>
> David
>
> _______________________________________________
> 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
>
>
_______________________________________________
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

Re: Deleting unknown object: vtkObject - vector of pointers?

by David Doria-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Fri, Nov 6, 2009 at 10:27 AM, Bill Lorensen <bill.lorensen@...> wrote:
Does SetRay increment the reference count of the Ray? Using
this->Ray->Register(this)

I tried your example with two vtk objects and it worked as expected.

Bill

My member variable was not a smart pointer:
vtkRay* Ray;

Should it be?

My SetRay function was:
void vtkLidarPoint::SetRay(vtkRay* R)
{
  this->Ray->DeepCopy(R);
}

I got rid of the deep copy and changed it to accept a smart pointer and to register the pointer to the ray with the LidarPoint object. However, I still get the "Deleting unknown object" errors.

Here is the smallest extracted version that demonstrates the problem:
http://www.rpi.edu/~doriad/VTK_List/DeletingUnknownObject/

I actually think this is a very good example to demonstrate a lot of these smart pointer issues all in one shot. If you guys can help me try to get a handle on this I'll try to improve the smart pointer tutorial I started.

Thanks,

David

_______________________________________________
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

Re: Deleting unknown object: vtkObject - vector of pointers?

by Bill Lorensen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Your member variable does not have to be a smartpointer. If it is not,
you'll have to Register it on a Set. And UnRegister on destruction.
 If you use the vtkSetObject macro, it will do the proper
register/unregister. You will still have to UnRegister in the the
descturcotr if it is not null.


On Fri, Nov 6, 2009 at 11:04 AM, David Doria <daviddoria+vtk@...> wrote:

>
> On Fri, Nov 6, 2009 at 10:27 AM, Bill Lorensen <bill.lorensen@...>
> wrote:
>>
>> Does SetRay increment the reference count of the Ray? Using
>> this->Ray->Register(this)
>>
>> I tried your example with two vtk objects and it worked as expected.
>>
>> Bill
>
> My member variable was not a smart pointer:
> vtkRay* Ray;
>
> Should it be?
>
> My SetRay function was:
> void vtkLidarPoint::SetRay(vtkRay* R)
> {
>   this->Ray->DeepCopy(R);
> }
>
> I got rid of the deep copy and changed it to accept a smart pointer and to
> register the pointer to the ray with the LidarPoint object. However, I still
> get the "Deleting unknown object" errors.
>
> Here is the smallest extracted version that demonstrates the problem:
> http://www.rpi.edu/~doriad/VTK_List/DeletingUnknownObject/
>
> I actually think this is a very good example to demonstrate a lot of these
> smart pointer issues all in one shot. If you guys can help me try to get a
> handle on this I'll try to improve the smart pointer tutorial I started.
>
> Thanks,
>
> David
>
> _______________________________________________
> 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
>
>
_______________________________________________
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

Re: Deleting unknown object: vtkObject - vector of pointers?

by David Doria-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Fri, Nov 6, 2009 at 11:38 AM, Bill Lorensen <bill.lorensen@...> wrote:
Your member variable does not have to be a smartpointer. If it is not,
you'll have to Register it on a Set. And UnRegister on destruction.
 If you use the vtkSetObject macro, it will do the proper
register/unregister. You will still have to UnRegister in the the
descturcotr if it is not null.

Sorry to be such a pain about this...

If the member variable IS a smart pointer, then does it do the register/unregister automatically? Is it recommended to have member variables as smart pointers or not? If you DO make the member variable a smart pointer, you must break the "don't include any headers but your superclass" rule. Is that allowed in this case?

I switched to
vtkSetObjectMacro(Ray, vtkRay);
in an attempt to have it do the register/unregister automatically, but it simply segfaults when I call SetRay.

The updated and simplified files are here:
http://www.rpi.edu/~doriad/VTK_List/DeletingUnknownObject/

Thanks,

David

_______________________________________________
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

Re: Deleting unknown object: vtkObject - vector of pointers?

by Bill Lorensen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ray is not initialized in the constructor. Do a
Ray=NULL;

Don't forget to Delete() Ray in the destructor.


On Fri, Nov 6, 2009 at 12:10 PM, David Doria <daviddoria+vtk@...> wrote:

>
> On Fri, Nov 6, 2009 at 11:38 AM, Bill Lorensen <bill.lorensen@...>
> wrote:
>>
>> Your member variable does not have to be a smartpointer. If it is not,
>> you'll have to Register it on a Set. And UnRegister on destruction.
>>  If you use the vtkSetObject macro, it will do the proper
>> register/unregister. You will still have to UnRegister in the the
>> descturcotr if it is not null.
>
> Sorry to be such a pain about this...
>
> If the member variable IS a smart pointer, then does it do the
> register/unregister automatically? Is it recommended to have member
> variables as smart pointers or not? If you DO make the member variable a
> smart pointer, you must break the "don't include any headers but your
> superclass" rule. Is that allowed in this case?
>
> I switched to
> vtkSetObjectMacro(Ray, vtkRay);
> in an attempt to have it do the register/unregister automatically, but it
> simply segfaults when I call SetRay.
>
> The updated and simplified files are here:
> http://www.rpi.edu/~doriad/VTK_List/DeletingUnknownObject/
>
> Thanks,
>
> David
>
> _______________________________________________
> 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
>
>
_______________________________________________
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

Re: Deleting unknown object: vtkObject - vector of pointers?

by David Doria-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, Nov 6, 2009 at 12:26 PM, Bill Lorensen <bill.lorensen@...> wrote:
Ray is not initialized in the constructor. Do a
Ray=NULL;

Don't forget to Delete() Ray in the destructor.

Getting closer... it gets to the end of the program now without crashing, errors, or warnings - but when the program quits (I put a break point on the 'return 0' statement and the following errors happen when I step over return 0) I get "Deleting unknown object" errors. I'm assuming I am misinterpreting the reference count that happens when the objects get added to the stl container and when the container goes out of scope? Should the stl vector(s) be of smartpointers or standard pointers?

I added the following line at the end of the outer loop:

vtkstd::cout << "Ref after column added to grid: " << Grid[0][0]->GetReferenceCount() << vtkstd::endl;

The reference count is still 2... is this what we would expect? Shouldn't it be 3 here? Because then when the program terminates, the outer vector (1) deletes the inner vectors(2) which delete the LidarPoints (3) so the count should have been 3 to then go down to 0?

Here is the current version: http://rpi.edu/~doriad/VTK_List/DeletingUnknownObject/ (there are too many files to post the code directly to the list).

One day we'll get this resolved... haha.

Thanks,

David

_______________________________________________
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

Re: Deleting unknown object: vtkObject - vector of pointers?

by Bill Lorensen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I a ref of 2 is correct. The Grid[i]=Column should have no ref count
implication since Column is a vector.

BTW, the current code does not crash on my system.

Bill

On Tue, Nov 10, 2009 at 2:25 PM, David Doria <daviddoria+vtk@...> wrote:

> On Fri, Nov 6, 2009 at 12:26 PM, Bill Lorensen <bill.lorensen@...>
> wrote:
>>
>> Ray is not initialized in the constructor. Do a
>> Ray=NULL;
>>
>> Don't forget to Delete() Ray in the destructor.
>
> Getting closer... it gets to the end of the program now without crashing,
> errors, or warnings - but when the program quits (I put a break point on the
> 'return 0' statement and the following errors happen when I step over return
> 0) I get "Deleting unknown object" errors. I'm assuming I am misinterpreting
> the reference count that happens when the objects get added to the stl
> container and when the container goes out of scope? Should the stl vector(s)
> be of smartpointers or standard pointers?
>
> I added the following line at the end of the outer loop:
>
> vtkstd::cout << "Ref after column added to grid: " <<
> Grid[0][0]->GetReferenceCount() << vtkstd::endl;
>
> The reference count is still 2... is this what we would expect? Shouldn't it
> be 3 here? Because then when the program terminates, the outer vector (1)
> deletes the inner vectors(2) which delete the LidarPoints (3) so the count
> should have been 3 to then go down to 0?
>
> Here is the current version:
> http://rpi.edu/~doriad/VTK_List/DeletingUnknownObject/ (there are too many
> files to post the code directly to the list).
>
> One day we'll get this resolved... haha.
>
> Thanks,
>
> David
>
> _______________________________________________
> 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
>
>
_______________________________________________
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

Re: Deleting unknown object: vtkObject - vector of pointers?

by Bill Lorensen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Oops. I'm wrong about that.  Grid[i]=Column should copy all of
Column[i]'s smart pointers, thus affect ref count.

I need to study it further.

On Tue, Nov 10, 2009 at 3:20 PM, Bill Lorensen <bill.lorensen@...> wrote:

> I a ref of 2 is correct. The Grid[i]=Column should have no ref count
> implication since Column is a vector.
>
> BTW, the current code does not crash on my system.
>
> Bill
>
> On Tue, Nov 10, 2009 at 2:25 PM, David Doria <daviddoria+vtk@...> wrote:
>> On Fri, Nov 6, 2009 at 12:26 PM, Bill Lorensen <bill.lorensen@...>
>> wrote:
>>>
>>> Ray is not initialized in the constructor. Do a
>>> Ray=NULL;
>>>
>>> Don't forget to Delete() Ray in the destructor.
>>
>> Getting closer... it gets to the end of the program now without crashing,
>> errors, or warnings - but when the program quits (I put a break point on the
>> 'return 0' statement and the following errors happen when I step over return
>> 0) I get "Deleting unknown object" errors. I'm assuming I am misinterpreting
>> the reference count that happens when the objects get added to the stl
>> container and when the container goes out of scope? Should the stl vector(s)
>> be of smartpointers or standard pointers?
>>
>> I added the following line at the end of the outer loop:
>>
>> vtkstd::cout << "Ref after column added to grid: " <<
>> Grid[0][0]->GetReferenceCount() << vtkstd::endl;
>>
>> The reference count is still 2... is this what we would expect? Shouldn't it
>> be 3 here? Because then when the program terminates, the outer vector (1)
>> deletes the inner vectors(2) which delete the LidarPoints (3) so the count
>> should have been 3 to then go down to 0?
>>
>> Here is the current version:
>> http://rpi.edu/~doriad/VTK_List/DeletingUnknownObject/ (there are too many
>> files to post the code directly to the list).
>>
>> One day we'll get this resolved... haha.
>>
>> Thanks,
>>
>> David
>>
>> _______________________________________________
>> 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
>>
>>
>
_______________________________________________
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

Re: Deleting unknown object: vtkObject - vector of pointers?

by Bill Lorensen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

David,

Try the attached. I instrumented it with more output and ->DebugOn()
to show register/delete's. Everything looks fine to me.

Bill


On Tue, Nov 10, 2009 at 3:25 PM, Bill Lorensen <bill.lorensen@...> wrote:

> Oops. I'm wrong about that.  Grid[i]=Column should copy all of
> Column[i]'s smart pointers, thus affect ref count.
>
> I need to study it further.
>
> On Tue, Nov 10, 2009 at 3:20 PM, Bill Lorensen <bill.lorensen@...> wrote:
>> I a ref of 2 is correct. The Grid[i]=Column should have no ref count
>> implication since Column is a vector.
>>
>> BTW, the current code does not crash on my system.
>>
>> Bill
>>
>> On Tue, Nov 10, 2009 at 2:25 PM, David Doria <daviddoria+vtk@...> wrote:
>>> On Fri, Nov 6, 2009 at 12:26 PM, Bill Lorensen <bill.lorensen@...>
>>> wrote:
>>>>
>>>> Ray is not initialized in the constructor. Do a
>>>> Ray=NULL;
>>>>
>>>> Don't forget to Delete() Ray in the destructor.
>>>
>>> Getting closer... it gets to the end of the program now without crashing,
>>> errors, or warnings - but when the program quits (I put a break point on the
>>> 'return 0' statement and the following errors happen when I step over return
>>> 0) I get "Deleting unknown object" errors. I'm assuming I am misinterpreting
>>> the reference count that happens when the objects get added to the stl
>>> container and when the container goes out of scope? Should the stl vector(s)
>>> be of smartpointers or standard pointers?
>>>
>>> I added the following line at the end of the outer loop:
>>>
>>> vtkstd::cout << "Ref after column added to grid: " <<
>>> Grid[0][0]->GetReferenceCount() << vtkstd::endl;
>>>
>>> The reference count is still 2... is this what we would expect? Shouldn't it
>>> be 3 here? Because then when the program terminates, the outer vector (1)
>>> deletes the inner vectors(2) which delete the LidarPoints (3) so the count
>>> should have been 3 to then go down to 0?
>>>
>>> Here is the current version:
>>> http://rpi.edu/~doriad/VTK_List/DeletingUnknownObject/ (there are too many
>>> files to post the code directly to the list).
>>>
>>> One day we'll get this resolved... haha.
>>>
>>> Thanks,
>>>
>>> David
>>>
>>> _______________________________________________
>>> 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
>>>
>>>
>>
>

[DeletingUnknownObject.cxx]

#include "vtkLidarPoint.h"
#include "vtkRay.h"

#include "vtkSmartPointer.h"

#include <vector>

int main()
{
 
  vtkstd::vector<vtkstd::vector<vtkSmartPointer<vtkLidarPoint> > > Grid;
  Grid.resize(10);
 
  for(unsigned int i = 0; i < 2; i++)
    {
    vtkstd::vector<vtkSmartPointer<vtkLidarPoint> > Column;
    Column.clear();
    Column.resize(10);
 
    for(unsigned int j = 0; j < 2; j++)
      {
      vtkSmartPointer<vtkRay> Ray = vtkSmartPointer<vtkRay>::New();
     
      vtkSmartPointer<vtkLidarPoint> LidarPoint = vtkSmartPointer<vtkLidarPoint>::New();
      vtkstd::cout << "After LidarPoint::New(): " << LidarPoint->GetReferenceCount() << vtkstd::endl;
      LidarPoint->SetRay(Ray);
      LidarPoint->DebugOn();
      Column[j] = LidarPoint;
      vtkstd::cout << "After Column[" << j << "]=LidarPoint : " << LidarPoint->GetReferenceCount() << vtkstd::endl;
     
      }
    std::cout << "-------------- End Of for(j) ---------------" << std::endl;      
    vtkstd::cout << "After leave for(j) scope, Column[0]: " << Column[0]->GetReferenceCount() << vtkstd::endl;    
    vtkstd::cout << "After leave for(j) scope, Column[1]: " << Column[0]->GetReferenceCount() << vtkstd::endl;    
    Grid[i] = Column;
    vtkstd::cout << "After Grid[" << i << "]=Column[0]: " << Column[0]->GetReferenceCount() << vtkstd::endl;
    vtkstd::cout << "After Grid[" << i << "]=Column[1]: " << Column[1]->GetReferenceCount() << vtkstd::endl;
  }
  std::cout << "-------------- End Of for(i) ---------------" << std::endl;      
  vtkstd::cout << "After leave for(i) scope Grid[0][0]: " << Grid[0][0]->GetReferenceCount() << vtkstd::endl;
  vtkstd::cout << "After leave for(i) scope Grid[0][1]: " << Grid[0][1]->GetReferenceCount() << vtkstd::endl;
  vtkstd::cout << "After leave for(i) scope Grid[1][0]: " << Grid[1][0]->GetReferenceCount() << vtkstd::endl;
  vtkstd::cout << "After leave for(i) scope Grid[1][1]: " << Grid[1][1]->GetReferenceCount() << vtkstd::endl;
  std::cout << "-------------- End Of Program ---------------" << std::endl;  
  return 0;
}


_______________________________________________
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

Re: Deleting unknown object: vtkObject - vector of pointers?

by David Doria-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Nov 10, 2009 at 3:46 PM, Bill Lorensen <bill.lorensen@...> wrote:
> David,
>
> Try the attached. I instrumented it with more output and ->DebugOn()
> to show register/delete's. Everything looks fine to me.
>
> Bill

Here are my outputs with and without LidarPoint->DebugOn();

http://www.rpi.edu/~doriad/VTK_List/DeletingUnknownObject/nodebug.txt
http://www.rpi.edu/~doriad/VTK_List/DeletingUnknownObject/debug.txt

In both cases, I still get a bunch of "Generic Warning: Deleting
unknown object: vtkObject "

and also:

vtkDebugLeaks has detected LEAKS!
Class "vtkRay" has 4 instances still around.
Class "vtkLidarPoint" has 4 instances still around.

Do you not get those??

Thanks,

David
_______________________________________________
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

Re: Deleting unknown object: vtkObject - vector of pointers?

by Bill Lorensen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

David,

I do get the deleting unknown object message. It only appeared after
turning debug leaks on. I didn't notice it the first time. I think you
are OK.

Yes, I get the debug leaks, but I think they are bogus. Not sure why.
I ran valgrind with no leaks. Perhaps the std::vector is being deleted
after vtk does its debug leaks detection. but, from the debug output
you can see that the LidarPoint and Ray are being deleted.

I'll look into this problem with debug leaks.

You should proceed with the assumption that everything you are doing is correct.

Bill

On Tue, Nov 10, 2009 at 4:44 PM, David Doria <daviddoria+vtk@...> wrote:

> On Tue, Nov 10, 2009 at 3:46 PM, Bill Lorensen <bill.lorensen@...> wrote:
>> David,
>>
>> Try the attached. I instrumented it with more output and ->DebugOn()
>> to show register/delete's. Everything looks fine to me.
>>
>> Bill
>
> Here are my outputs with and without LidarPoint->DebugOn();
>
> http://www.rpi.edu/~doriad/VTK_List/DeletingUnknownObject/nodebug.txt
> http://www.rpi.edu/~doriad/VTK_List/DeletingUnknownObject/debug.txt
>
> In both cases, I still get a bunch of "Generic Warning: Deleting
> unknown object: vtkObject "
>
> and also:
>
> vtkDebugLeaks has detected LEAKS!
> Class "vtkRay" has 4 instances still around.
> Class "vtkLidarPoint" has 4 instances still around.
>
> Do you not get those??
>
> Thanks,
>
> David
> _______________________________________________
> 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
>
_______________________________________________
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

Re: Deleting unknown object: vtkObject - vector of pointers?

by Bill Lorensen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

David,

There is still an issue with your classes.

Stay tuned...

Bill

On Tue, Nov 10, 2009 at 4:59 PM, Bill Lorensen <bill.lorensen@...> wrote:

> David,
>
> I do get the deleting unknown object message. It only appeared after
> turning debug leaks on. I didn't notice it the first time. I think you
> are OK.
>
> Yes, I get the debug leaks, but I think they are bogus. Not sure why.
> I ran valgrind with no leaks. Perhaps the std::vector is being deleted
> after vtk does its debug leaks detection. but, from the debug output
> you can see that the LidarPoint and Ray are being deleted.
>
> I'll look into this problem with debug leaks.
>
> You should proceed with the assumption that everything you are doing is correct.
>
> Bill
>
> On Tue, Nov 10, 2009 at 4:44 PM, David Doria <daviddoria+vtk@...> wrote:
>> On Tue, Nov 10, 2009 at 3:46 PM, Bill Lorensen <bill.lorensen@...> wrote:
>>> David,
>>>
>>> Try the attached. I instrumented it with more output and ->DebugOn()
>>> to show register/delete's. Everything looks fine to me.
>>>
>>> Bill
>>
>> Here are my outputs with and without LidarPoint->DebugOn();
>>
>> http://www.rpi.edu/~doriad/VTK_List/DeletingUnknownObject/nodebug.txt
>> http://www.rpi.edu/~doriad/VTK_List/DeletingUnknownObject/debug.txt
>>
>> In both cases, I still get a bunch of "Generic Warning: Deleting
>> unknown object: vtkObject "
>>
>> and also:
>>
>> vtkDebugLeaks has detected LEAKS!
>> Class "vtkRay" has 4 instances still around.
>> Class "vtkLidarPoint" has 4 instances still around.
>>
>> Do you not get those??
>>
>> Thanks,
>>
>> David
>> _______________________________________________
>> 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
>>
>
_______________________________________________
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

Re: Deleting unknown object: vtkObject - vector of pointers?

by Bill Lorensen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

David,

Here are your files with my changes. The deleting unknown message was
because vtkDebugLeaks uses the vtk factory mechanism to keep track of
references. You need to add to your .cxx
vtkCxxRevisionMacro(vtkLidarPoint, "$Revision: 1.1 $");
and
vtkCxxRevisionMacro(vtkRay, "$Revision: 1.1 $");

and your .h

  vtkTypeRevisionMacro(vtkLidarPoint,vtkObject);
and
  vtkTypeRevisionMacro(vtkLidarRay,vtkObject);
to your classes.

I made some other small changes also.

Bill


On Tue, Nov 10, 2009 at 5:11 PM, Bill Lorensen <bill.lorensen@...> wrote:

> David,
>
> There is still an issue with your classes.
>
> Stay tuned...
>
> Bill
>
> On Tue, Nov 10, 2009 at 4:59 PM, Bill Lorensen <bill.lorensen@...> wrote:
>> David,
>>
>> I do get the deleting unknown object message. It only appeared after
>> turning debug leaks on. I didn't notice it the first time. I think you
>> are OK.
>>
>> Yes, I get the debug leaks, but I think they are bogus. Not sure why.
>> I ran valgrind with no leaks. Perhaps the std::vector is being deleted
>> after vtk does its debug leaks detection. but, from the debug output
>> you can see that the LidarPoint and Ray are being deleted.
>>
>> I'll look into this problem with debug leaks.
>>
>> You should proceed with the assumption that everything you are doing is correct.
>>
>> Bill
>>
>> On Tue, Nov 10, 2009 at 4:44 PM, David Doria <daviddoria+vtk@...> wrote:
>>> On Tue, Nov 10, 2009 at 3:46 PM, Bill Lorensen <bill.lorensen@...> wrote:
>>>> David,
>>>>
>>>> Try the attached. I instrumented it with more output and ->DebugOn()
>>>> to show register/delete's. Everything looks fine to me.
>>>>
>>>> Bill
>>>
>>> Here are my outputs with and without LidarPoint->DebugOn();
>>>
>>> http://www.rpi.edu/~doriad/VTK_List/DeletingUnknownObject/nodebug.txt
>>> http://www.rpi.edu/~doriad/VTK_List/DeletingUnknownObject/debug.txt
>>>
>>> In both cases, I still get a bunch of "Generic Warning: Deleting
>>> unknown object: vtkObject "
>>>
>>> and also:
>>>
>>> vtkDebugLeaks has detected LEAKS!
>>> Class "vtkRay" has 4 instances still around.
>>> Class "vtkLidarPoint" has 4 instances still around.
>>>
>>> Do you not get those??
>>>
>>> Thanks,
>>>
>>> David
>>> _______________________________________________
>>> 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
>>>
>>
>

[vtkLidarPoint.cxx]

#include "vtkLidarPoint.h"
#include "vtkRay.h"

#include "vtkSmartPointer.h"
#include "vtkObjectFactory.h" //for new() macro

vtkCxxRevisionMacro(vtkLidarPoint, "$Revision: 1.1 $");
vtkStandardNewMacro(vtkLidarPoint);

vtkLidarPoint::vtkLidarPoint()
{
  this->Ray = NULL;
}

vtkLidarPoint::~vtkLidarPoint()
{
  if (this->Ray)
    {
    this->Ray->Delete();
    }
}


void vtkLidarPoint::PrintSelf(vtkstd::ostream &os, vtkIndent indent)
{

}


[vtkLidarPoint.h]

#ifndef __vtkLidarPoint_h
#define __vtkLidarPoint_h

#include "vtkObject.h" //super class
#include "vtkRay.h"

#include "vtkSmartPointer.h"

class vtkLidarPoint : public vtkObject
{
public:
  static vtkLidarPoint *New();
  vtkTypeRevisionMacro(vtkLidarPoint,vtkObject);

  void PrintSelf(vtkstd::ostream &os, vtkIndent indent);

  vtkGetObjectMacro(Ray, vtkRay);
  vtkSetObjectMacro(Ray, vtkRay);
               
protected:

  vtkLidarPoint();
  ~vtkLidarPoint();
private:
  vtkLidarPoint(const vtkLidarPoint&); //not implemented
  void operator=(const vtkLidarPoint&); //not implemented
               
  vtkRay* Ray; //the direction and location from which the point was scanned
  //vtkSmartPointer<vtkRay> Ray;
               
};

#endif


[vtkRay.cxx]

#include "vtkRay.h"

#include "vtkObjectFactory.h" //for new() macro
#include "vtkMath.h"
#include "vtkTransform.h"


vtkCxxRevisionMacro(vtkRay, "$Revision: 1.1 $");
vtkStandardNewMacro(vtkRay);

vtkRay::vtkRay()
{
       
}

vtkRay::~vtkRay()
{
}

void vtkRay::PrintSelf(vtkstd::ostream &os, vtkIndent indent)
{
}


[vtkRay.h]

#ifndef __vtkRay_h
#define __vtkRay_h

class vtkTransform;
#include "vtkObject.h" //superclass

class vtkRay : public vtkObject
{
public:
  static vtkRay *New();
  vtkTypeRevisionMacro(vtkRay,vtkObject);
   
  void PrintSelf(vtkstd::ostream &os, vtkIndent indent);
               
protected:
  vtkRay();
  ~vtkRay();
private:
  vtkRay(const vtkRay&);  // Not implemented.
  void operator=(const vtkRay&);  // Not implemented.
 
};

#endif


_______________________________________________
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

Re: Deleting unknown object: vtkObject - vector of pointers?

by David Doria-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Nov 10, 2009 at 7:33 PM, Bill Lorensen <bill.lorensen@...> wrote:

> David,
>
> Here are your files with my changes. The deleting unknown message was
> because vtkDebugLeaks uses the vtk factory mechanism to keep track of
> references. You need to add to your .cxx
> vtkCxxRevisionMacro(vtkLidarPoint, "$Revision: 1.1 $");
> and
> vtkCxxRevisionMacro(vtkRay, "$Revision: 1.1 $");
>
> and your .h
>
>  vtkTypeRevisionMacro(vtkLidarPoint,vtkObject);
> and
>  vtkTypeRevisionMacro(vtkLidarRay,vtkObject);
> to your classes.
>
> I made some other small changes also.
>
> Bill

Excellent! No more errors/warning! I really appreciate you taking the
time to look into this.

I've tried to add these things to the little section I started:
http://www.vtk.org/Wiki/VTK#Developers_Corner

I'm not too sure about a lot of this wiki formatting - the section
looks pretty ugly. Does anyone know how to clean it up?

Thanks,

David
_______________________________________________
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

Parent Message unknown Re: Deleting unknown object: vtkObject - vector of pointers?

by David Doria-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Here are some updates (vtkCxxSetObjectMacro instead of
vtkSetObjectMacro) and the full example:

http://www.vtk.org/Wiki/Using_a_custom_class_member_variable

Thanks,

David
_______________________________________________
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