sdltrs: display of typed characters lags keyboard, sometimes permanently by one character
-
@mitu I downloaded the Pi 3 version of RetroPie and put it onto a Pi 3 B+. I then performed a full update of it, then installed sdltrs via retropie_setup.sh (from binaries), then copied over all of the .rom files in the BIOS directory from my Pi 4 as well as the entirety of the trs-80 subdirectory of the "roms" directory. In short, everything on the Pi 3 is identical to how it is on the Pi 4.
The issue does not reproduce on the Pi 3, which means this is almost certainly an SDL2 issue or graphics driver issue (or something else that is specific to the Pi 4). And seeing how plenty of other emulators work just fine, I'm skeptical to the point of disbelief that it's a graphics driver issue.
-
My test was a bit simpler (haven't got to test on a Pi3) - I started the emulator from a desktop session and the issue is gone. The difference between the 2 cases is the different input and video driver - when starting from the desktop, it uses X11 input and video, without it relies on the KMS/DRM video and input drivers.
It's a bit difficult to pin it down to an particular (or obvious) SDL2 issue, since other emulators don't exhibit the same behavior when using the same video/input drivers (i.e.
vice
for C64,openmsx
for MSX,scummvm
, etc.)EDIT: a similar issue/behavior was reported for 'draStic', the Nintendo DS emulator, but we couldn't find a proper solution since it's a closed source application. At least for
sdl2trs
the source is available, so it's a starting point in trying to find the root cause of this behavior. -
@mitu I wouldn't know where to begin with respect to tracking this down, as I have no familiarity with any of the code involved here. But I am happy to help however I can, and would really like to see this tracked down and fixed.
-
Hi,
as the current maintainer of
sdl2trs
I've experienced nearly the same issue withWayland
. 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);
-
@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 thedrawnRectCount
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.
-
@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 copysdl2trs
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 thedrawnRectCount
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!
-
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 afterSDL_UpdateTexture
...In
hatari
theRenderClear
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); }
-
@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
. ReplacingSDL_RenderClear
withSDL_RenderDrawPoint
also seems to fix the issue ... -
The issue in
hatari
is also fixed upstream:
https://github.com/hatari/hatari/commit/191a35fe24b340be143e9a368698123cdf0280b7 -
@JenGun Thank you for submitting the patch. We may have to include it locally before a new Hatari release.
-
@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 ... -
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.