I just add ReinterpretCastConverter in the Reflector to convert void* in T* and T* in void*
files joint :
OpenSceneGraph/include/osgIntrospection/Reflector // modified file
OpenSceneGraph/src/osgIntrospection/Reflector.cpp // modified file
"
"
Found in the join file the fix for the bug found by Rafa.
Problem :
osgIntrospection::Value grp(new osg::Group);
osgIntrospection::ValueList vlcall;
vlcall.push_back(osgIntrospection::Value("toto"));
const osgIntrospection::MethodInfo *m =
grp->getType.getCompatibleMethod("setName", vlcall, true);
if (m)
{
m->invoke(grp, vlcall); // ** SEGFAULT here
}
Algorithm explanation :
The "invoke" method try to convert "grp", which reflect an
"osg::Group*", in a
"osgIntrospection::Value", which reflect a "osg::Node*".
This because
the "setName(const char *)" method found by
"grp->getType.getCompatibleMethod"
is an "osg::Object" type method.
When osgIntrospection do this conversion it try :
- to found a "osgIntrospection::Converter" to convert
from "osg::Group*" to "osg::Node*"
- to found a chain of "osgIntrospection::Converter" to convert
from "osg::Group*" to "one or many type" to "osg::Node*"
- to converte an Enum to int or unsigned int
- to convert the value in its "value string representation",
then converte this string in the destination value
Else it throw a "TypeConversionException".
Bug :
1)
When osgIntrospection try to found a chain of
"osgIntrospection::Converter"
It could do any downcast or (Type to SuperType) or upcast
(SuperType to Type).
This mean the the chain could be :
osg::Group to osg::Transform to osg::Camera to
osg::CullSettings to osg::CullStack to
osg::CollectOccludersVisitor to
osg::NodeVisitor to osg::Referenced to osg::Object
During the convertion with this chain, A METTRE failed and
the pointer in
"grp" is set NULL. But the "grp" is always a valid
"osgIntrospection::Value"
and so, osgIntrospection accept the conversion. Then it try
to use this pointer
to call the "setName" function. And Bing SEGFAULT.
2)
In "bool Reflection::accum_conv_path( ... )"
the convection path isn't accumulate in the recursive loop.
this cause multi request of a conversion path, and a
slowdown in the
conversion algorithm.
3)
Use of the last conversion way in a conversion from
pointer to pointer
this mean you can do this :
"osg::Node*" to " value string representation" to "osg::Material*"
What a bad thing !!!
Solution :
1)
Introduce the concept of dynamic_cast and static_cast.
now, to do a conversion, osgIntrospection does this :
- to found a "osgIntrospection::Converter" to convert
from "osg::Group*" to "osg::Node*"
- to found a chain of "osgIntrospection::Converter" to convert
from "osg::Group*" to "one or many type" to "osg::Node*"
only with static_cast, downcast (Type to SuperType)
- to found, if the source and the destination are two pointer,
a chain of "osgIntrospection::Converter" to convert
from "osg::Group*" to "one or many type" to "osg::Node*"
only with dynamic_cast, upcast (SuperType to Type)
- to convert an Enum to int or to unsigned int
- to convert the value in its "value string representation",
then convert this string in the destination value
Else it throw a "TypeConversionException".
Add the "enum CastType" to distinguish the static_cast or
dynamic_cast converter.
Add file OpenSceneGraph/include/osgIntrospection/CastType
2)
add a line to accumulate converter in converter Path.
3)
add a line to check if source and destination are pointer.
"
the declaring file for a given type via the new member function
osgIntrospection::Type::getDeclaringFile. This information is useful
in order to know what header to include when auto-generating wrappers
for a given type.
During the C# wrapper generator development I've been keeping the
declaring file configuration state up-to-date manually with changes
to OSG, and it's proven to require substantial effort. So it would be
extremely valuable to get this change in before 2.0 to reduce maintenance
during the lifetime of the release. It'll also be equally useful to
others looking to create wrapper generators using osgIntrospection.
This is a fairly simple change and was tested with a fresh rebuild of the
entire suite of osgWrapper libraries, so it should be relatively low risk
(fingers crossed)."
Lost the functionality to find the real type pointed by a pointer.
Ex: a osg::Node pointer point on a osg::Group, if I look for information
on the pointer type, the introspection say it is a "osg::Node*".
But if I want information on the pointed type,
the introspection must return the "osg::Group".
This bug come from the osgIntrospection::Value::Ptr_instance_box::ptype() function.
In the original version, this function use the member "Instance_base *inst_"
like this :
typeof(*static_cast<Instance<T> *>(inst_)->_data)
But in the new version, this function use the template argument "T":
typeof(typename remove_pointer<T>::type)
This is a good meta-programming use, but here we need a dynamic request.
Moreover the "typeof" macro define in "Reflection" header accept only a type in parameter with the new version.
fix:
Add the macro "typeofvalue" in "Reflection" header which accept a value or a type in parameter.
Restore original code in osgIntrospection::Value::Ptr_instance_box::ptype() function.
"
"
the main problem is the wrapper generation:
The PropertyInfo class use MethodInfo class to access to the value.
When the property are define with the I_Property* macro,
the MethodInfo use by the property to have access to the value
are instancied in the I_Property* macro, but there
are already instantied by the I_Method* macro before
secondary problem:
- the function used by the property could no be customized
in the genwrapper.conf file
- an array property can't insert a value
- the std::map reflector (and indexedProperty in general) haven't remove method
- about the help in wrapper ... why not ...
solution :
To use the function define by the I_Method, I add a MethodInfo variable in the I_Method0 macro
old macro :
#define I_Method0(ret, fn) (\
params.clear(),\
addMethod(new osgIntrospection::TypedMethodIn
fo0<reflected_type, ret >(qualifyName(#fn), &reflected_type::fn, params)))
new macro :
#define I_Method0(ret, fn, signature, briefHelp, detailedHelp) \
params.clear(); \
osgIntrospection::MethodInfo* signature = addMethod(new osgIntrospection::TypedMethodInfo0<reflected_type, ret >(qualifyName(#fn), &reflected_type::fn, params, briefHelp, detailedHelp)); sink(signature)
the osgIntrospection::MethodInfo* signature is used by the I_Property macro to define the MethodInfo that it use
so for I_Property macro :
old macro :
#define I_PropertyWithReturnType(t, n, r) \
cap=addProperty(new osgIntrospection::PropertyInfo(osgIntrospection::Reflection::getType(typeid(reflected_type)), osgIntrospection::Reflection::getType(typeid(t)), #n, \
I_Method0(t, get##n), \
I_Method1(r, set##n, IN, t, value)))
new macro:
#define I_SimpleProperty(t, n, get, set) \
get, \
set))
The genwrapper has been modified in this way.
The method signature is define by the prototype of the method
For example, the "const char* libraryName();" have "__C5_char_P1__libraryName" for signature
solution for secondary problem:
The genwrapper accept new tokens in the configuration to custumize the property.
The new PropertyInserter and the CustomPropertyInsertAttribute class has been defined
The PropertyRemover has been added to the StdMapReflector
The _briefHelp and _detailedHelp variable has been added in PropertyInfo, MethodInfo and ContructorInfo class
modification:
I have modify the genwrapper files
Configuration.cpp Configuration.h add some tokens to custumize the property
Doxyfile.template add the comment in the output xml
genwrapper.conf customize some property in osg::Geometry
RegistryBuilder.h RegistryBuilder.cpp add the process_help function (to extract help from xml)
TypeRegister.cpp TypeRegister.h optimize the property detection
TypeDesc.h TypeDesc.cpp modify FunctionDesc and PropertyDesc
WrapperGenerator.h WrapperGenerator.cpp modify the output
I also modify the fallowing osgIntrospection files:
include/osgIntrospection/Attributes add the PropertyInserter and the CustomPropertyInsertAttribute class
include/osgIntrospection/ConstructorInfo add the _briefHelp and _detailedHelp variable in the ConstructorInfo class
add access function for the two new variables (_briefHelp and _detailedHelp)
modify the constructor to define the two new variables (_briefHelp and _detailedHelp)
include/osgIntrospection/MethodInfo add the _briefHelp and _detailedHelp variable in the MethodInfo class
add access function for the two new variables (_briefHelp and _detailedHelp)
modify the constructor to define the two new variables (_briefHelp and _detailedHelp)
include/osgIntrospection/PropertyInfo add the _briefHelp and _detailedHelp variable in the PropertyInfo class
add access function for the two new variables (_briefHelp and _detailedHelp)
modify the constructor to define the two new variables (_briefHelp and _detailedHelp)
include/osgIntrospection/ReflectionMacro remove unused I_Property* macro
modify all I_Method macro to accept the help string
modify all I_Method macro to define a MethodInfo signature
include/osgIntrospection/Reflector add the PropertyInserter in StdVectorReflector and StdListReflector
add the PropertyRemover in the StdMapReflector
include/osgIntrospection/StaticMethodInfo modify all StaticMethodInfo* to accept the help in parameter
include/osgIntrospection/TypedMethodInfo modify all TypedMethodInfo* to accept the help in parameter
include/osgIntrospection/TypedConstructorInfo modify all TypedConstructorInfo* to accept the help in parameter
include/osgIntrospection/Type add the _briefHelp and _detailedHelp variable in the Type class
"
"bug fix to reflect the wchar_t in Value and Value.cpp I add the toWString() function.
in Type and Type.cpp I just add two function to get a map of propertyList and a map of methodList
i need this map in my editor a i think it's could be util to put this functionnality in osgIntrospection,
1. type converters created automatically by the I_BaseType macro use
static_cast<> even for base-to-derived conversions. dynamic_cast<> should be
used instead.
2. as a consequence of the above fix, I_BaseType must now differentiate
between polymorphic and non-polymorphic base classes, because the latter
can't be dynamic_cast'd to derived classes. Some template magic (see
is_polymorphic<> in ReflectionMacros) is used to detect polymorphism at
compile time (I'm NOT sure it works on all platforms as it's partly
implementation-dependent. Please test!).
3. predefined custom property getters/setters/counters/etc. (as those
defined for STL containers) only work on Value objects that contain
non-pointer instances. This was an unwanted restriction that no longer
exists.
Wrappers will need to be recompiled. This is a good time to give them a
fresh update with genwrapper.
NOTE: fix#1 should get rid of those crashes and strange behaviours that
some users noticed while using osgIntrospection through osgTcl or in their
own code."