Hi jose

The problem is again the convertTo function.

there are two function for osgText::setFont :

void setFont (Font *font=0)
void setFont (const std::string &fontfile)

When you call type.getCompatibleMethod , osgIntrospection chack all function in the type and search
a function named "setFont".
The first found is "void setFont (Font *font=0)", osgIntrospection check the parameter compatibility
and try to convert std::string in osgTextfont.

in the tryConvertTo function

Value Value::tryConvertTo(const Type& outtype) const
{
 
// ** ########################## all this fail

   check_empty();

    if (_type == &outtype)
        return *this;

    if (_type->isConstPointer() && outtype.isNonConstPointer())
        return Value();

    // search custom converters
    ConverterList conv;
    if (Reflection::getConversionPath(*_type, outtype, conv))
    {
        std::auto_ptr<CompositeConverter> cvt(new CompositeConverter(conv));
        return cvt->convert(*this);
    }

    std::auto_ptr<ReaderWriter::Options> wopt;

    if (_type->isEnum() && ( outtype.getQualifiedName() == "int" || outtype.getQualifiedName() == "unsigned int"))
    {
        wopt.reset(new ReaderWriter::Options);
        wopt->setForceNumericOutput(true);
    }



// ** ##########################


// ** so try to do a string convertion

    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;
                if (dst_rw->readTextValue(ss, v))
                {
                    return v;
                }
            }
        }
    }

    return Value();
}


when try to do a string convertion from string to a osgText::Font pointer, the address give to the pointer is a bad address
If this address is use ... this is fatal ==>> SEGFAULT

So again this tryConvertTo do bad convertion ... cause by the read write convertion ...
I don't know how to fix this quickly.


but you can use the getMethod directly instead of use getCompatibleMethod

see your modified osgText_osgFont.cpp joint

David







// g++ osgText_setFont.cpp -W -Wall -losg -losgDB -losgIntrospection -Wl,-E

#include <osgIntrospection/Value>
#include <osgIntrospection/MethodInfo>
#include <osgIntrospection/variant_cast>
#include <osgIntrospection/Exceptions>
#include <osg/Referenced>
#include <osg/Group>
#include <osg/Drawable>
#include <osgDB/DynamicLibrary>
#include <osg/io_utils>

// borrowed from osgDB...
std::string createLibraryNameForWrapper(const std::string& ext)
{
#if defined(WIN32)
	// !! recheck evolving Cygwin DLL extension naming protocols !! NHV
	#ifdef __CYGWIN__
		return "cygosgwrapper_"+ext+".dll";
	#elif defined(__MINGW32__)
		return "libosgwrapper_"+ext+".dll";
	#else
		#ifdef _DEBUG
			return "osgwrapper_"+ext+"d.dll";
		#else
			return "osgwrapper_"+ext+".dll";
		#endif
	#endif
#elif macintosh
	return "osgwrapper_"+ext;
#elif defined(__hpux__)
	// why don't we use PLUGIN_EXT from the makefiles here?
	return "osgwrapper_"+ext+".sl";
#else
	return "osgwrapper_"+ext+".so";
#endif
}

osgDB::DynamicLibrary *load(const std::string &name)
{
	std::cout << "loading ... " << name << std::endl;
	return osgDB::DynamicLibrary::loadLibrary(
		createLibraryNameForWrapper(name)
	);
}

using namespace osgIntrospection;

int main() 
{
	osg::ref_ptr<osgDB::DynamicLibrary> osg_lib = load("osg");
	osg::ref_ptr<osgDB::DynamicLibrary> osgProducer_lib = load("osgText");

	// get the type
	std::cout << "find type osgText" << std::endl;
	const Type &type = Reflection::getType("osgText::Text");
	// create an instance
	std::cout << "find type osgText" << std::endl;
	Value text = type.createInstance();

	{ // Get the method (1)
		ValueList vl;
		vl.push_back(Value(std::string("The text")));

		std::cout << "get method setText" << std::endl;
		const MethodInfo *method = type.getCompatibleMethod("setText",vl, true);
		// call
		if (method)
		{
			method->invoke(text, vl);
			std::cout << "method executed" << std::endl;
		}
	}

	{ // Get the method (2)
		ValueList vl;
		vl.push_back(Value(std::string("fonts/arial.ttf")));

		std::cout << "get method setFont" << std::endl;
		
		osgIntrospection::ParameterInfoList pl;
		pl.push_back(new osgIntrospection::ParameterInfo("fontfile", typeof(std::string), osgIntrospection::ParameterInfo::IN));
		const MethodInfo *method = type.getMethod("setFont", pl, true);
      		
		//const MethodInfo *method = type.getCompatibleMethod("setFont", vl, true);

		// call
		if (method)
		{
			method->invoke(text, vl);
			std::cout << "method executed" << std::endl;
		}
	}

	return 0;
}
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

Reply via email to