Recursion problem

Recommended Posts

Here is the code I have:
std::vector<JOINT> JointPalette;
JointPalette.clear();

HRESULT SortJoints(BONE *pBone, UINT Index, int ParentIndex)
{
int CurrIndex = JointPalette.size();
JointPalette.resize(CurrIndex+1);    //Increase the JointPalette space by 1

//Code to fill up JointPalette[CurrIndex]
//mainly using D3DXMatrixFunc(), and D3DXQuaternionFunc()

if (pBone[Index].SiblingIndex != -1)
SortJoints(pBone, pBone[Index].SiblingIndex, ParentIndex);

if (pBone[Index].ChildrenIndex != -1)
SortJoints(pBone, pBone[Index].ChildrenIndex , CurrIndex);
}

Doing this would cause a the program to break and point to some code in the page 'xtree' However if I replace the starting code with:

std::vector<JOINT> JointPalette;
JointPalette.resize(NumBones);

HRESULT SortJoints(BONE *pBone, UINT Index, int ParentIndex)
{
static int CurrIndex = -1
CurrIndex++;

.... same as above ...


everything works alright. I would love to know what causing the error in the first code, so I can learn from my mistakes. Thanks in advance. Edited: some typo errors

Share on other sites
In the first case, currentIndex is the size of the JointPalette at the top of the function. In the second case, currentIndex is the size of the JointPalette after the call SortJoints(pBone, pBone[Index].SiblingIndex, ParentIndex);

Share on other sites
But I don't understand how that causes the problem.

I am guessing that the error is related to me trying to access pass the vector size? But as to how, I don't know.

Just a feeling on my part.

I am not sure I understand you completely ToohrVyk.

Create an account

Register a new account

• Partner Spotlight

• Forum Statistics

• Total Topics
627652
• Total Posts
2978421

• 10
• 12
• 22
• 13
• 33