Re: [GD-Windows] Strange float bug?
Brought to you by:
vexxed72
From: Brett B. <res...@ga...> - 2004-03-08 00:10:44
|
Thanks everybody for the info so far. Here is what I found in the = control word conditions and value: with no error =3D 0x037f where 0x033f =3D (_PC_64 | _EM_INVALID | = _EM_ZERODIVIDE | _EM_OVERFLOW | _EM_UNDERFLOW | _EM_INEXACT | = _EM_DENORMAL) and I can't seem to figure out where the last bit 6 comes = from???? when I get an error =3D 0x007f which means I lost precision down to = _PC_24. That doesn't seem enough to cause the problem though does it? The error gets generated practically anyplace if we try to do math, for = example: out.right.x =3D 1.0f - (yy + zz); where out.right.x is a vector, yy =3D 0.0f and zz =3D 0.0f. thus I'm getting: -nan =3D 1.0f - (0.0f + 0.0f); Given the control word and the line above, is this the expected = behavior? Thanks, Brett ----- Original Message -----=20 From: "Simon O'Connor" <si...@sc...> To: <gam...@li...> Sent: Monday, March 08, 2004 12:17 AM Subject: RE: [GD-Windows] Strange float bug? >=20 > Hi Brett, >=20 >=20 > 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 >=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))? >=20 >=20 > The "something" is likely to be a third party library... >=20 > ...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) >=20 > 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. >=20 > 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. >=20 > 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. >=20 >=20 > Unmasking FP exceptions can be handy during debugging for trapping = things > like domain errors at source too IMO. >=20 >=20 > Cheers, >=20 > Simon O'Connor > Programmer @ Acclaim > & Microsoft DirectX MVP=20 >=20 >=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 >=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 >=20 >=20 >=20 > ------------------------------------------------------- > This SF.Net email is sponsored by: IBM Linux Tutorials > Free Linux tutorial presented by Daniel Robbins, President and CEO of > GenToo technologies. Learn everything from fundamentals to system > administration.http://ads.osdn.com/?ad_id=1470&alloc_id638&op=CCk > _______________________________________________ > Gamedevlists-windows mailing list > Gam...@li... > https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_idU5 |