Results 1 to 8 of 8

Thread: Problems using SDLInput.pas :(

  1. #1

    Problems using SDLInput.pas :(

    Hi all,
    I am trying to use SDLInput.pas for my PGDAnnual2009 entry and am having some issues...

    I am using a TSDLInputManager class that I have already created like so:

    [pascal]InputManager := TSDLInputManager.Create([itJoystick , itKeyBoard, itMouse]);[/pascal]

    Issue #1 I have tried enabling all three input types (joystick, keyboard and mouse) using this code:

    [pascal]InputManager.Enable([itJoystick,itKeyBoard,itMouse]);[/pascal]

    but it crashes and gives me an error dialog box:

    Project DayOfDestruction.exe raised exception class EListError with message 'List index out of bounds (0)'. Process stopped. Use Step or Run to continue.
    Would this be because I don't have a joystick attached to my system?

    I would have thought that the code would have done some error checking behind the scenes...

    it seems I can fix it using this code instead as a workaround:

    [pascal] If InputManager.JoyStick.NumOfJoySticks > 0 Then
    InputManager.Enable([itJoystick,itKeyBoard,itMouse])
    Else
    InputManager.Enable([itKeyBoard,itMouse]);[/pascal]

    But I don't think I should have to do this myself

    Issue #2 I am trying to detect keypresses using the keyboard input manager like so:

    [pascal]InputManager.KeyBoard.OnKeyUp := OnKeyUp;[/pascal]

    Where the OnKeyUp method is this:

    [pascal]Procedure TGame.OnKeyUp(var Key: TSDLKey; Shift: TSDLMod; unicode : UInt16);
    Begin
    If Key = SDLK_ESCAPE Then ExitApplication;
    End;[/pascal]

    but it is never being called for some reason...

    As you can see from the code below the update method of the InputManager is being called ok in my main SDL loop:

    [pascal]Procedure TSDLApplication.Run(Const AWidth,AHeight,ADepth : Uint32;
    Const AFullScreen : Boolean);
    Const
    cLockFPS = 60;
    cMinTimeSlice = Round(1/cLockFPS);
    cMaxTimeSlice = 1;
    Var
    event : TSDL_Event;
    TimeSlice : Single;
    FPS : Single;
    Begin
    FWidth := AWidth;
    FHeight := AHeight;
    FDepth := ADepth;
    FFullScreen := AFullScreen;
    Try
    If Not Initialize Then Exit;
    FTimer.Init;

    TimeSlice := cMinTimeSlice;
    FFinished := False;
    While Not FFinished Do
    Begin
    FInputManager.UpdateInputs(event);
    If SDL_MustLock(FVideoBuffer) Then
    SDL_LockSurface(FVideoBuffer);

    FPS := FTimer.GetFPS;
    ProcessFrame(TimeSlice,FPS,FFinished);

    If SDL_MustLock(FVideoBuffer) Then
    SDL_UnlockSurface(FVideoBuffer);

    Case FOpenGLEnabled Of
    False : SDL_Flip(FVideoBuffer);
    True : SDL_GL_SwapBuffers;
    End;

    TimeSlice := FTimer.GetElapsedSeconds;
    FTimer.LockFPS(cLockFPS);
    End;
    Finally
    Cleanup;
    End;
    End;[/pascal]

    Any ideas?

    cheers,
    Paul

  2. #2

    Re: Problems using SDLInput.pas :(

    Nevermind...I figured it out

    I somehow deleted the SDL_PollEvent() call out of the code so no events were being read from SDL!! D'OH!

    [pascal]While SDL_PollEvent(@event) = 1 Do FInputManager.UpdateInputs(event);[/pascal]

    It is now working...

    cheers,
    Paul

  3. #3

    Re: Problems using SDLInput.pas :(

    I'm still wondering about issue#1 though - the crash if no joystick is available...

    Not sure why it was programmed that way...

    cheers,
    Paul

  4. #4

    Re: Problems using SDLInput.pas :(

    bump?

  5. #5

    Re: Problems using SDLInput.pas :(

    In some way it makes sense to only enable things that actualy are available ...
    http://3das.noeska.com - create adventure games without programming

  6. #6

    Re: Problems using SDLInput.pas :(

    I don't like these kind of things either. It's better to just return an error code than a crash.

    The actual error looks very "Delphi-ish" and seems to be generated by the TSDLInputManager wrapper class. If you have the source, you could debug that yourself Just temporarly add the unit that contains TSDLInputManager to your project and step through the code using the debugger. It's probably just a matter of adding/tweaking an IF statement.

    If you don't have the source, you can ask the people who are maintaining JEDI-SDL.
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  7. #7

    Re: Problems using SDLInput.pas :(

    You should be able to do the following:

    Code:
    if (SDL_Init(SDL_INIT_JOYSTICK) < 0) then
     InputManager := TSDLInputManager.Create([itJoystick , itKeyBoard, itMouse])
    else
     InputManager := TSDLInputManager.Create([itKeyBoard, itMouse]);
    The problem is that that TSDLInputManager will throw an error if you try to init something that doesn't exist. It's an oddity of the pascal wrappers (and one that I personally don't like). To avoid things like this, try using the SDL interface directly instead of using the wrapper objects.

  8. #8

    Re: Problems using SDLInput.pas :(

    Thanks all for the hints/tips

    I may just stick with the code I have now:

    [pascal]If InputManager.JoyStick.NumOfJoySticks > 0 Then
    InputManager.Enable([itJoystick,itKeyBoard,itMouse])
    Else
    InputManager.Enable([itKeyBoard,itMouse]); [/pascal]

    cheers,
    Paul

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
  •