1. Nightfox_

    OP Nightfox_ Member
    Newcomer

    Joined:
    Jun 4, 2018
    Messages:
    40
    Country:
    Australia
    I'm working with SDL on Switch and I can't seem to get SDL Timers to work.

    When the equivalent code is compiled for PC, the timer works perfectly

    Code:
    int testNumber = 0;
    
    Uint32 my_callbackfunc(Uint32 interval, void *param)
    {
        TRACE("The timer has now called this function");
        testNumber++;
        return(interval);
    }
    
    int main(int argc, char* argv[])
    {
        SDL_Init(SDL_INIT_TIMER);
        SDL_TimerID timer = SDL_AddTimer(1000,my_callbackfunc,NULL);
        // Set mesa configuration (useful for debugging)
        setMesaConfig();
    
        // Initialize EGL on the default window
        if (!initEgl(nwindowGetDefault()))
            return EXIT_FAILURE;
    
        // Load OpenGL routines using glad
        gladLoadGL();
    
        // Initialize our scene
        sceneInit();
    
        // Main graphics loop
        while (appletMainLoop())
        {
            TRACE("%d",narmba);
            // Get and process input
            hidScanInput();
            u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
            if (kDown & KEY_PLUS)
                break;
    
            // Render stuff!
            sceneRender();
            eglSwapBuffers(s_display, s_surface);
        }
    
        // Deinitialize our scene
        sceneExit();
    
        // Deinitialize EGL
        deinitEgl();
        return EXIT_SUCCESS;
    }
    my_callbackfunc() should be called every second, but it doesn't even get called once when running on Switch. But when doing the same thing for PC, the timer works fine.

    Is there an extra step that needs to be done for Switch SDL timers or is the SDL library buggy?

    Thanks
     
  2. cpasjuste

    cpasjuste GBAtemp Maniac
    Member

    Joined:
    Aug 27, 2015
    Messages:
    1,084
    Country:
    France
    Hi, i "guess" it should work, but didn't test it like that. It may be an issue, but I won't be able to test soon. You can add an issue on github so I take a closer look as soon as possible (https://github.com/devkitPro/SDL/tree/switch-sdl2).
    Also, for timers to work you may need to init video? I think its the case on most distribution?
     
    Last edited by cpasjuste, Jan 6, 2019
  3. Nightfox_

    OP Nightfox_ Member
    Newcomer

    Joined:
    Jun 4, 2018
    Messages:
    40
    Country:
    Australia
    It doesn't work either for my main project which does init video, audio and joysticks too. Also the PC build of that SDL Timer testing program above works fine just initialising timer.

    I'll add an issue to github thanks :)

    — Posts automatically merged - Please don't double post! —

    Hmm the issues section is missing on the github page. Have public issues been disabled for that repository?
     
  4. cpasjuste

    cpasjuste GBAtemp Maniac
    Member

    Joined:
    Aug 27, 2015
    Messages:
    1,084
    Country:
    France
    I think you need to select the master branch.
     
  5. Nightfox_

    OP Nightfox_ Member
    Newcomer

    Joined:
    Jun 4, 2018
    Messages:
    40
    Country:
    Australia
    Issues tab still missing on master branch
     

    Attached Files:

  6. cpasjuste

    cpasjuste GBAtemp Maniac
    Member

    Joined:
    Aug 27, 2015
    Messages:
    1,084
    Country:
    France
    Took a quick look today, unfortunately i didn't find the problem yet... :/
     
  7. cpasjuste

    cpasjuste GBAtemp Maniac
    Member

    Joined:
    Aug 27, 2015
    Messages:
    1,084
    Country:
    France
    Hi, this will be fixed in next sdl2 release (which should come very soon) :)
     
    hippy dave likes this.
  8. cpasjuste

    cpasjuste GBAtemp Maniac
    Member

    Joined:
    Aug 27, 2015
    Messages:
    1,084
    Country:
    France
    Hi @Nightfox_ , fixed sdl2 is now available via pacman.
     
    Nightfox_ and hippy dave like this.
  9. Nightfox_

    OP Nightfox_ Member
    Newcomer

    Joined:
    Jun 4, 2018
    Messages:
    40
    Country:
    Australia
    You are an absolute legend. Thank you.
     
  10. Nightfox_

    OP Nightfox_ Member
    Newcomer

    Joined:
    Jun 4, 2018
    Messages:
    40
    Country:
    Australia
    I can confirm that SDL Timers work correctly now and that my game port is fully playable now. Just ironing out some bugs before release
     
    hippy dave likes this.
  11. Nightfox_

    OP Nightfox_ Member
    Newcomer

    Joined:
    Jun 4, 2018
    Messages:
    40
    Country:
    Australia
    hippy dave and cpasjuste like this.
Draft saved Draft deleted
Loading...

Hide similar threads Similar threads with keywords - SDL_Timers, working, Switch