[osg-users] Vec3Array instantiation

Vincent Majorczyk osgforum at tevs.eu
Thu Apr 7 00:49:11 PDT 2016


Hello

I'm trying to use osg:Vec3Array with a c++11 smart pointer instead of osg smart pointer. I aim to join two APIs: osg and another one using C++11 smart pointer. Apparently, this is a destructor problem: ~TemplateArray<>() is private, so an explicit delete doesn't work. I have test many cases to understand the problem. 


Code:
osg::Vec3Array * test = new osg::Vec3Array();
delete test; // error here




Code:
std::shared_ptr<osg::Vec3Array> test2(new osg::Vec3Array()); // error due to pointer releasing




Code:
osg::Vec3Array test; // not work




Code:
osg::ref_ptr<osg::Vec3Array> test3 = new osg::Vec3Array(); // this work fine.



So there are few solutions to use the Vec3Array: use osg smart pointer. What is the reason the destructor is protected even through the method is empty? Maybe to force developers to use smart pointers but I'm constrained to use c++11 smart pointer due to the second api. I think the only way, is to create a C++11 smart pointer templated by osg smart pointer or a class which contains the osg smart pointer.

Do you have an idea to use C+11 smart pointer instead of osg one?

Thank you!

Cheers,
Vincent

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=66760#66760








More information about the osg-users mailing list