Game Development Community

Torque Engine BUG: 4WD Vehicle sound causes sytem lockup?!

by Eugene Goh · in Torque Game Engine · 10/05/2004 (4:22 am) · 9 replies

I have had a strange problem that can be replicated on the starter.racing demo. Steps to replicate follow:

Alter server/scripts/car.cs

Uncomment:
engineSound = BuggyEngineSound;
   softImpactSound = SoftImpactSound;
   hardImpactSound = HardImpactSound;

Add:
datablock AudioProfile(SoftImpactSound)
{
   filename    = "~/data/sound/smallcrash.wav";
   description = AudioClosest3d;
   preload = true;
};

datablock AudioProfile(HardImpactSound)
{
   filename    = "~/data/sound/bigcrash.wav";
   description = AudioClosest3d;
   preload = true;
};

Make sure all the sounds are there, including the buggyEngineSound for which there is already a profile (which I left unchanged).

In the same file, add these lines at the bottom of WheeledVehicleData::onAdd
%obj.setWheelPowered(0,true);
   %obj.setWheelPowered(1,true);

Run the code, enter the mission and if lucky, drive around for a couple of minutes. System lockup happens, causing everything to grind down to a a couple of cpu cycles per minute.

This was done on two machines, one on XP, one on Windows 2000. Both used VC6 SP5 for compilation (Release build), and have different sound cards. It was tested on TGE 1.2.something as well as vanilla 1.3. Console.log doesn't show anything unusual.

The game will run well if the car sounds are disabled, or only two wheels are powered. The combination seems to be the problem. Any insights would be greatly appreciated!

#1
10/05/2004 (4:38 am)
I'm not sure if this is caused by the sounds or not. I had a problem with 4WD 3 months back, cuasing it to crash/hang. 2 wheels worked just fine. Eventually I re-arranged the hubs on my model, and it all worked fine from then on. So now I have 4WD, and sounds, no problem.
#2
10/05/2004 (4:44 am)
Just tried this out on the debug version as well, same problem. I didn't get to see the debug output for pretty obvious reasons.

How did you rearrange them Ward? I faced this problem not only for the default buggy model, but also my own car model.

Edit: specifically, which number hub did you put on each wheel?
#3
10/05/2004 (6:51 am)
I looked at how they did it in Tribes II and applied it that way, worked perfectly.
#4
10/05/2004 (6:56 am)
Any links on that Stefan? Google isn't being kind.
#5
10/05/2004 (5:58 pm)
I've had 4 wheel drive and 4 wheel steering on my jeep and I've never had any problems. Although I'm not sure if we use crash sounds for it.
#6
10/06/2004 (6:44 am)
I have looked into the documentation (i.e. the source code) and found the problem. I believe Torque is using Creative Lab's version of OpenAL for the win32 platform. The OpenAL specification supports pitch value ranges between 0 and 1. Most OpenAL libararies support from 0 to 2. Creative Lab's library supports from 0.01 to 2. When it hits 0, we get the crash.

The pitch is controlled by the average wheel torquescale. When the vehicle is in 2 wheel drive mode, the pitch varies approximately between about 0.512 to 1.3. When in 4WD mode, it varies between 0 and 1.3. The rationale for this, I cannot understand as I'm no car mechanic. But when it hits 0, OpenAL and Torque goes boom.

I suspect the real problem might be in this block of code:

(engine\game\vehicles\wheeledVehicle.cc)

WheeledVehicle::advanceTime
Wheel* wend = &mWheel[mDataBlock->wheelCount];
   for (Wheel* wheel = mWheel; wheel < wend; wheel++)
      if (wheel->tire && wheel->spring) {
         // Update angular position
         wheel->apos += (wheel->avel * dt) / M_2PI;
         wheel->apos -= mFloor(wheel->apos);
         if (wheel->apos < 0)
            wheel->apos = 1 - wheel->apos;

         // Keep track of largest slip
         slipTotal += wheel->slip;
         torqueTotal += wheel->torqueScale;
      }

   // Update the sounds based on wheel slip and torque output
   updateSquealSound(slipTotal / mDataBlock->wheelCount);
   updateEngineSound(sIdleEngineVolume + (1 - sIdleEngineVolume) *
      (1 - (torqueTotal / mDataBlock->wheelCount)));
It does not care whether the wheel is powered or not and just averages, changing the sound.


The workaround I put in was to change

void WheeledVehicle::updateEngineSound(F32 level)
{
   if (mEngineSound) {
      alxSourceMatrixF(mEngineSound, &getTransform());
      alxSourcef(mEngineSound, AL_GAIN_LINEAR, level);
      alxSourcef(mEngineSound, AL_PITCH, pitch);
   }
}

to

void WheeledVehicle::updateEngineSound(F32 level)
{
   if (mEngineSound) {
      alxSourceMatrixF(mEngineSound, &getTransform());
      alxSourcef(mEngineSound, AL_GAIN_LINEAR, level);
      
      // Creative Labs win32 OpenAL workaround
      F32 pitch = ((level-sIdleEngineVolume) * 1.3);
      if (pitch < 0.4)  
         pitch = 0.4;
      // End workaround
      alxSourcef(mEngineSound, AL_PITCH, pitch);
   }
}

In principle, I should use 0.01 instead of 0.4 as the limiter, but you can't really hear anything under 20 Hz, and my sound was pretty low pitched to begin with.

Mac/Linux coders beware! If you have a 4WD vehicle in your game, it might cause system lockups when played on Windows machines!

If anybody has any insights as to how the torquescale is supposed to work, please do share! This does not feel like a complete fix. If the torquescale is correct and it's just the sound that is being messed up, I can probably work something out.
#7
04/08/2005 (12:37 pm)
I think as a feature request GG should do something about the whole OpenAl thing. It has caused alot of head ache in our project. I just hope that this will be redone with TSE.
#8
04/08/2005 (4:31 pm)
It's on the list. BTW, nice fix, Eugene.
#9
04/09/2005 (6:56 am)
Thanks Ben I saw your other post in another forum about this. I am very happy that this is being looked at.