Game Development Community

Out of bounds array access in createLightmaps.cpp

by Tom Spilman · in Torque Game Engine Advanced · 12/21/2004 (10:08 pm) · 3 replies

Not sure why VC++ in debug isn't screaming at me when this happens. If you look at the enum for Speed in BaseLightEntity:

enum Speed {
         VerySlow    = 0,
         Slow        = 1,
         Normal      = 3,
         Fast        = 4,
         VeryFast    = 5
      };

... it skips 2.... ok that's odd. Looking at createLightmaps.cpp you can see the use of the speed enum in any of the animated light build functions. For instance Lighting::Light::buildStrobeLight():

state.mDuration = (i & 0x01) ? 0.f : AnimationTimes[strobeLight->mSpeed];

To test i set a strobe speed to 5 and traced the code... strobeLight->mSpeed is 5. Looking at the definition of AnimationTimes at the top of createLightmaps.cpp:

static const F32 AnimationTimes[] = { 2.f, 1.f, 0.5f, 0.25f, 0.125f };

Clearly a speed of 5 is out of bounds and would lead to errors in release builds. So it seems that problem is in the Speed enum and it skipping 2.

Not that strobe lights work in TSE... but still.

About the author

Tom is a programmer and co-owner of Sickhead Games, LLC.


#1
12/21/2004 (10:54 pm)
On todo list.
#2
12/23/2004 (10:03 am)
Strobe lights will not be supported in this way for TSE. This should be done with dynamic lights.
#3
12/23/2004 (10:06 am)
By dynamic you mean stencil shadows or just a hardware light using the lightmap as a mask for the effected area?