Hi Vincent,

It's odd that your report that your get different instances each time.
 This suggest you've not implemeneted something correctly.  Most of
the OSG wouldn't work if there wasn't a single Registry so it does
work on the OSG side.

As a general note I have moved from using the
osgDB::Registry::instance approach to using something like:

osg::ref_ptr<MySingletonClass>& MySingletonClass::instance()
{
     static osg::ref_ptr<MySingletonClass>& s_mySingleton = new
MySingletonClass;
     return s_mySingleton;
}

This approach allows you to reset the singleton externally, so it's
not necessary to bool trick to get it to destruct.  With this little
tweak the implementation code becomes much cleaner.

Robert.


On Tue, May 19, 2009 at 12:25 PM, Vincent Bourdier
<vincent.bourd...@gmail.com> wrote:
> Hi Robert,
>
> The this I don't understand, is that I copy the code for my own registry,
> with exactly the same static implementation, but I get a new instance each
> time I call the instance(). The constructor is called and the adress
> changes...
>
> This is a part of the code :
>
>
>> Registry* Registry::instance(bool erase)
>> {
>>     static Registry* s_registry = new Registry;
>>
>>     if(erase)
>>     {
>>         s_registry->destruct();
>>         s_registry = NULL;
>>     }
>>
>>     return s_registry;
>> }
>>
>>
>> class DLL_EXPORT Registry
>> {
>>
>> public :
>>
>>     static Registry* instance(bool erase = false);
>> }
>
> I know static variable is the same for each instance, but how can it be true
> if the constructor is called each time ?
>
> So i can't see the problem, considering this is the copy/paste of the osg
> Registry code...
>
> Thanks.
>
> Regards,
>    Vincent.
>
> 2009/5/19 Robert Osfield <robert.osfi...@gmail.com>
>>
>> HI Vincent,
>>
>> Go have a look at the source code, it contains the single static
>> instance of the Registry, so the method only ever returns a single
>> Registry.   It would be worth your reading up about static variables
>> in C/C++ so you can understand how this stuff works, it really beyond
>> the scope of the OSG community to teach your this stuff.
>>
>> Robert.
>>
>> On Tue, May 19, 2009 at 11:54 AM, Vincent Bourdier
>> <vincent.bourd...@gmail.com> wrote:
>> > Hi all,
>> >
>> > A little new question about a c++ implementation of registry :
>> >
>> > The static method instance() return a new registry each time, so each
>> > call
>> > have a new instance, so how can the registry's class plugin list can be
>> > good
>> > ? any call to registry::instance()->addReaderWriter() add the the
>> > reader/Wirter in a new registry instance ... so how can it works
>> > correctly ?
>> >
>> > Thanks for you help.
>> >
>> > Regards,
>> >    Vincent.
>> >
>> > 2009/5/15 Vincent Bourdier <vincent.bourd...@gmail.com>
>> >>
>> >> Hi Art,
>> >>
>> >> I need to make these lib (dll/so) for linux and window at least, so I
>> >> need
>> >> common behavior.
>> >> I'm thinking a mix of the inheriting class and the osg plugin registry
>> >> behavior with the template static register method ... (note so
>> >> understandable I think) that is to say, may be a mix of all these way
>> >> can
>> >> bring me to a good solution ..
>> >>
>> >> Still here if you have suggestion or ideas
>> >>
>> >> Thanks every one, still good to have quality help here :-)
>> >>
>> >> Regards,
>> >>    Vincent.
>> >>
>> >> 2009/5/15 Art Tevs <arti_t...@yahoo.de>
>> >>>
>> >>> Hi Vincent,
>> >>>
>> >>>
>> >>>
>> >>> Vincent.B wrote:
>> >>> > Hi all,
>> >>> > If you need to load dynamically some DLL (as osg plugins) but theses
>> >>> > DLL have no similar I/O (so make each one inherit from a base class
>> >>> > have no
>> >>> > sense), how will you do ?
>> >>> >
>> >>> > I'm thinking in the calssical loadLibrary and getProcAdress for each
>> >>> > one, ... but if you know or think in an other solution, I would be
>> >>> > very
>> >>> > interested to hear it.
>> >>> >
>> >>>
>> >>>
>> >>> In windows world each dll can have an entry point. This is a C
>> >>> function,
>> >>> which will be called on dll loading. In unix world, I am not sure if
>> >>> there
>> >>> exists default entry point routines, I think yes, but I am not sure.
>> >>>
>> >>> cheers,
>> >>> art
>> >>>
>> >>> ------------------
>> >>> Read this topic online here:
>> >>> http://forum.openscenegraph.org/viewtopic.php?p=12249#12249
>> >>>
>> >>>
>> >>>
>> >>>
>> >>>
>> >>> _______________________________________________
>> >>> 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
>
>
> _______________________________________________
> 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

Reply via email to