Problem by with core::list

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
JoeMill

Problem by with core::list

Post by JoeMill »

Hi,

i try to make a simple LOD - System for a small Tech Demo using Irrlicht and i run into a huge problem.

I defined 3 LOD-Stages and to achieve the goal, i have to iterate through the SceneNodes and set the Visible-Flag to true or false. So i let me gave the RootSceneNode from the SceneManager, but when the iteration on one Level comes to an end, the destructor off the core::list is called and i don't know why :( . So i tried to hold the start of the SceneNodes, which are interesting for me in my program, but this didn't helped.
When I run the program, i get a "Debug Assertion Failed", by Debugging the prog i come to the following code, which throws this Assertion

Code: Select all

/*
* If this ASSERT fails, a bad pointer has been passed in. It may be
* totally bogus, or it may have been allocated from another heap.
* The pointer MUST come from the 'local' heap.
*/
_ASSERTE(_CrtIsValidHeapPointer(pUserData));
here the Part of my Code which causes the trouble:

Code: Select all

bool COrionProjekt::setLOD(LevelOfDetail newLevel) {

	// still to complete
	if (newLevel == m_detail)
		return false;

	m_detail = newLevel;

	if (!m_galaxyRootSceneNode)
		return false;
	

	// When I created the SceneNodes, from my Galaxy Data, i created one RootNode for the hole Galaxy. It is an EmptySceneNode, but this problem also accurs, if i get the RootSceneNode from the SceneManager.
	core::list<scene::ISceneNode*> galChildList = m_galaxyRootSceneNode->getChildren();
	core::list<scene::ISceneNode*>::Iterator galChildIt = galChildList.begin();

	for (; galChildIt != galChildList.end(); ++galChildIt) {
		// Did we found a System?
		if ((*galChildIt)->getID() & EGOT_SYSTEM) {

			// GalaxyStructure:
			//										m_galaxyRootSceneNode---------------------------------------+
			//												|                                           ....    |
			//                   +----------------------SystemNode1-------------------------+           ....  SystemNodeX
			//                   |                                                          |                   ...
			//   +----------StarRootNode--------+                    +----------+--- PlanetRootNode
			//   |               |              |                    |    ...   |
			// Star(3D-Model)   StarLight    StarCorona           Planet1 ... PlanetX
			//                                                       |
			//                                                 +-----+------+
			//                                                 |    ...     |
			//                                               Moon1  ...   MoonX

			switch (m_detail) {
				
				// In the Galaxyview, all Lights of the Stars have to been turned off,
				// because i think DirectX supports only 8 LightSources in 1 Scene.
				// Also all Planets must be invisible, because there are just too many of them.

				case ELOD_GALAXY : {
					// iterate through the Childs of this System
					// search for the StarLight and the PlanetRootNode, because we want to turn them invisible
					core::list<scene::ISceneNode*> sysChildlist = (*galChildIt)->getChildren();
					core::list<scene::ISceneNode*>::Iterator sysChildIt = sysChildlist.begin();

					for (; sysChildIt != sysChildlist.end(); ++sysChildIt) {
						if ((*sysChildIt)->getID() & ERNT_STAR) {
							// turn the light off, by calling a function,
							// which iterate through the Childs of the StarRootNode
							// and if the StarLightNode is found the visible flag is set to false
							setStarLight((*sysChildIt), false);
						
						} else if ((*sysChildIt)->getID() & ERNT_PLANET) {
							// Because if a Node is invisible, his Childs are also Invisible,
							// we need only make the PlanetRootNode invisble
							(*sysChildIt)->setVisible(false);
						}
					}// for SystemChilds
					break;
				} // case

....
and the setStarLight-function:

Code: Select all

void COrionProjekt::setStarLight(scene::ISceneNode* node, bool state) {
	// Zum Sternenlicht durchhangeln
	core::list<scene::ISceneNode*> list = node->getChildren();
	core::list<scene::ISceneNode*>::Iterator it = list.begin();

	for (; it != list.end(); ++it) {
		// Check ob es sich um das Licht handelt
		if ((*it)->getID() & ERNT_STAR_LIGHT) {
			(*it)->setVisible(state);
			return;
		}
	}
}
The first time this error accurs was, when the Iteration through the setStarLight()-function was completed and should return. Sometimes i can debug to this point, that i see that the deconstructor off the list is called, but why?

Did anyone know what i do wrong? Has someone a suggestion?

Sorry for my bad english ;), but i hope you understand what my problem is and that someone can help me :D.

so long
Joe[/code]
JoeMill

Post by JoeMill »

I searched in the MSDN for the _CrtIsValidHeapPointer-Function and found this:
The _CrtIsValidHeapPointer function is used to ensure that a specific memory address is within the local heap. The 'local' heap refers to the heap created and managed by a particular instance of the C run-time library. If a dynamically linked library (DLL) contains a static link to the run-time library, then it has its own instance of the run-time heap, and therefore its own heap, independent of the application?s local heap. When _DEBUG is not defined, calls to _CrtIsValidHeapPointer are removed during preprocessing.
So I think the problem is, that when i try to iterate through the ScenenNodes in my app, i left the "local" heap from my app and work the "local" heap of the irrlicht dll, so what can i do? I do not want to put this LOD-System (maybe a zoomstages are a better name for ;) ) in the irrlicht dll.

Any Ideas?

greetz
joe
JoeMill
Posts: 3
Joined: Wed Jan 14, 2004 12:29 pm
Location: Dresden, Germany

I found the solution

Post by JoeMill »

i want it to use like i uye the std::list, but i should a have read the doc a little bit deeper ;).

I only need to crete a Iterator for the list, because i receive a reference :oops:, so i chnged the code to this and it works :D

Code: Select all

core::list<scene::ISceneNode*>::Iterator galChildIt = m_galaxyRootSceneNode->getChildren().begin();
Was a nice day to figure this out :P.

@niko

great work so far, but why did you reinvent the wheel and use your own list and string class?

greetz
Joe
keless
Posts: 805
Joined: Mon Dec 15, 2003 10:37 pm
Location: Los Angeles, California, USA

Post by keless »

well, i cant neccesarily speak for Niko, but my quess would be cross-platform concerns. By writing his own base classes which are distributed with the engine, he doesnt need to worry whether the systems his engine ends up on have generic versions of the same thing.
a screen cap is worth 0x100000 DWORDS
SwiftCoder
Posts: 32
Joined: Thu Jan 15, 2004 7:33 pm
Location: Carribean

Post by SwiftCoder »

keless wrote:well, i cant neccesarily speak for Niko, but my quess would be cross-platform concerns. By writing his own base classes which are distributed with the engine, he doesnt need to worry whether the systems his engine ends up on have generic versions of the same thing.
All very well, but I can't off-hand think of a system that does not have stl, and the stl classes have been implemented separately on each operating system, conforming to the same specification, so stl tends to be one of the fastest choices on any given platform (the exception being stlport, which has not been extensively modified for speed under windows).
Post Reply