Just what may be a simple question but, while looking at the code for all the examples on Android, I noticed that vtkSmartPointer<> are not used at all in the examples. Is there any particular reason for that? I kind of got used to using them now and I was wondering if their use might lead to some issues or not?
For instance this is the struct used in VolumeRenderer:
struct userData
{
vtkRenderWindow *RenderWindow;
vtkRenderer *Renderer;
vtkAndroidRenderWindowInteractor *Interactor;
};
I just tried to re-implement this example using only smartpointers and I'm not running into any issue so far but I was wondering if that was a good idea or not. So this is what I have for the exact same structure:
struct userData
{
vtkSmartPointer<vtkRenderWindow> RenderWindow;
vtkSmartPointer<vtkRenderer> Renderer;
vtkSmartPointer<vtkAndroidRenderWindowInteractor> Interactor;
};
Thanks in advance.
There should be no issue at all in using vtkNew and/or vtkSmartPointer in your Android (or iOS) applications. In this case vtkNew looks more appropriate and maintains strong ownership, if you need to set these members externally for some reason then vtkSmartPointer would be the way to go.
For more information on which pointer class is appropriate I would recommend taking a look at this Source article
It mostly depends on the use-case of userData. Using vtkSmartPointer will increment the ref counter and therefore as long as userData is valid, you will have the other pointers valid too. However, in this case, you are storing references to render window objects which could go away because of some external event in that case you want to consider using vtkWeakPointer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With