After a long, frustrating afternoon of debugging, I have discovered something peculiar when trying to use a member function from a class with multiple bases as the functor for OSG::traverse(). I use OSG::osgTypedMethodFunctor1ObjPtrCPtrRef<...>() to create the functor that is handed off to OSG::traverse(), and up until now this has worked fine. When using Visual C++ 7.1 and a class that uses multiple inheritance, however, the OSG::FunctorBase<T>::_flags data member is trashed in the call to OSG::TypedStoredObjectFunctorBase<...>::setMethod() because the storage for the OSG::FunctorBase<T>::_data2 member is not large enough. Only four bytes are allocated, but eight are required.
The tricky thing is that this only appears to happen with Visual C++ 7.1 and a class that uses multiple inheritance. The attached program demonstrates the behavior. When compiled with Visual C++ 7.1, sizeof(&A::f) returns 4 whereas sizeof(&B::f) returns 8. With GCC 3.4 (tested on Fedora Core 3) and 4.0 (tested on Mac OS X 10.4.2), both return 8. It is probably possible for me to work around this behavior by passing an alternate type for the SizeTraitsT template parameter to OSG::FunctorBase<T>, though I have not tried doing so yet. I do not know if there is a solution that OpenSG can use to account for this case, but if I come up with one, I will submit a patch. -Patrick -- Patrick L. Hartling | VP Engineering, Infiscape Corp. PGP: http://tinyurl.com/2msw3 | http://www.infiscape.com/
#include <iostream>
class A
{
public:
void f()
{
}
};
class Base1
{
public:
};
class Base2
{
public:
};
class B : public Base1, public Base2
{
public:
void f()
{
}
};
int main()
{
std::cout << "sizeof(&A::f) == " << sizeof(&A::f) << std::endl;
std::cout << "sizeof(&B::f) == " << sizeof(&B::f) << std::endl;
return 0;
}
signature.asc
Description: OpenPGP digital signature
