[C++-sig] Reference counted object return value policy
Jean-Sébastien Guay
jean-sebastien.guay at cm-labs.com
Wed Sep 24 04:09:10 CEST 2008
Hello again,
> So you're saying that exposing a thin wrapper that would return a
> ref_ptr<osg::Node> instead of osg::Node would work?
Continuing my (mostly bind) experimentation, I tried this:
osg::ref_ptr<osg::Node> readNodeFileWrapper(const std::string& filename)
{
return osg::ref_ptr<osg::Node>(osgDB::readNodeFile(filename));
}
BOOST_PYTHON_MODULE(_osgDB)
{
def("readNodeFile", readNodeFileWrapper);
}
That gets me a python.exe crash like the other experiments did, running
this way from the Python interpreter:
import osg
import osgDB
n = osgDB.readNodeFile("cow.osg")
Note that this works:
import osg
n = osg.Node()
so I assume my osg::Node wrapper is at least minimally functional...
Though I have no way of knowing if n is actually properly constructed or
if it's enclosed in a ref_ptr... My osg::Node wrapper starts like this,
for reference:
class_<Node, bases<Object>, ref_ptr<Node> >("Node")
/* ... */
;
Another weird thing, if I change the above thin wrapper to hard-code the
filename:
osg::ref_ptr<osg::Node> readNodeFileWrapper()
{
return osg::ref_ptr<osg::Node>(osgDB::readNodeFile("cow.osg"));
}
I don't get a crash, but OSG reports it can't load a file called "α"
(lowercase greek alpha), which seems to indicate that somewhere, the
string got mangled somehow? I don't understand how that can be since
it's a direct call into OSG from C++ code, nothing else involved.
Has anyone seen something like that before? Thanks in advance,
J-S
--
______________________________________________________
Jean-Sebastien Guay jean-sebastien.guay at cm-labs.com
http://www.cm-labs.com/
http://whitestar02.webhop.org/
More information about the Cplusplus-sig
mailing list