removeCustomAnimator.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright (C) 2008-2012 Colin MacDonald
  2. // No rights reserved: this software is in the public domain.
  3. #include "testUtils.h"
  4. using namespace irr;
  5. using namespace core;
  6. using namespace scene;
  7. class CustomAnimator : public ISceneNodeAnimator
  8. {
  9. void animateNode(ISceneNode* node, u32 timeMs)
  10. {
  11. // Check that I can remove myself from my node durings its animateNode() loop.
  12. node->removeAnimator(this);
  13. }
  14. ISceneNodeAnimator* createClone(ISceneNode* node, ISceneManager* newManager=0) { return 0 ; }
  15. };
  16. /** Test that a custom animator can remove itself cleanly from an ISceneNode during its
  17. * own animateNode() loop.
  18. * http://irrlicht.sourceforge.net/phpBB2/viewtopic.php?t=32271 */
  19. bool removeCustomAnimator(void)
  20. {
  21. IrrlichtDevice * device = irr::createDevice(video::EDT_NULL, dimension2du(160, 120));
  22. assert_log(device);
  23. if(!device)
  24. return false;
  25. ISceneManager * smgr = device->getSceneManager();
  26. ISceneNode * node = smgr->addEmptySceneNode();
  27. CustomAnimator * instantlyElapsing1 = new CustomAnimator();
  28. CustomAnimator * instantlyElapsing2 = new CustomAnimator();
  29. node->addAnimator(instantlyElapsing1);
  30. node->addAnimator(instantlyElapsing2);
  31. // This should result in both custom animators being removed and
  32. // deleted cleanly, without a crash.
  33. node->OnAnimate(0);
  34. device->closeDevice();
  35. device->run();
  36. device->drop();
  37. // If we didn't crash, then the test passed.
  38. return true;
  39. }