Quote Originally Posted by michalis
The answer is simple: you shouldn't use GL and GLU units from jedi-sdl when compiling under FPC. See the "FPC and SDL" wiki page http://www.freepascal.org/wiki/index.php/FPC_and_SDL and especially my reply in section "unitpath in fpc.cfg" on the discussion page: http://www.freepascal.org/wiki/index...lk:FPC_and_SDL. The problem is described there, and the summary is: GL and GLU from jedi-sdl should be used only for Delphi/Kylix, and with FPC you should use the GL/GLU units provided in it's distribution.

So the proper solution to your problem is just to remove gl.pas and glu.pas from your project directory (and make sure that jedi-sdl OpenGL dir is nowhere on FPC units path). As soon as FPC uses it's own GL/GLU units, the problem is fixed, no segfaults. And FPC OpenGL units are compatible enough to let you write the same code and have it compiled under both FPC and Delphi.

Alternatively, you could put $ifdef FPC and use the following FPC version of gluUnProject in GLU unit:

[pascal]
gluUnProject: function(winx, winy, winz: GLdouble; var modelMatrix, projMatrix: T16dArray; var viewport: TViewPortArray; objx, objy, objz: PGLdouble): Integer;
{$IFDEF WIN32}stdcall;{$ELSE}cdecl;{$ENDIF}
[/pascal]

(I actually pasted the first declaration line from FPC glu sources). But that's bad solution. Like I said: the proper solution is just to let FPC use it's own GL/GLU units.

Note: this is not a bug of FPC, neither a bug of Delphi. All Pascal compilers have some freedom to choose when parameters are passed by value and when by reference --- in this case Delphi was more willing to pass parameters by reference than FPC. GPC has construction to explicitly force constant paremeters being passed by reference, but neither FPC nor Delphi implement them.

Jedi-sdl people: could you add something like

[pascal]
{$ifdef FPC}
{$fatal This unit shouldn't be used with FPC. Instead you should use the FPC own OpenGL units.}
{$endif}
[/pascal]

inside your gl and glu units ? This would avoid these problems.
thanks for all the hints michalis

I will read those posts :-)

cheers,
Paul.