aboutsummaryrefslogtreecommitdiff
path: root/tests/removeCustomAnimator.cpp
blob: cc4c142c4b3be807a24e01b7aba18c1646a79264 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (C) 2008-2011 Colin MacDonald
// No rights reserved: this software is in the public domain.

#include "testUtils.h"

using namespace irr;
using namespace core;
using namespace scene;

class CustomAnimator : public ISceneNodeAnimator
{
	void animateNode(ISceneNode* node, u32 timeMs)
	{
		// Check that I can remove myself from my node durings its animateNode() loop.
		node->removeAnimator(this);
	}

	ISceneNodeAnimator* createClone(ISceneNode* node, ISceneManager* newManager=0) { return 0 ; }
};


/** Test that a custom animator can remove itself cleanly from an ISceneNode during its
 *  own animateNode() loop. 
 * http://irrlicht.sourceforge.net/phpBB2/viewtopic.php?t=32271 */
bool removeCustomAnimator(void)
{
	IrrlichtDevice * device = irr::createDevice(video::EDT_NULL, dimension2du(160, 120));
	assert(device);
	if(!device)
		return false;

	ISceneManager * smgr = device->getSceneManager();

	ISceneNode * node = smgr->addEmptySceneNode();
	CustomAnimator * instantlyElapsing1 = new CustomAnimator();
	CustomAnimator * instantlyElapsing2 = new CustomAnimator();
	node->addAnimator(instantlyElapsing1);
	node->addAnimator(instantlyElapsing2);

	// This should result in both custom animators being removed and
	// deleted cleanly, without a crash.
	node->OnAnimate(0);
	
	device->closeDevice();
	device->run();
	device->drop();

	// If we didn't crash, then the test passed.
	return true;
}