Hi Chris,

In point 7, while you pass a raw Camera* to viewer.addSlave, you will probably find that it then stores that pointer in a osg::ref_ptr<osg::Camera>, which then increments the reference count. Therefore the reference count is decremented to 1 (not 0) at the end of the block.

Cheers,

Roland


--
ROLAND HILL
Director
Four Winds Technology Pty Ltd
Ph/Fax :  +61 (0)2 6366 9425
Mobile :  +61 (0)41 880 7472
[email protected]

Privacy and Confidentiality Notice
The information contained herein and any attachments are intended solely for the named recipients. It may contain privileged confidential information. If you are not an intended recipient, please delete the message and any attachments then notify the sender of miss-delivery. Any use or disclosure of the contents of either is unauthorised and may be unlawful. All liability for viruses are excluded to the fullest extent permitted by law.

On 05/09/13 10:29, Chris Stankevitz wrote:
Hello,

Can you please correct any wrong statements:

1. osg::ref_ptr increments the reference count when it is constructed
with a pointer.

2. osg::ref_ptr decrements the reference count when it is destroyed

3. osg::ref_ptr::get returns a raw pointer and does not increase the
reference count

4. when the reference count becomes zero, the underlying object is deleted

5. The following code appears in the osgscreencapture example (minus
some unrelated content):

    if (pbuffer.valid())
    {
        osg::ref_ptr<osg::Camera> camera = new osg::Camera;
        camera->setGraphicsContext(pbuffer.get());
        camera->setViewport(new osg::Viewport(0,0,width,height));
        GLenum buffer = pbuffer->getTraits()->doubleBuffer ? GL_BACK : GL_FRONT;
        camera->setDrawBuffer(buffer);
        camera->setReadBuffer(buffer);
        camera->setFinalDrawCallback(new WindowCaptureCallback(mode,
position, readBuffer));

        viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd());

        viewer.realize();
    }

6. The reference count of "camera" is incremented when it is constructed

7. The raw osg::Camera* is passed to viewer.addSlave, which does not
increment the reference count.

8. The osg::ref_ptr is not passed to anything

9. The reference count is not incremented anywhere else other than
during construction.

7. The reference count of "camera" is decremented when it reaches the
end of the if-block.

8. The reference count becomes zero at the end of the if-block

9. The camera object is destroyed at the end of the if-block

10. The raw camera pointer passed to viewer.addSlave is now invalid

11. The program should crash as soon as the viewer or anybody else
does anything with the camera

Thank you,

Chris
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to