TimerCallback crash with Linux

Hi there,

I am developing a small game with FreePascal (FP for short) and SDL. While trying to support multiple platforms
I ran into a problem with SDL_AddTimer. I reduced my code to the core problem (see below) to find out what’s wrong.

In Win32 the executables (FP and C) run as expected. But when I compile the same code under Linux only the C binary
will run while the FP binary crashes at the first call to the timer callback function:

Starting…
SDL_AddTimer: Success!
Waiting 8 seconds…
An unhandled exception occurred at $08055A31 :
Exception : Unknown Run-Time error : 202
$08055A31
$08048472
$40036544
$4006638A
$4003615B
$400638CF
$400B9E51

I am using FreePascal 2.0.2 with SDL 1.2.10 (i.e. libSDL-1.2.so.0.7.3) on Debian.
Using JEDI-SDLv1.0 or SDL4FreePascal leads to same crash.

Any help appreciated.

Sascha

//------------------------------------------------------------------------------
// C code
//------------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include “SDL/SDL.h”

Uint32 timer_func(Uint32 interval, void *parameter)
{
printf (“timer interval: %d ms\n”, interval);
return (interval-1000);
}

int main (void)
{
SDL_TimerID MyTimer;

printf(“Starting…\n”);

if (SDL_Init(SDL_INIT_TIMER) < 0)
{
printf(“Kann SDL nicht initialisieren: %s\n”, SDL_GetError());
exit(1);
}
atexit(SDL_Quit);

// Now add timer
MyTimer = SDL_AddTimer(3000, timer_func, NULL);
if (MyTimer == NULL)
{
printf(“SDL_AddTimer: Error!\n”);
exit(1);
}
atexit(SDL_Quit);
printf (“SDL_AddTimer: Success!\n”);

// just wait
printf(“Waiting 8 seconds…\n”);
SDL_Delay( 8000 );

// Release
SDL_Quit;
printf(“ByeBye ;)\n”);

return(0);
}

//------------------------------------------------------------------------------
// PASCAL code
//------------------------------------------------------------------------------
program timer;

{$mode objfpc}

uses
sysutils,
sdl_timer, sdl_types, // SDL4FP //
sdl;

var
//JEDI//_Timer: PSDL_TimerID;
_Timer: SDL_TimerID; // SDL4FP //

function timer_func(Interval: Uint32; Param: Pointer): Uint32; cdecl;
begin
Writeln(‘timer interval: ’ + IntToStr(Interval) + ’ ms’);
Result := Interval-1000;
end;

begin
Writeln(‘Starting…’);

// Init SDL and timer
if SDL_Init(SDL_INIT_TIMER) < 0 then
begin
Writeln(‘SDL_Init: Error!’);
Exit;
end;

// Now add timer
_Timer := SDL_AddTimer( 3000, @timer_func, nil );
if _Timer = nil then
begin
Writeln(‘SDL_AddTimer: Error!’);
Exit;
end;
Writeln(‘SDL_AddTimer: Success!’);

// just wait
Writeln(‘Waiting 8 seconds…’);
SDL_Delay( 8 * 1000 );

// Release
SDL_Quit;
WriteLn(‘ByeBye ;)’);
end.

Viel oder wenig? Schnell oder langsam? Unbegrenzt surfen + telefonieren
ohne Zeit- und Volumenbegrenzung? DAS TOP ANGEBOT JETZT bei Arcor: g?nstig
und schnell mit DSL - das All-Inclusive-Paket f?r clevere Doppel-Sparer,
nur 44,85 ? inkl. DSL- und ISDN-Grundgeb?hr!
http://www.arcor.de/rd/emf-dsl-2