Skip to content

CRT switchres crash on raspberry pi 5 #19255

Description

@thetooth

Is there an existing issue for this?

  • This is a bug in RetroArch frontend
  • I have searched the existing issues

Description

Under any version enabling switchres under the gl driver causes segv in DRM driver. Have tried both native and super resolutions, even just regular old VGA modes crash.

Tried to deep dive this and found that in gfx_ctx_drm_swap_buffers, eglDestroySurface() is being called leaving the surface pointer not set to EGL_NO_SURFACE, later calls to egl_create_surface fail because it's expecting that deletion marker.

diff --git a/gfx/drivers_context/drm_ctx.c b/gfx/drivers_context/drm_ctx.c
index 78119d0..6383a1d 100644
--- a/gfx/drivers_context/drm_ctx.c
+++ b/gfx/drivers_context/drm_ctx.c
@@ -599,8 +599,7 @@ static void gfx_ctx_drm_swap_buffers(void *data)
             gbm_surface_release_buffer(drm->gbm_surface, drm->bo);
          if (drm->next_bo)
             gbm_surface_release_buffer(drm->gbm_surface, drm->bo);
-         egl_ctx_data_t *egl = &drm->egl;
-         eglDestroySurface(egl->dpy, egl->surf);
+         egl_destroy_surface(&drm->egl);
 
          gbm_surface_destroy(drm->gbm_surface);
       }

Unfortunately, this just creations another issue. For progressive resolutions switchres is working, but for anything with a frame buffer of 320x240 or similar results in drm->next_bo being null and crashing again.

Expected behavior

No response

Steps to reproduce the bug

./configure --enable-kms --enable-egl --enable-opengl --enable-opengl_core --enable-udev --enable-sdl2 --disable-x11 --disable-wayland
make DEBUG=1 SANITIZER=address,undefined -j"$(nproc)"
./retroarch

Version/Commit

master

Bisect Results

No response

Present in the nightly version

Yes, this is reproduced in the nightly build

Platform & operating system

Linux aarch64

Affected Cores

No response

Environment information

No response

Relevant log output

[INFO] [KMS] New FB: 720x480 (stride: 2880).
[INFO] [CRT] Requested resolution: 640x480@60.000000, orientation: normal.
[INFO] [CRT] Video context is: kms.
[INFO] [CRT] CRT mode: 2 - arcade_31.
[INFO] [CRT] SR rtn 0.
[INFO] [CRT] KMS context detected, keeping SR alive.
[DEBUG] [CRT] 640x480 rotation: 0 rotated: 0 core rotation:0
[INFO] Switchres: Calculating best video mode for 640x480@60.000000 orientation: normal
[INFO] Switchres: Modeline "640x480_60 31.500000KHz 60.000000Hz" 25.452000 640 664 760 808 480 491 493 525   -hsync -vsync
[DEBUG] [KMS] Mode details:  #0 RetroArch_CRT-640x480@60.00 60.00 640 664 760 808 480 491 493 525 25452
[DEBUG] [KMS] New mode detected: 640x480.
[INFO] [CRT] Aspect ratio forced by user: 1.333333.
[INFO] [Video] Video refresh rate changed to 60.000 Hz.
[DEBUG] [KMS] modeswitch detected, doing GBM and EGL stuff.
AddressSanitizer:DEADLYSIGNAL
=================================================================
==88983==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000298 (pc 0x7ffec82ab3b8 bp 0x7fffca64ed60 sp 0x7fffca64ed60 T0)
==88983==The signal is caused by a READ memory access.
==88983==Hint: address points to the zero page.
    #0 0x7ffec82ab3b8  (/lib/aarch64-linux-gnu/libEGL_mesa.so.0+0x2b3b8) (BuildId: c3af8f042aee0a09ab064dd7f3d439a557cbf00c)
    #1 0x5555e98064b8 in gfx_ctx_drm_wait_flip gfx/drivers_context/drm_ctx.c:554
    #2 0x5555e98077d8 in gfx_ctx_drm_swap_buffers gfx/drivers_context/drm_ctx.c:631
    #3 0x5555e9856764 in gl2_frame gfx/drivers/gl2.c:4185
    #4 0x5555e8c45bec in video_driver_frame gfx/video_driver.c:5327
    #5 0x5555e8c27554 in video_driver_cached_frame gfx/video_driver.c:3347
    #6 0x5555e8a394d8 in runloop_check_state /home/user/RetroArch/runloop.c:6792
    #7 0x5555e8a464d0 in runloop_iterate /home/user/RetroArch/runloop.c:7825
    #8 0x5555e89ddabc in rarch_main /home/user/RetroArch/retroarch.c:6525
    #9 0x5555e89ddb7c in main /home/user/RetroArch/retroarch.c:6664
    #10 0x7ffecdf52258  (/lib/aarch64-linux-gnu/libc.so.6+0x22258) (BuildId: 13bc4af497c4104410d1e268e575ad7f1df46dd3)
    #11 0x7ffecdf52338 in __libc_start_main (/lib/aarch64-linux-gnu/libc.so.6+0x22338) (BuildId: 13bc4af497c4104410d1e268e575ad7f1df46dd3)
    #12 0x5555e8944cac in _start (/home/user/RetroArch/retroarch+0x5c34cac) (BuildId: a5f912c5fb21e069c29d94657e038dc603d9df83)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/lib/aarch64-linux-gnu/libEGL_mesa.so.0+0x2b3b8) (BuildId: c3af8f042aee0a09ab064dd7f3d439a557cbf00c) 
==88983==ABORTING

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions