Sign in to follow this  

Recursion problem

This topic is 3785 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites

This topic is 3785 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this