Found a Strange Bug
by Jesse Allen · in Torque 3D Professional · 07/19/2014 (6:23 am) · 12 replies
I wanted to report a bug I found that can be extremely annoying...
If you launch a game with no weapon mounted, performance nosedives. On the 'Empty Room' level, my fps drop from over 500 to 20-40fps. On the 'Empty Terrain' level, my fps are halved.
To duplicate this bug, all you have to do is open the gameCore.cs server script and comment out the lines where weapons are mounted to the player (in GameCore::loadOut).
This bug has cost me a ridiculous amount of troubleshooting time, and took a long time to track down. I was ready to blame Recast or other source changes for the trouble, and all along it was the fact that I was trying to start my player weaponless...
Are there some sort of checks being performed constantly if the player has no weapon? Whatever it is, it's game-breaking if you try to start a game with no weapon mounted.
If you launch a game with no weapon mounted, performance nosedives. On the 'Empty Room' level, my fps drop from over 500 to 20-40fps. On the 'Empty Terrain' level, my fps are halved.
To duplicate this bug, all you have to do is open the gameCore.cs server script and comment out the lines where weapons are mounted to the player (in GameCore::loadOut).
This bug has cost me a ridiculous amount of troubleshooting time, and took a long time to track down. I was ready to blame Recast or other source changes for the trouble, and all along it was the fact that I was trying to start my player weaponless...
Are there some sort of checks being performed constantly if the player has no weapon? Whatever it is, it's game-breaking if you try to start a game with no weapon mounted.
About the author
Skilled Artist and Musician. Intermediate Torque Developer.
#2
07/19/2014 (10:18 am)
This player/weapon thing came up a while back and I'm not sure anyone ever really nailed it, though I think someone did mention sound.... I remember Steve Acaster was in that discussion.
#3
07/19/2014 (11:18 am)
Thanks for the quick replies guys. Just dropped in a MainMenu theme and yep, that was indeed the culprit.
#4
07/19/2014 (2:21 pm)
Oh gosh. This is just embarrassing.
#5
This is kinda different because it does play a sound when you first start a mission (as andrew mentions above the gun makes a sound when you equip it) but for me the momentary fps drop occurs when firing a weapon the first time. It doesn't matter which weapon, when you fire once the one off fps drop never happens again even on other weapons.
Also if you exit a mission and start it again without closing the app it never has the fps drop again either. So this is consistent with the original problem described above
*Edit:
Happens with OpenAL, XAudio and even NULL sound plugin.
07/19/2014 (6:21 pm)
My experience with this bug is somewhat different. I get no FPS difference if i comment out the loadOut in gameCore.cs. I do get a huge FPS drop momentarily when i first fire the gun (this suggests something in the SFX is creating/loading/buffering perhaps?), after that all is sweet. This is kinda different because it does play a sound when you first start a mission (as andrew mentions above the gun makes a sound when you equip it) but for me the momentary fps drop occurs when firing a weapon the first time. It doesn't matter which weapon, when you fire once the one off fps drop never happens again even on other weapons.
Also if you exit a mission and start it again without closing the app it never has the fps drop again either. So this is consistent with the original problem described above
*Edit:
Happens with OpenAL, XAudio and even NULL sound plugin.
#6
I think you're dealing with a different bug. The delay when you fire the gun for the first time is from the shell that flys out of the gun if I remember correctly. I believe I tracked that down in a different thread but never came up with a solution beyond removing the debris piece from the weapon. It's a preload issue I believe.
@ Everyone else
I traced this sound bug and it's DirectSound specific. It comes from:
The hold up is the call to update deferred settings in DirectSound. I was in the process of trying to figure out how to fix this when the question was raised why we would even bother since support for DirectSound has been dropped by Microsoft. I confirmed the bug only exists in DirectSound, so should I try to figure out how to prevent this bug or should we just pull support for DirectSound in favor of xaudio?
07/20/2014 (7:11 am)
@ TimmyI think you're dealing with a different bug. The delay when you fire the gun for the first time is from the shell that flys out of the gun if I remember correctly. I believe I tracked that down in a different thread but never came up with a solution beyond removing the debris piece from the weapon. It's a preload issue I believe.
@ Everyone else
I traced this sound bug and it's DirectSound specific. It comes from:
void SFXDSDevice::update()
{
Parent::update();
// Apply the deferred settings that changed between updates.
mListener->CommitDeferredSettings();
}The hold up is the call to update deferred settings in DirectSound. I was in the process of trying to figure out how to fix this when the question was raised why we would even bother since support for DirectSound has been dropped by Microsoft. I confirmed the bug only exists in DirectSound, so should I try to figure out how to prevent this bug or should we just pull support for DirectSound in favor of xaudio?
#7
Question - what's the purpose of calling this on every update? Is that necessary? Is it something that could be called when changing audio settings (as the name implies) or does it do something important as the listener is moved in the scene? And why didn't I just look it up myself?
07/20/2014 (9:18 am)
This begs the question "just how legacy are we shooting for?"Question - what's the purpose of calling this on every update? Is that necessary? Is it something that could be called when changing audio settings (as the name implies) or does it do something important as the listener is moved in the scene? And why didn't I just look it up myself?
#8
Another question I don't know the answer to is what changes when you play a sound that causes this function to no longer be a problem.
I had a plan to dig into the whole thing and solve it but then someone pointed out XAudio2 is the replacement for DirectSound, and will fall back on using DirectSound on older systems. So, as far as I can tell, there is no argument in favor of DirectSound at all since XAudio2 has legacy support as well.
07/20/2014 (9:50 am)
From what I briefly read on it you can set the device into two modes. In dynamic mode you can just change the settings as you please and it will automatically update them. The other mode you have to notify it when you change the settings using the function above. It sounds like the current implementation uses the function of the latter to achieve the effects of the former. Why? I'm not sure, maybe it was faster ( doesn't look like it ). Another question I don't know the answer to is what changes when you play a sound that causes this function to no longer be a problem.
I had a plan to dig into the whole thing and solve it but then someone pointed out XAudio2 is the replacement for DirectSound, and will fall back on using DirectSound on older systems. So, as far as I can tell, there is no argument in favor of DirectSound at all since XAudio2 has legacy support as well.
#9
07/20/2014 (10:26 am)
I would say ditch DirectSound in favor of XAudio2. It would also be nice if someone could update the FMOD support from FMOD Ex API (the old legacy FMOD API) to FMOD Studio API as it now offers a great licensing deal (free!) for low budget games.
#10
07/20/2014 (4:23 pm)
I could be wrong because i don't really keep up with the sound API's but i think OpenAL (well the creative version anyway) will use DirectSound as a software fallback device too. I vote get rid of DirectSound, it's 2014 and we can't support 10 year old operating systems and software forever.
#11
Bonus points to anyone who does tackle FMOD Studio support :)
07/20/2014 (6:00 pm)
Yea I've had no trouble with Xaudio so far, I have to agree with Anders and Timmy on this. Bonus points to anyone who does tackle FMOD Studio support :)
#12
07/20/2014 (6:08 pm)
FMOD Ex support would be great, i personally don't have time to implement it as i am snowed under with other stuff at the moment.
Andrew Mac
The reason you're seeing the correlation between the weapon and the bug is because the weapon plays a sound when you first equip it. If you do something to play a sound on spawn I think you'll see your performance come back.