Cleaning up NaNs in float3::*Normalize

Cleaning up NaNs in float3::*Normalize

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

Post Reply
imbaczek
Posts: 3629
Joined: 22 Aug 2006, 16:19

Cleaning up NaNs in float3::*Normalize

Post by imbaczek »

As you may have noticed, changing Normalize to use isqrt() caused a rather unpleasant side effect of spewing NaNs all over the place. After fixing several cases of that I've come to the conclusion that we need a cleaner fix for this, therefore I added a SafeNormalize() which does the zero vector check. Also, all normalizes now work safely when compiled without singaling NaNs.

I'm not completely sold on that idea, however, due to several reasons - it's not elegant, performance could be better without some checks, etc., so I had another idea, which was making the default Normalize always safe and instead adding another variant, UnsafeNormalize(). The problem is, we don't know which instances of Normalize can be safely made unsafe (well, at least I don't know :P).

Both solutions will require a cleanup of recently made commits, so I want to ask you about your opinions and/or other ideas.
imbaczek
Posts: 3629
Joined: 22 Aug 2006, 16:19

Re: Cleaning up NaNs in float3::*Normalize

Post by imbaczek »

PS. signaling-nans can also crash gfx drivers, apparently. happens to both nvidias and atis. beware.

i wonder how many "graphic driver bugs" have actually been caused by quiet nans in spring code.
zerver
Spring Developer
Posts: 1358
Joined: 16 Dec 2006, 20:59

Re: Cleaning up NaNs in float3::*Normalize

Post by zerver »

Edit: Please disregard this post, it turned out to be a MT related problem.

Possibly a nan left in TorpedoProjcectile (latest master):

float3.h LINE 441 assert(SqLength() > NORMALIZE_EPS);

Code: Select all

(gdb) bt full
#0  0x7c82860c in ntdll!LdrAlternateResourcesEnabled ()
   from C:\WINDOWS\system32\ntdll.dll
No symbol table info available.
#1  0x7739bf53 in WaitMessage () from C:\WINDOWS\system32\user32.dll
No symbol table info available.
#2  0x7739610a in USER32!DefDlgProcW () from C:\WINDOWS\system32\user32.dll
No symbol table info available.
#3  0x7738965e in USER32!ScrollWindowEx () from C:\WINDOWS\system32\user32.dll
No symbol table info available.
#4  0x7739f762 in USER32!SoftModalMessageBox ()
   from C:\WINDOWS\system32\user32.dll
No symbol table info available.
#5  0x7739f047 in USER32!MessageBoxTimeoutW ()
   from C:\WINDOWS\system32\user32.dll
No symbol table info available.
#6  0x7739eec9 in USER32!MessageBoxTimeoutW ()
   from C:\WINDOWS\system32\user32.dll
No symbol table info available.
#7  0x773d7d0d in USER32!MessageBoxTimeoutA ()
   from C:\WINDOWS\system32\user32.dll
No symbol table info available.
#8  0x773c42c8 in USER32!MessageBoxExA () from C:\WINDOWS\system32\user32.dll
No symbol table info available.
#9  0x773c42a4 in USER32!MessageBoxA () from C:\WINDOWS\system32\user32.dll
No symbol table info available.
#10 0x77bca3b4 in strerror () from C:\WINDOWS\system32\msvcrt.dll
No symbol table info available.
#11 0x77bc6b23 in msvcrt!_assert () from C:\WINDOWS\system32\msvcrt.dll
No symbol table info available.
#12 0x0056dc7e in CTorpedoProjectile::Update ()
No symbol table info available.
#13 0x00546918 in CProjectileHandler::UpdateProjectileContainer ()
No symbol table info available.
#14 0x0054a960 in CProjectileHandler::Update ()
No symbol table info available.
#15 0x0081c641 in CGame::SimFrame ()
No symbol table info available.
#16 0x0082d219 in CGame::ClientReadNet ()
No symbol table info available.
#17 0x00830b5f in CGame::Update ()
No symbol table info available.
#18 0x0044fd0f in SpringApp::Sim ()
No symbol table info available.
#19 0x009a47c0 in gmlClientServer<void, int, CUnit*>::gmlClientAux ()
No symbol table info available.
#20 0x00959067 in boost::(anonymous namespace)::thread_start_function ()
No symbol table info available.
#21 0x77bcb530 in msvcrt!_endthreadex () from C:\WINDOWS\system32\msvcrt.dll
No symbol table info available.
#22 0x77e6482f in KERNEL32!GetModuleHandleA ()
   from C:\WINDOWS\system32\kernel32.dll
No symbol table info available.
#23 0x00000000 in ?? ()
No symbol table info available.
Last edited by zerver on 27 Aug 2009, 13:08, edited 1 time in total.
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: Cleaning up NaNs in float3::*Normalize

Post by jK »

imbaczek wrote:performance could be better without some checks, etc.,
did you ever benchmarked this?
I don't think there is will be any noticeable change.
imbaczek
Posts: 3629
Joined: 22 Aug 2006, 16:19

Re: Cleaning up NaNs in float3::*Normalize

Post by imbaczek »

release build has all checks in place already, asserts are left in debug mode.
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: Cleaning up NaNs in float3::*Normalize

Post by jK »

still there are multiple places where it fails (e.g. camera)
Post Reply

Return to “Engine”