Forum

Avoiding Compiler Screwups?

Discuss programming topics for the various GPL'd game engine sources.

Moderator: InsideQC Admins

Avoiding Compiler Screwups?

Postby Baker » Thu Oct 09, 2014 5:07 am

Are there any special tricks to avoiding compiler screwups?

Here is one that is bothering me right now .... Using maximum optimization, ambient sounds aren't playing until pressing ALT-TAB and switching away or back. Both using GCC and using Visual Studio. Maybe even more than that. Of course the debug build works fine.

The most aggressive optimizations don't seem to add any fps or performance, but they sure do screw up small things in subtle ways.

I've had the compiler poorly round floats so that multiplying by 100 ends up being slightly short of x 100 in multiplication against an integer before. There is a block of original Quake source code in software I have wrapped with #pragma optimize ("off") / #pragma optimize ("on") to keep the compiler from foobaring it.

Sometimes I kind of wonder whether just to use slightly less than the best optimization to prevent this kind of subtle chaos.
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Re: Avoiding Compiler Screwups?

Postby Spike » Thu Oct 09, 2014 10:18 am

bugs like that suggest that you're not initialising something properly.
try valgrind.
Spike
 
Posts: 2908
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Re: Avoiding Compiler Screwups?

Postby qbism » Thu Oct 09, 2014 4:37 pm

Pentium optimizations can have errors related to FP precision. Anything below P4/ss3 or thereabouts
User avatar
qbism
 
Posts: 1236
Joined: Thu Nov 04, 2004 5:51 am

Re: Avoiding Compiler Screwups?

Postby Baker » Fri Oct 10, 2014 3:48 am

I've used a few different tools like Very Sleep and Microsoft Application Verifier, nothing.

After further examination, the sound issue might not have been code related at all. I think one of the tabs in my web browser was responsible or something running in the background.
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Re: Avoiding Compiler Screwups?

Postby Baker » Sat Oct 11, 2014 12:59 am

UPDATE: I was running at maxfps set to 9999 and running 300 to 1200 fps can have an unexpected effect on sound, it seems.

At high frametimes, I think the funny business occurs here:

So at high frame rates, ambient sound level may never increment because the (int) rounds to zero.
Code: Select all
   // don't adjust volume too fast
      if (chan->master_vol < vol)
      {
         chan->master_vol += (int) (host_frametime * ambient_fade.value); <------------ high frame rate = very low number, (int) causes it to be zero.

         if (chan->master_vol > vol)
            chan->master_vol = vol;
      }
      else if (chan->master_vol > vol)
      {
         chan->master_vol -= (int) (host_frametime * ambient_fade.value);

         if (chan->master_vol < vol)
            chan->master_vol = vol;
      }


The reason ALT-TAB fixed it for me is due to code that reduces the framerate if not the activate app, allowing the sound to progress in non-zero increments.

I was blaming the compiler because I happened to be trying to get MinGW going and that is when I noticed the issue. The debug build didn't experience the issue because the debug yielded a lower framerate.
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Re: Avoiding Compiler Screwups?

Postby qbism » Sat Oct 11, 2014 1:58 pm

Separate packet update rate from refresh rate?
User avatar
qbism
 
Posts: 1236
Joined: Thu Nov 04, 2004 5:51 am

Re: Avoiding Compiler Screwups?

Postby Spike » Sat Oct 11, 2014 2:33 pm

fte just uses a float internally and just copies that over to the master_vol field, apparently.
well done finding it though, such things can be annoying (especially that ambient noise stuff anyway).
Spike
 
Posts: 2908
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Re: Avoiding Compiler Screwups?

Postby Baker » Sat Oct 11, 2014 3:49 pm

qbism wrote:Separate packet update rate from refresh rate?

Code is in snd_dma.c and in the original Quake.

To the best of my knowledge, certain ambient sounds like the sky noise are client-side only, and don't require any kind of server support.

Code: Select all
#define   AMBIENT_WATER   0
#define   AMBIENT_SKY      1
#define   AMBIENT_SLIME   2
#define   AMBIENT_LAVA   3

#define   NUM_AMBIENTS         4      // automatic ambient sounds


Code: Select all
   ambient_sfx[AMBIENT_WATER] = S_PrecacheSound ("ambience/water1.wav");
   ambient_sfx[AMBIENT_SKY] = S_PrecacheSound ("ambience/wind2.wav");
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Re: Avoiding Compiler Screwups?

Postby revelator » Mon Oct 13, 2014 5:08 pm

One thing to also look out for are floating point precision when it comes to msvc.
Msvc from version 2012 and up have replaced floating point precision with SSE math so if you get weird behaviour ill look at that.
This was discovered because vanilla doom3's stencil shadows fucked up totally when compiled with msvc 2012, so stick to 2010 if you cannot fix the code.
Productivity is a state of mind.
User avatar
revelator
 
Posts: 2593
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger


Return to Engine Programming

Who is online

Users browsing this forum: No registered users and 2 guests