RE: [GD-Windows] Strange float bug?
Brought to you by:
vexxed72
From: Simon O'C. <si...@sc...> - 2004-03-07 16:25:02
|
Hi Brett, Personally, almost every NaN I've ever encountered has been due to = something earlier on such as passing out of domain values to trig functions, = divisions by zero, square roots of negatives etc.=20 However, the fact that resetting the FPU control word to its default = fixes the problem hints that something else is changing it behind your back. = What value is the control word set to when the NaN occurs (_controlfp(0,0))? The "something" is likely to be a third party library... ...What immediately springs to mind is if you're using Direct3D and also using double precision floating point anywhere (probably unwittingly - = evil things as you'll know from your PS2 experience :o) IDirect3D*::CreateDevice() changes the control word so that the FPU uses 24bit mantissa precision (_PC_24) rather than the default 53bit = precision (_PC_53). It also (re)masks FP exceptions (which is the _controlfp() default, but it'll re-mask them if you'd unmasked them). It does this = for performance reasons. If you use double precision values in your code with _PC_24 you'll = likely get denormals, under/over flows and generally unexpected behaviour. If = you force the control word back to default, you might get unexpected = behaviour from D3D too. If you really need double precision or exceptions unmasked, you can pass = the D3DCREATE_FPU_PRESERVE flag to CreateDevice() - it will impact = performance slightly though since it makes D3D save, change and restore the control = word for every call that might change the control word. Unmasking FP exceptions can be handy during debugging for trapping = things like domain errors at source too IMO. Cheers, Simon O'Connor Programmer @ Acclaim & Microsoft DirectX MVP=20 > -----Original Message----- > From: gam...@li...=20 > [mailto:gam...@li...] On=20 > Behalf Of Brett Bibby > Sent: 07 March 2004 13:39 > To: Gam...@li... > Subject: [GD-Windows] Strange float bug? >=20 > We have been tracking down the wierdest bug for several days.=20 > Our code was crashing randomly and then we finally found a=20 > repeatable case where an assert on an identity matrix when we=20 > check the orthonormalness of it and we chanced upon a line of=20 > code that returned -nan that was simply x =3D (1.0f - (a + b)).=20 > Anyway, I suddenly remembered a GDC talk about Windows=20 > denormals, did a quick google and pasted a _controlfp(=20 > _CW_DEFAULT, 0xfffff ) into our code and presto it now works. >=20 > We make games for PS2 and GCN and are Windows amateurs, but I=20 > hate the idea of not understanding what went wrong and how to=20 > properly handle this. Has anybody ever encountered something=20 > like this before? >=20 > Brett >=20 >=20 >=20 > ------------------------------------------------------- > This SF.Net email is sponsored by: IBM Linux Tutorials Free=20 > Linux tutorial presented by Daniel Robbins, President and CEO=20 > of GenToo technologies. Learn everything from fundamentals to=20 > system = administration.http://ads.osdn.com/?ad_id=1470&alloc_id638&op=3Dick > _______________________________________________ > Gamedevlists-windows mailing list > Gam...@li... > https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_idU5 >=20 > --- > Incoming mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.596 / Virus Database: 379 - Release Date: 26/02/2004 > =20 >=20 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.596 / Virus Database: 379 - Release Date: 26/02/2004 =20 |