Game Development Community

Lurking bug in shapeBase::playAudio() and stopAudio().

by Orion Elenzil · in Torque Game Engine · 07/31/2006 (4:29 pm) · 6 replies

In both the console methods below,
i'm pretty sure ShapeBase::MaxScriptThreads should be ShapeBase::MaxSoundThreads.

the actual object methods which these console methods call use MaxSoundThreads.

this is present in TGE 1.3 and 1.4.

it probably rarely has effect since by default MaxScriptThreads and MaxSoundThreads are both set to 4,
but if you go adjusting those, watch out!

ConsoleMethod( ShapeBase, playAudio, bool, 4, 4, "(int slot, AudioProfile ap)")
{
   U32 slot = dAtoi(argv[2]);
   if (slot >= 0 && slot < ShapeBase::[b]MaxScriptThreads[/b]) {  // should be MaxSoundThreads 
      AudioProfile* profile;
      if (Sim::findObject(argv[3],profile)) {
         object->playAudio(slot,profile);
         return true;
      }
   }
   return false;
}

ConsoleMethod( ShapeBase, stopAudio, bool, 3, 3, "(int slot)")
{
   U32 slot = dAtoi(argv[2]);
   if (slot >= 0 && slot < ShapeBase::[b]MaxScriptThreads[/b]) {  // should be MaxSoundThreads 
      object->stopAudio(slot);
      return true;
   }
   return false;
}

#1
08/01/2006 (8:10 am)
Are you sure about that ?
If you reach MaxScriptThreads what happens then with your changes , MaxSoundThreads is handled in another part of shapebase.cc.
example-> if you reach maxScriptThreads and still call playAudio , does it not crash then ?
#2
08/01/2006 (8:18 am)
Hey Billy -
no, not absolutely sure, but i'd put $20 on it.

the main evidence is check out the source for the playAudio() method which the console method is just a wrapper for. It's doing the same test against MaxSoundThreads, not MaxScriptThreads:
void ShapeBase::playAudio(U32 slot,AudioProfile* profile)
{
   AssertFatal(slot < [b]MaxSoundThreads[/b],"ShapeBase::playSound: Incorrect argument");
   Sound& st = mSoundThread[slot];
   if (profile && (!st.play || st.profile != profile)) {
      setMaskBits(SoundMaskN << slot);
      st.play = true;
      st.profile = profile;
      updateAudioState(st);
   }
}

also i did a cursory grep for all occurences of MaxScriptThreads, and these two (playAudio, stopAudio) were the only ones which were obviously related to sound to me.

my theory is that whoever implemented the console methods playAudio() and stopAudio() probably copied the methods for playThread() and stopThread(), *which are immediately below play/stopAudio()*, and just overlooked changing the constant. it never manifested because by default the two constants are both the value 4, so it actually wouldn't matter which you chose.
#3
08/01/2006 (8:26 am)
Ye ok need todo some testing , this code part have been the same since V12 :)
#4
08/09/2006 (2:25 pm)
Good catch!
#5
08/10/2006 (2:30 am)
Does this have anything todo with alxstop() not working to stop playing a audiochannel ?
#6
08/10/2006 (2:33 am)
alxStop($handle) works just fine. Others are using it. You should learn from your other thread where you already got an answer.

For anyone that did not understand, if you read the first post, it says both maxScriptThreads and MaxSoundThreads are the same in stock, but it is a bug in that if someone changes either of the two, you will get oddities.