User talk:ScratchMonkey: Difference between revisions

From KitwarePublic
Jump to navigationJump to search
No edit summary
No edit summary
Line 1: Line 1:
== Smart Pointers ==
I have a SmartPointer question for you (since you clearly know what is going on - thanks for adding to the tutorial!), but I'm not sure who you are! Can you send me your email address?
I have a SmartPointer question for you (since you clearly know what is going on - thanks for adding to the tutorial!), but I'm not sure who you are! Can you send me your email address?


Line 22: Line 23:
Thanks!
Thanks!
[[User:Daviddoria|daviddoria]] 02:00, 18 February 2010 (UTC)
[[User:Daviddoria|daviddoria]] 02:00, 18 February 2010 (UTC)
: The code looks correct, except that I'd pass the smart pointer by const reference. I suspect that won't fix the leak, though. I'll have to compile it later and see if I can figure out what's going wrong. [[User:ScratchMonkey|ScratchMonkey]] 02:32, 18 February 2010 (UTC)
<source lang="cpp">
    void SetRenderWindow(const vtkSmartPointer<vtkRenderWindow>& renderWindow) {this->RenderWindow = renderWindow;}
</source>

Revision as of 02:32, 18 February 2010

Smart Pointers

I have a SmartPointer question for you (since you clearly know what is going on - thanks for adding to the tutorial!), but I'm not sure who you are! Can you send me your email address?

daviddoria 00:50, 18 February 2010 (UTC)

I am trying to use a smart pointer for a member variable in this example: http://www.vtk.org/Wiki/VTK/Examples/RectangularButtonSource

In the MouseInteractorStyle class, I have:

<source lang="cpp">

   void SetRenderWindow(vtkSmartPointer<vtkRenderWindow> renderWindow) {this->RenderWindow = renderWindow;}
   //void SetRenderWindow(vtkRenderWindow* renderWindow) {this->RenderWindow = renderWindow;}
 private:
   vtkSmartPointer<vtkRenderWindow> RenderWindow;
   //vtkRenderWindow* RenderWindow;

</source>

If I use the smart pointer lines above (uncommented), debug leaks produces lots of messages. If I used the commented lines (non-smart pointer), it works fine. My thought was that in main, I have a vtkSmartPointer<vtkRenderWindow>, so I should continue to pass it around and store it as a smart pointer instead of a normal pointer. Is that not the correct thing to do?

Please take a look and let me know what you think.

Thanks! daviddoria 02:00, 18 February 2010 (UTC)

The code looks correct, except that I'd pass the smart pointer by const reference. I suspect that won't fix the leak, though. I'll have to compile it later and see if I can figure out what's going wrong. ScratchMonkey 02:32, 18 February 2010 (UTC)

<source lang="cpp">

   void SetRenderWindow(const vtkSmartPointer<vtkRenderWindow>& renderWindow) {this->RenderWindow = renderWindow;}

</source>