I am quite desperate about a random crash. The memory could not be "read" error.
I would be very happy for any help. Thank you.

HRESULT CSceneNode::UpdateAll()
{
	D3DXMATRIX backup_local_tm = ei.world_tm;
	Update();
	
	SceneNodeIterator begin=FirstChild();
	SceneNodeIterator end=LastChild();
	for (;begin!=end;begin++)
	{
		(*begin)->UpdateAll();		 // Here is the random Crash !!!
	}
	ei.world_tm = backup_local_tm;
	return S_OK;
}


HRESULT CSceneNode::Update()
{
	if (!pretransformed)
	{
		ei.world_tm=*physics->GetMatrix()*ei.world_tm;
		SetTmMat(&ei.world_tm);
	}
	return S_OK;
}

void CSceneNode::SetTmMat(D3DXMATRIX* m) 
{
	tm_mat= *m; 
	if (bound) bound->TransformIntoWorldCoordinates();
	hasInverseTM=false;
}

	
//----- in SceneNode.h
D3DXMATRIX tm_mat;
CBoundingVolume *bound;

//----- in CBoundingVolume.h
void CBoundingVolume::TransformIntoWorldCoordinates()
{
	if (!(init && owner )) return;
	REPORTR(rlReport, init && owner, return);

	int i;
	for (i=0;i<8;i++) D3DXVec3TransformCoord (&wVerts[i], &verts[i], owner->GetTmMat());
	for (i=0;i<3;i++) D3DXVec3TransformNormal(&wAxis[i],  &axis[i],  owner->GetTmMat());
	D3DXVec3TransformCoord(&wCenter, &center, owner->GetTmMat());
}

// inside ei is
D3DXMATRIX world_tm;

//----- in physics.h
class EXPORTDECL CPhysics  
public:
  Physics();
  virtual ~CPhysics() {}
  virtual D3DXMATRIX *GetMatrix() {return &staticTM;}	

//----- in physics.cpp
CPhysics::CPhysics()
{
	animated=0;
	staticTM=identityMatrix;
}

CPhysics* CPhysics::CreateNew()
{
	return new CPhysics;
}

I have no idea what this code is supposed to do, but lines 6,7 and 8 look suspicious to me. What does UpdateAll() do? Does it affect the value returned by LastChild()? I'd be tempted to go for something more like:

for( SceneNodeIterator it = FirstChild(); it! = LastChild(); ++it )

Edit: Actually, UpdateAll() is a recursive function. Have you tried putting break points in all the functions to check you're not dereferencing a null pointer? Also, very few crashes are random :-)

Edited 5 Years Ago by ravenous: n/a

Did you release all the objects, and do you reset the device before quitting the program? I really don't have time to read through all the code and I am not an expert in DirectX. This is more like game Development. But again, there is a problem, that no-one answers in game-development forum, so there is a lot of unanswered threads. When I get better at game programming I think I will be there more often.

(*begin)->UpdateAll();	 // Here is the random Crash !!!

And where did you define the function first child? You should post more code.

(*begin)->UpdateAll();	 // Here is the random Crash !!!

And where did you define the function first child? You should post more code.

When I run the application it goes fine in about 75 percent cases and only about every fourth run it crashes there. Here is the code you ware asking:

//children methods
	DWORD NumChildren() {return DWORD(children.size());}
	std::vector<Node*>& GetChildren() { return children; }
	typename vector<Node*>::iterator FirstChild() {return children.begin();}
	typename vector<Node*>::iterator LastChild() {return children.end();}
	void AddChild(Node* tnode)
	{
		children.push_back(tnode);
		if (tnode!=NULL) 
		{
			if (tnode->GetParent()!=NULL) tnode->BrakeLinkToParent();
			tnode->parent=(Node*)this;
		}
	}
	Node *GetChild(DWORD i) {return children[i];}
This article has been dead for over six months. Start a new discussion instead.