我遇到由CSceneNode * pRoot = nodes [0]引起的隨機崩潰問題; //真正的問題是= nodes [0]; 崩潰消息是:「0x0059d383」處的指令引用「0x00000000」處的內存。內存不會被「讀取」。 我看不到問題,請幫我解決問題?內存不被「讀取」。 - 隨機崩潰
在Save.cpp
void CNESave::SaveLocation(CNELocation* pLoc)
// Other code
CSceneNode* scene = pLoc->GetScene();
vector<CSceneNode*> nodes;
scene->GetNodes(GetNodesByPartOfName, nodes, &string("_Ldynamic"));
CSceneNode* pRoot = nodes[0]; //This is the problem causing random crashes!
// If I change it (just for testing) to CSceneNode* pRoot = scene
// them it isn't crashing.
// So CSceneNode* pRoot is OK and the problematic part is = nodes[0];
在SceneNode.cpp
bool GetNodesByPartOfName(CSceneNode* node, const void *data)
{
string *str = (string *)data;
return node->GetName().find(*str)!=npos;
}
void CSceneNode::GetNodes(GetNodesFunc gf, vector<CSceneNode*> &nodes,
const void *data)
{
if (gf(this, data)) nodes.push_back(this);
SceneNodeIterator begin=FirstChild(), end=LastChild();
for (;begin!=end;begin++) ((CSceneNode*)*begin)->GetNodes(gf, nodes, data);
}
CSceneNode* CSceneNode::CreateNew()
{
return new CSceneNode();
}
// a lot of other code
在SceneNode.h
class EXPORTDECL CSceneNode;
typedef bool (*GetNodesFunc)(CSceneNode *node, const void *data);
EXPORTDECL bool GetNodesByPartOfName(CSceneNode* node, const void *data);
typedef vector<CSceneNode*>::iterator SceneNodeIterator;
class EXPORTDECL CSceneNode : public CTreeNode<CSceneNode, true>
{
public:
//construction & destruction
CSceneNode();
virtual ~CSceneNode();
virtual CSceneNode *CreateNew();
// a lot of other code
解決。非常感謝你們。
你肯定'nodes'後'GetNodes'是不是空的? – Naveen 2010-10-01 12:45:09
可能不會導致你的問題,但我會避免'&string(「_Ldynamic」)'構造... – 2010-10-01 12:45:26