Jump to content
  • Advertisement
Sign in to follow this  
littlekid

Recursion problem

This topic is 4004 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!