Please do not post a support request without first reading and following the advice in https://retropie.org.uk/forum/topic/3/read-this-first

sdltrs: display of typed characters lags keyboard, sometimes permanently by one character


  • Hi,

    as the current maintainer of sdl2trs I've experienced nearly the same issue with Wayland. Please try the attached patch and test if this fixes it also on the Pi4 ...

    diff --git a/src/trs_sdl_interface.c b/src/trs_sdl_interface.c
    index b0dbfe4..a2c8734 100644
    --- a/src/trs_sdl_interface.c
    +++ b/src/trs_sdl_interface.c
    @@ -1508,6 +1508,7 @@ void trs_sdl_flush(void)
       }
     
       SDL_UpdateTexture(texture, NULL, screen->pixels, screen->pitch);
    +  SDL_RenderClear(render);
       SDL_RenderCopy(render, texture, NULL, NULL);
       SDL_RenderPresent(render);
     
    @@ -1716,9 +1717,7 @@ void trs_get_event(int wait)
             break;
           case SDL_WINDOWEVENT:
             if (event.window.event & SDL_WINDOWEVENT_RESIZED) {
    -          SDL_RenderClear(render);
    -          SDL_RenderCopy(render, texture, NULL, NULL);
    -          SDL_RenderPresent(render);
    +          drawnRectCount = MAX_RECTS;
             }
             if (event.window.event & SDL_WINDOWEVENT_EXPOSED) {
               SDL_FlushEvent(SDL_KEYDOWN);
    
  • Global Moderator

    @JenGun thanks for stopping by !

    The patch does fix the issue.

    My temporary workaround that I found was to force trs_sdl_flush to redraw, by ignoring the drawnRectCount check (which seems to work also, but obviously not correct) and my next step was to investigate why the check fails - in some cases - with KMSDRM.


  • @mitu I'll give that patch a shot as well.

    I do have one question about such things in general: what's the best way to pull down the source, compile it, and put the resulting binary into play? For atari800, I simply hit ctrl-c while it was in the middle of compiling during an "install from source" operation within retropie_setup.sh, then moved the directory and was from that point able to make my changes, compile them up, and manually install the resulting binary over the one on the system.

    But that seems a bit excessive. My hope is that you have some well-defined method for doing these things that isn't quite as involved.

  • Global Moderator

    @n2185x said in sdltrs: display of typed characters lags keyboard, sometimes permanently by one character:

    But that seems a bit excessive. My hope is that you have some well-defined method for doing these things that isn't quite as involved.

    You can use retropie_packages.sh to run each scriptmodule helper methods:

    # download sources & apply local patches
    sudo ./retropie_packages.sh sdltrs sources
    
    # build
    sudo ./retropie_packages.sh sdltrs build
    
    # install 
    sudo ./retropie_packages.sh sdltrs install
    
    # configure 
    sudo ./retropie_packages.sh sdltrs configure
    

    Or you can just clone the upstream repository (the sdl2 branch) and build it manually, then copy sdl2trs to /opt/retropie/emulators/sdltrs.


  • @mitu Fantastic, that's exactly what I was looking for.

    I can confirm that the patch works brilliantly.

    This forum is awesome.


  • @mitu Thanks for testing and adding sdl2trs to RetroPie! :-)

    My temporary workaround that I found was to force trs_sdl_flush to redraw, by ignoring the drawnRectCount check (which seems to work also, but obviously not correct) and my next step was to investigate why the check fails - in some cases - with KMSDRM.

    That was also my first try, but the emulator screen was not redrawn after leaving the TextGUI. It will also burn some CPU cycles ... ;-)

    Sometimes the screen is not updated in Wayland after resizing, but for now the patch is committed: https://gitlab.com/jengun/sdltrs/-/commit/a817f5e817db7166a4654fa735a4abb848534a45


  • @JenGun Thanks very much for showing up with a fix. This is excellent.

    It does raise a question, however: does the change actually qualify as a fix to a bug in sdl2trs, or is this a workaround to a bug that is elsewhere?

    I think it's at least somewhat important. If you read my comments above, you'll see that a similar issue occurs with respect to the hatari gui. This suggests that the real bug is downstream of sdl2trs. It might be in SDL itself, or it might even be downstream of that. No idea. As long as the fix here is benign then it's all good, but if there's any way to use this to discover where the real bug is, it might be worth pursuing.

    Thanks again for the fix, it's greatly appreciated!


  • @n2185x

    It does raise a question, however: does the change actually qualify as a fix to a bug in sdl2trs, or is this a workaround to a bug that is elsewhere?

    Good question ... I would cautiously refer to it as a "workaround": the error only seems to occur on a few systems and why RenderClear fixes it is not entirely clear to me ... maybe this will flush the render command queue ...

    Something similar happens here on another machine: the SDL window turns completely white after a few seconds. An old version (SDL 2.0.9) fixes the problem ... with newer versions a superfluous SDL_RenderDrawPoint is needed after SDL_UpdateTexture ...

    In hatari the RenderClear command is also "missing", so the fix might also apply:

    diff --git a/src/screen.c b/src/screen.c
    index 32765a48..a609ca34 100644
    --- a/src/screen.c
    +++ b/src/screen.c
    @@ -115,6 +115,7 @@ void SDL_UpdateRects(SDL_Surface *screen, int numrects, SDL_Rect *rects)
            if (bUseSdlRenderer)
            {
                    SDL_UpdateTexture(sdlTexture, NULL, screen->pixels, screen->pitch);
    +               SDL_RenderClear(sdlRenderer);
                    SDL_RenderCopy(sdlRenderer, sdlTexture, NULL, NULL);
                    SDL_RenderPresent(sdlRenderer);
            }
    
  • Global Moderator

    @JenGun this does seem to improve things, at least for the Hatari menu. For the record, RetroPie includes libSDL2 2.0.10.


  • @mitu It makes the SDL GUI work in Wayland. Replacing SDL_RenderClear with SDL_RenderDrawPoint also seems to fix the issue ...


  • Global Moderator

    @JenGun Thank you for submitting the patch. We may have to include it locally before a new Hatari release.

  • administrators

    @mitu the last release was some time ago (2019 afair) so I was going to maybe try out git HEAD version. But maybe a new release will be out soon also and we can just do a patch.


  • @mitu Sorry, the URL was malformed. They use SDL_RenderClear only for hardware accelerated cards to avoid the problem. If the Renderer falls back to SW rendering (for whatever reason), it will break again ...


  • @BuZz

    But maybe a new release will be out soon also and we can just do a patch.

    Seems they are preparing to release version 2.3 ...

Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.

Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.