Commit fabe1d1d authored by hybrid's avatar hybrid

Merged fix by rogerborg for better programming style.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1039 dfc29bdd-3216-0410-991c-e03cc46cb475
parent c294fb0a
...@@ -194,30 +194,38 @@ int main() ...@@ -194,30 +194,38 @@ int main()
smgr->addCameraSceneNode(0, core::vector3df(0,-40,0), core::vector3df(0,0,0)); smgr->addCameraSceneNode(0, core::vector3df(0,-40,0), core::vector3df(0,0,0));
/* // Create our scene node. I don't check the result of calling new, as it
Create our scene node. Note that it is dropped (->drop()) instantly after // should throw an exception rather than returning 0 on failure.
we create it. This is possible because the scene manager now takes // Because the new node will create itself with a reference count of 1, and
care of it. This is not nessecary, it would also be possible to drop it // then will have another reference added by its parent scene node when it is
at the end of the program. // added to the scene, I need to drop my reference to it. Best practice is
*/ // to drop it only *after* I have finished using it, regardless of what the
// reference count of the object is after creation.
CSampleSceneNode *myNode = CSampleSceneNode *myNode =
new CSampleSceneNode(smgr->getRootSceneNode(), smgr, 666); new CSampleSceneNode(smgr->getRootSceneNode(), smgr, 666);
myNode->drop(); // To animate something in this boring scene consisting only of one tetraeder,
// and to show, that you now can use your scene node like any other scene
/* // node in the engine, we add an animator to the scene node, which rotates
To animate something in this boring scene consisting only of one tetraeder, // the node a little bit.
and to show, that you now can use your scene node like any other scene
node in the engine, we add an animator to the scene node, which rotates
the node a little bit.
*/
scene::ISceneNodeAnimator* anim = scene::ISceneNodeAnimator* anim =
smgr->createRotationAnimator(core::vector3df(0.8f, 0, 0.8f)); smgr->createRotationAnimator(core::vector3df(0.8f, 0, 0.8f));
// createRotationAnimator() could return 0, so should be checked
if(anim)
{
myNode->addAnimator(anim); myNode->addAnimator(anim);
// I'm done referring to anim, so must drop this reference now because it
// was produced by a createFoo() function.
anim->drop(); anim->drop();
anim = 0; // As I shouldn't refer to it again, ensure that I can't
}
// I'm done with my CSampleSceneNode object, and so must drop my reference
myNode->drop();
myNode = 0; // As I shouldn't refer to it again, ensure that I can't
/* /*
Now draw everything and finish. Now draw everything and finish.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment