Where are you running this code that crashes?
You need to tell the compiler that this is a console Application otherwise the calls to *writeln* will AV. Which is what I am seeing.
The following works for me on Windows.
[pascal]
program Thread;
{$APPTYPE CONSOLE}
uses
sdl;
var
thread : PSDL_Thread;
returnValue : Integer;
function thread_func( aData : pointer ) : integer; cdecl;
begin
// do threading here
WriteLn( 'Start Thread' );
SDL_Delay( 5000 );
WriteLn( 'End Thread' );
result := 1; // thread leaves and return this value
end;
begin
returnValue := 0;
thread := SDL_CreateThread( @thread_func, nil );
SDL_WaitThread( thread, returnValue );
WriteLn( 'Thread returns code ', returnValue );
SDL_Quit;
WriteLn( 'ByeBye ' );
end.
[/pascal]
On other platforms you may have to specifcy the *cdecl* call and the pointer parameter as well to avoid the AV.
As for timers, the following example works for me....
[pascal]
program SDLTimers;
{$APPTYPE CONSOLE}
uses
SysUtils,
sdl;
var
Timer1 : PSDL_TimerID;
Timer2 : PSDL_TimerID;
Param1 : Integer;
Param2 : Integer;
function CallTimer1( interval : UInt32; param : Pointer ) : UInt32; cdecl;
var
pParam : PInteger;
begin
pParam := PInteger( param );
WriteLn( 'Parameter = ' + IntToStr( pParam^ ) + ' in CallTimer1' );
Result := interval;
end;
function CallTimer2( interval : UInt32; param : Pointer ) : UInt32; cdecl;
var
pParam : PInteger;
begin
pParam := PInteger( param );
WriteLn( 'Parameter = ' + IntToStr( pParam^ ) + ' in CallTimer2' );
Result := interval;
end;
begin
if ( SDL_Init( SDL_INIT_TIMER ) <> 0 ) then
WriteLn( 'Cannot initalize SDL' );
// Adding Timers
WriteLn( 'Adding Timers +' );
Param1 := 12;
Param2 := 15;
Timer1 := SDL_AddTimer( 500, CallTimer1, @Param1 );
Timer2 := SDL_AddTimer( 1200, CallTimer2, @Param2 );
WriteLn( 'SDL_Delay 30 secs, so we can see the timers in operation' );
SDL_Delay( 30000 );
WriteLn( 'Removing Timers -' );
SDL_RemoveTimer( Timer2 );
SDL_RemoveTimer( Timer1 );
WriteLn( 'Ciao ' );
ReadLn;
SDL_Quit;
end.
[/pascal]
Does it work for you?
Bookmarks