PDA

View Full Version : BUG: SDL_AddTimer doesn't work in Lazarus/FPC?



jdarling
05-02-2009, 10:07 PM
While playing with my Sidescroller I decided I should put the physics into their own thread via an SDL timer. I was amazed when it didn't work :(

Here is the base code for reference:

unit uCollisionEngine;

{$mode objfpc}{$H+}

interface

uses
Classes, SysUtils, uApeEngine;

var
APE : TApeEngine;

procedure InitCollisionEngine;

implementation

uses
uVector, sdl, uDebugger;

var
engineSDLTimer : PSDL_TimerID;

function CEngine_Timer( interval: UInt32; param: Pointer ): UInt32; cdecl;
begin
APE.Step;
Debug('CEngine_Timer called');
result := interval;
end;

procedure InitCollisionEngine;
begin
if assigned(engineSDLTimer) then
exit;
engineSDLTimer := SDL_AddTimer(100, @CEngine_Timer, nil);
end;

initialization
APE := TApeEngine.Create;
APE.Init(0.1);
APE.AddMasslessForce(Vector(0,3));
APE.ConstraintCycles := 10;
engineSDLTimer := nil;

finalization
if assigned(engineSDLTimer) then
SDL_RemoveTimer(engineSDLTimer);
APE.Free;

end.


After calling InitCollisionEngine engineSDLTimer is still NIL and the CEngine_Timer function never gets called.

Any ideas?

waran
06-02-2009, 12:38 AM
But you didn't forget "SDL_Init(SDL_INIT_TIMER);" right in the beginning, did you?

jdarling
06-02-2009, 03:22 AM
Bloody hell! I shoulda known it was that I pulled a stupid instead of a bug :) Thanks for the pointer!

Oh well, consider this one closed on the account of stupidity.