Results 1 to 3 of 3

Thread: BUG: SDL_AddTimer doesn't work in Lazarus/FPC?

  1. #1

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

    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:
    Code:
    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?

  2. #2

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

    But you didn't forget "SDL_Init(SDL_INIT_TIMER);" right in the beginning, did you?

  3. #3

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

    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •