Re: [osg-users] Vec3Array instantiation

2016-04-07 Thread Filip Arlet
Hi,

Simply you can't do it. They are completle different smart pointers. shared_ptr 
has outside reference counting and ref_ptr has inside reference counting in 
osg::Referenced class. Basically you would need to call ref() everytime you 
create or copy shared_ptr and call unref() (unref_nodelete()) every time 
shared_ptr is destroyed. And use custom deleter (void 
custom_del(osg::Referenced* referenced) { referenced->unref(); ??}. But I dont 
think it will work. Your main problem is that those pointer types have no idea 
about each other. If your osg::Referenced ref counter drop to zero, your object 
gets deleted, but you can still have some shared_ptr around with bad data and 
vice versa, if your shared_ptr gets deleted, you can still have some ref_ptrs 
in osg classes.

But what I can recommend is this:
subclass osg::Drawable (or Geometry) if you look into osg/Geometry.cpp all 
functions that accepts arrays (drawImplementation, acceptPrimitiveFunctor, 
computeBounds, ... ) can use float* values  ...basically glVertexPointer doesnt 
care about your array type. You can create your custom class without Array 
Pointers, but with your own shared_ptrs.


Code:

class MyDrawable : public osg::Drawable
{
MyDrawable(std::shared_ptr arr) :
m_arr(arr)
{}
private:
std::shared_ptr m_arr;
}




Then you would have to look at each virtual function of osg::Drawable and 
implement it (its not so hard, just take a look at osg::Geometry, how its done 
- but instead of osg::VecArrays you will use your Array). Of course you dont 
need to implement all of them.

Cheers,
Filip

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





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Vec3Array instantiation

2016-04-07 Thread Christian Buchner
the osg::ref_ptr<> could be wrapped into a smart pointer, right? But what's
the point ;)

2016-04-07 10:33 GMT+02:00 Sebastian Messerschmidt <
sebastian.messerschm...@gmx.de>:

> Hi Vincent,
>
>> 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 test2(new osg::Vec3Array()); // error due
>> to pointer releasing
>>
>>
>>
>>
>> Code:
>> osg::Vec3Array test; // not work
>>
>>
>>
>>
>> Code:
>> osg::ref_ptr 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.
>>
> First of all, the osg will manage the array fine when you keep it in a
> drawable, so there should no need to use your own management. If you need
> to hold it outside, simply use the ref_ptr. the ref_ptr is basically an
> smart-pointer for osg::Object derived objects.
> The reason the destructor is private is to prevent stack-instances of the
> type and to disallow use patterns like yours.
> If i remember correctly there was some guide on this in the wiki/trac.
>
>
> Do you have an idea to use C+11 smart pointer instead of osg one?
>
> Simply don't. It would not solve a single problem and would create
> pitfalls.
> Use the osg::ref_ptr if you need to keep an object (it acts as a "shared
> ptr"). If you need a week smart ptr you can use observer pointer.
>
>
> Cheers
> Sebastian
>
>
>
>> Thank you!
>>
>> Cheers,
>> Vincent
>>
>> --
>> Read this topic online here:
>> http://forum.openscenegraph.org/viewtopic.php?p=66760#66760
>>
>>
>>
>>
>>
>> ___
>> osg-users mailing list
>> osg-users@lists.openscenegraph.org
>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>>
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Vec3Array instantiation

2016-04-07 Thread Sebastian Messerschmidt

Hi Vincent,

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 test2(new osg::Vec3Array()); // error due to 
pointer releasing




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




Code:
osg::ref_ptr 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.
First of all, the osg will manage the array fine when you keep it in a 
drawable, so there should no need to use your own management. If you 
need to hold it outside, simply use the ref_ptr. the ref_ptr is 
basically an smart-pointer for osg::Object derived objects.
The reason the destructor is private is to prevent stack-instances of 
the type and to disallow use patterns like yours.

If i remember correctly there was some guide on this in the wiki/trac.


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

Simply don't. It would not solve a single problem and would create 
pitfalls.
Use the osg::ref_ptr if you need to keep an object (it acts as a "shared 
ptr"). If you need a week smart ptr you can use observer pointer.



Cheers
Sebastian



Thank you!

Cheers,
Vincent

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





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Vec3Array instantiation

2016-04-07 Thread Vincent Majorczyk
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 test2(new osg::Vec3Array()); // error due to 
pointer releasing




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




Code:
osg::ref_ptr 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





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org