Ogre::SharedPtr

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
Post Reply
aoikonom
Gnoblar
Posts: 23
Joined: Tue Aug 07, 2012 11:05 am

Ogre::SharedPtr

Post by aoikonom »

After upgrading from Ogre 1.8 to 1.9 I have some isues with Ogre::SharedPtr

The following piece of code used to work in 1.8

Code: Select all

	void OgreBuilder::setFogToMaterials(const Ogre::ColourValue &backgroundColour, const Ogre::Real &expDensity) {
		Ogre::MaterialManager::ResourceMapIterator it = Ogre::MaterialManager::getSingleton().getResourceIterator();
		while (it.hasMoreElements()) {
			Ogre::MaterialPtr mat = it.getNext();
			setFogToMaterial(mat, backgroundColour, expDensity);
		}
	}
But in 1.9 has a compiler error
error C2439: 'Ogre::SharedPtr<T>::pRep' : member could not be initialized \ogremain\include\ogresharedptr.h

The error occuss in the following code

Code: Select all

        SharedPtr(const SharedPtr<Y>& r)
            : pRep(r.getPointer())
            , pInfo(r.pInfo)
		{
            if (pRep) 
            {
                ++pInfo->useCount;
            }
        }
More info :
Cast from base to derived requires dynamic_cast or static_cast
1> \src\ogrebuilder.cpp(186) : see reference to function template instantiation 'Ogre::SharedPtr<T>::SharedPtr<Ogre::Resource>(const Ogre::SharedPtr<Ogre::Resource> &)' being compiled
1> with
1> [
1> T=Ogre::Material
1> ]

A simpler example that worked with 1.8 and fails with 1.9 is

Code: Select all

		Ogre::ResourcePtr resource;
		Ogre::MaterialPtr mat = resource;
It seems normal that I cannot convert a general ResourcePtr to a MaterialPtr, but what is the correct way to do the conversion?
scrawl
OGRE Expert User
OGRE Expert User
Posts: 1119
Joined: Sat Jan 01, 2011 7:57 pm
x 216

Re: Ogre::SharedPtr

Post by scrawl »

Code: Select all

      Ogre::ResourcePtr resource;
      Ogre::MaterialPtr mat = resource.static_cast<Ogre::Material>();
User avatar
Klaim
Old One
Posts: 2565
Joined: Sun Sep 11, 2005 1:04 am
Location: Paris, France
x 56
Contact:

Re: Ogre::SharedPtr

Post by Klaim »

Wasn't this cast function made unnecessary by recent improvements that should be in the RC2?
scrawl
OGRE Expert User
OGRE Expert User
Posts: 1119
Joined: Sat Jan 01, 2011 7:57 pm
x 216

Re: Ogre::SharedPtr

Post by scrawl »

Only for the getByName and create methods. ResourceIterator and a few others need casting.
aoikonom
Gnoblar
Posts: 23
Joined: Tue Aug 07, 2012 11:05 am

Re: Ogre::SharedPtr

Post by aoikonom »

Thanks scrawl, it worked
Post Reply