Hello, I have a recursive function that has been baffling me for quite a while now:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
CUSTOM_FRAME* dr_animated::searchbyname(CUSTOM_FRAME* pFrame, LPCSTR names, size_t length)
{
if ( !strncmp( names, pFrame->Name, length) )
{
MessageBox(NULL, "FrameName:", "Hitbox Editor", MB_OK);
MessageBox(NULL, pFrame->Name, "Hitbox Editor", MB_OK);
MessageBox(NULL, "OtherName:", "Hitbox Editor", MB_OK);
MessageBox(NULL, names, "Hitbox Editor", MB_OK);
return pFrame;
}
else
{
if (pFrame->pFrameSibling)
searchbyname((CUSTOM_FRAME*)pFrame->pFrameSibling, names, length);
if(pFrame->pFrameFirstChild)
searchbyname((CUSTOM_FRAME*)pFrame->pFrameFirstChild, names, length);
}
return NULL; ///This always results in a crash, but I know that and keep it in temporarily.
}
|
Basically what it does is go through every frame (bones of an armature), looking for which one has a name which is identical to the passed value 'names' (I called it that because I thought calling it "name" was the reason for the problem, which it wasn't).
What happens is, upon calling it, the MessageBoxes appear (for instance, if names = "Animation_Bone_008", the boxes display:
FrameName:
"Animation_Bone_008" - meaning there IS a pFrame node with that Name.
OtherName:
"Animation_Bone_008" - Which confirms that 'names' was in fact "Animation_Bone_008"
Now here's the issue. After displaying those messages, I expect the function to return a pointer to the bone it found a match for, or, if it didn't, to go on until it does (or crash if it's not there).
It does not. Instead, after calling the function, I always get the exact same return if there IS a match, and a crash if there isn't.
What is returned is a Frame with the name "Animation_Bone_L_007", which is a completely random and unrelated frame.
I have no idea why this is happening, especially since the MessageBox's run, implying that the match was found. Any help is appreciated, thankyou.