Avoiding Compiler Screwups?

Discuss programming topics for the various GPL'd game engine sources.
Post Reply
Baker
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Avoiding Compiler Screwups?

Post by Baker »

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 ..
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: Avoiding Compiler Screwups?

Post by Spike »

bugs like that suggest that you're not initialising something properly.
try valgrind.
qbism
Posts: 1236
Joined: Thu Nov 04, 2004 5:51 am
Contact:

Re: Avoiding Compiler Screwups?

Post by qbism »

Pentium optimizations can have errors related to FP precision. Anything below P4/ss3 or thereabouts
Baker
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Re: Avoiding Compiler Screwups?

Post by Baker »

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 ..
Baker
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Re: Avoiding Compiler Screwups?

Post by Baker »

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 ..
qbism
Posts: 1236
Joined: Thu Nov 04, 2004 5:51 am
Contact:

Re: Avoiding Compiler Screwups?

Post by qbism »

Separate packet update rate from refresh rate?
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: Avoiding Compiler Screwups?

Post by Spike »

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).
Baker
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Re: Avoiding Compiler Screwups?

Post by Baker »

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 ..
revelator
Posts: 2621
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Re: Avoiding Compiler Screwups?

Post by revelator »

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.
Post Reply