mournerslament
July 24th, 2007, 11:29 PM
Hi, I have limited experience with multithreaded applications, but the most experience on my team, so I am trying to implement it in our game we are working on. The purpose of the thread is to simply update all of the skeletal hierarchies of our characters in our game.
I have had a host of problems with it, thus far, despite all the reading I have done. My current problem may be the most frustrating: My thread is being killed somehow upon a call to EnterCriticalSection() in the thread. This is a relatively recent issue, and I do not even know how it started to do this, since I do not remember changing anything, at least not that would affect something like this.
Here is the code where the thread is running. Sorry about the formatting, I just spent 15 minutes trying to get it looking anywhere near readable, but the code tags are doing some weird stuff to my code, so I just copied and pasted it again...Is there some sort of secret to actually get it to format nicely? :
unsignedint__stdcall DR_AnimationSystem::UpdateHierarchies(void *pAnim)
{
unsignedint num = 0;
DR_AnimationSystem *pAnimSystem = (DR_AnimationSystem *)pAnim;
///bool bUpdate = true;
while(1)
{
//Gets here once, and then never gets to the next line
EnterCriticalSection(&(pAnimSystem->m_cs));
{
num = static_cast<unsignedint>(pAnimSystem->m_vHierarchies.size());
}
LeaveCriticalSection(&(pAnimSystem->m_cs));
for(unsignedint a = 0; a < num; a = a+1)
{
if(!pAnimSystem->m_vHierarchies[a])
{
EnterCriticalSection(&(pAnimSystem->m_cs));
{
pAnimSystem->m_vHierarchies.erase(pAnimSystem->m_vHierarchies.begin()+a--);
}
LeaveCriticalSection(&(pAnimSystem->m_cs));
}
else
{
pAnimSystem->m_vHierarchies[a]->Process();
}
}
Sleep(1);
}
return 0;
}
This was running fine earlier, I was just having some other problems. I don't think I changed anything to mess with this. I would post more code, but there is a lot of it, and I do not see how any of it would mess what is going on here. The other thread still runs fine, and everything works, this thread is just...gone?
I know I am not terminating it, I even took out my cleanup code in order to make sure, and I am still having this problem.
Please tell me I am making some stupid mistake somewhere. Any help would be very very appreciated, since I am on a very tight schedule right now and need to get this done soon. Again, sorry about how nasty the code looks, I really did try to format it, but I just made things worse. Thanks.
I have had a host of problems with it, thus far, despite all the reading I have done. My current problem may be the most frustrating: My thread is being killed somehow upon a call to EnterCriticalSection() in the thread. This is a relatively recent issue, and I do not even know how it started to do this, since I do not remember changing anything, at least not that would affect something like this.
Here is the code where the thread is running. Sorry about the formatting, I just spent 15 minutes trying to get it looking anywhere near readable, but the code tags are doing some weird stuff to my code, so I just copied and pasted it again...Is there some sort of secret to actually get it to format nicely? :
unsignedint__stdcall DR_AnimationSystem::UpdateHierarchies(void *pAnim)
{
unsignedint num = 0;
DR_AnimationSystem *pAnimSystem = (DR_AnimationSystem *)pAnim;
///bool bUpdate = true;
while(1)
{
//Gets here once, and then never gets to the next line
EnterCriticalSection(&(pAnimSystem->m_cs));
{
num = static_cast<unsignedint>(pAnimSystem->m_vHierarchies.size());
}
LeaveCriticalSection(&(pAnimSystem->m_cs));
for(unsignedint a = 0; a < num; a = a+1)
{
if(!pAnimSystem->m_vHierarchies[a])
{
EnterCriticalSection(&(pAnimSystem->m_cs));
{
pAnimSystem->m_vHierarchies.erase(pAnimSystem->m_vHierarchies.begin()+a--);
}
LeaveCriticalSection(&(pAnimSystem->m_cs));
}
else
{
pAnimSystem->m_vHierarchies[a]->Process();
}
}
Sleep(1);
}
return 0;
}
This was running fine earlier, I was just having some other problems. I don't think I changed anything to mess with this. I would post more code, but there is a lot of it, and I do not see how any of it would mess what is going on here. The other thread still runs fine, and everything works, this thread is just...gone?
I know I am not terminating it, I even took out my cleanup code in order to make sure, and I am still having this problem.
Please tell me I am making some stupid mistake somewhere. Any help would be very very appreciated, since I am on a very tight schedule right now and need to get this done soon. Again, sorry about how nasty the code looks, I really did try to format it, but I just made things worse. Thanks.