PDA

View Full Version : Bug with JEDI-SDL and lighting



{MSX}
07-04-2005, 07:53 AM
Ok, i've this nasty bug. I have a program with JEDI-SDL and OpenGL, running on windows and linux.
The bug happends only when i compile the program on windows with FPC (any 1.9.x version). With Delphi or on linux (both kylix and fpc) the bug disappears.
The problem is that when i try to render anything with GL_LIGHTING turned on, i have a EDivByZero exception. The exception starts inside OpenGl code, so i can't track it.
If i render with GL_LIGHTING disabled than it runs fine.
This happends almost in any program, for example it happends on lesson7 of JEDI-SDL version NeHe.

I've come to the conclusion that (maybe) it could be a bug in FPC for which it passes some malformed data to OpenGl (wich pass silently) but when rendering it gets DivByZero.

Anyone experienced this too ? If it's needed i'll post executables this evening.

Here's the output:


An unhandled exception occurred at 0x08AD2593 :
EDivByZero : Division by zero
$08AD2593
$0896A4A4
$00080100
$18FF3635
An unhandled exception occurred at 0x004156DA :
EAccessViolation : Access violation
$004156DA
$00416B84
$0006FF44
$0896A4A4
$00080100
$24FF1C1B
An unhandled exception occurred at 0x004156DA :
EAccessViolation : Access violation
$004156DA
$00416B84
$0006FCD4
$00416B84
$0006FF44
$0896A4A4
$00080100
$24FF1C1B
An unhandled exception occurred at 0x004156DA :
EAccessViolation : Access violation
$004156DA
$00416B84
$0006FA64
$00416B84
$0006FCD4
$00416B84
$0006FF44
$0896A4A4
$00080100
$24FF1C1B

Sly
07-04-2005, 10:56 AM
Do you mask FPU exceptions? Try adding this code to one of your units.

var
Saved8087CW: Word;

{$ifdef FPC} //FPC do not have this function in its RTL
const
Default8087CW = $1332; //according to the FPC site it's the value used in the
//startup code.
procedure Set8087CW( value :word ); Assembler;
asm
FLDCW value
end;
{$endif}


initialization
{ Save the current FPU state and then disable FPU exceptions }
Saved8087CW := Default8087CW;
Set8087CW($133f); { Disable all fpu exceptions }

finalization
{ Reset the FPU to the previous state }
Set8087CW(Saved8087CW);

{MSX}
07-04-2005, 12:08 PM
I can't compile, it says:


TestUnit.pas(19,11) Error: Asm: [fldcw reg16] invalid combination of opcode and
operands
TestUnit.pas(33,1) Fatal: There were 1 errors compiling module, stopping


Is there some compiler directive to enable somewhere ?

BTW What does this code do? And is it already present in Delphi ? And about Linux ?

Thanks!

{MSX}
07-04-2005, 12:48 PM
Ok, i've found by myself.. Btw Savege had the same problem (http://community.freepascal.org:10000/bboard/q-and-a-fetch-msg.tcl?msg_id=0001Hc&topic_id=11&topic=Free%20Pascal%20and%20assembler%20code) :P Thank you savage :)

It now works with light. I still don't understand why is this needed.. Does Opengl continuosly rise error on the FPU ?

Btw now i have the same problem when i exit from the program... meybe restoring the value can cause the error?

savage
07-04-2005, 05:23 PM
Hi MSX, I thought I had some floating point switch code in one the JEDI-SDL units that worked with Delphi and FPC. I will have to check it when I get home.

Sly
07-04-2005, 09:39 PM
That code was copied from fmod.pas. I believe it was Dominique who added the FPC code into it. :)

Borland compilers do not mask FPU exceptions by default. Microsoft compilers do. When working with 3D APIs such as Direct3D and OpenGL, it is often helpful to mask FPU exceptions.