Happy to see you again on the mailing list. osgIntrospection needs its author to evolved correctly.
2006/10/23, Marco Jez <
[EMAIL PROTECTED]>:
Value v;
I don't see anything to avoid convertion from string to pointer.
Actually, if you try to convert a text string to any pointer type the
conversion will fail and Value::tryConvertTo() will return an empty Value,
which is the correct behaviour:
Value v;
if (dst_rw->readTextValue(ss, v))
{
return v;
}
the return statement is executed only if the read-from-stream operation
succeeds. If it fails, the function reaches its end and an empty Value is
returned.
[note to self: what happens if the string represents a valid number?
hmmmm.... ]
I don't see anything to avoid convertion from string to pointer.
the std::istream& ReaderWriter::readTextValue(std::istream &, Value& v, const Options* = 0)
function return a reference and so always return true.
Back on the bug:
Perhaps i do a too little explication for the bug. (and perhaps my english is not really good)
get a look in the code:
Value Value::tryConvertTo(const Type& outtype) const
{
...
const ReaderWriter* src_rw = _type->getReaderWriter();
if (src_rw)
{
const ReaderWriter* dst_rw = outtype.getReaderWriter();
if (dst_rw)
{
std::stringstream ss;
if (src_rw->writeTextValue(ss, *this, wopt.get()))
{
Value v;
// ** ##### all work fine at this point, see the next call in detail
if (dst_rw->readTextValue(ss, v))
{
return v;
}
}
}
}
}
in this call, the parameter "is" contain "fonts/arial.ttf"
virtual std::istream &readTextValue(std::istream &is, Value& v, const Options* = 0) const
{
void *ptr;
is >> ptr;
// ** ###########after this, ptr = 0xf;
v = Value(T(ptr));
return is;
}
so the Value constructor is call ...
template<typename T> Value::Value(T *v)
{
_inbox = new Ptr_instance_box<T *>(v);
_type = _inbox->type();
// ** ##### all work fine at this point, see the next call in detail
_ptype = _inbox->ptype();
}
and Ptr_instance_box<T *>::ptype() is call
virtual const Type* ptype() const
{
if (!static_cast<Instance<T> *>(inst_)->_data) return 0;
return &typeof(*static_cast<Instance<T> *>(inst_)->_data);
}
and here, static_cast<Instance<T> *>(inst_)->_data is not null and is equal to "0xf"
this cause the call of typeof(*static_cast<Instance<T> *>(inst_)->_data)
#define typeof(expr) osgIntrospection::Reflection::getType(typeid(expr))
and the typeid of the deferenced pointer cause the SEGFAULT.
The test that you want to do
_ptype = v ? _inbox->ptype() : 0;
is already done in :
virtual const Type* ptype() const
{
if (!static_cast<Instance<T> *>(inst_)->_data) return 0;
return &typeof(*static_cast<Instance<T> *>(inst_)->_data);
}
"inst_->_data" is equal to "v" after inst_ initialisation.
and probably not fix the bug.
Best Regards,
David
_______________________________________________ osg-users mailing list [email protected] http://openscenegraph.net/mailman/listinfo/osg-users http://www.openscenegraph.org/
