Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Startup crash on macOS with certain display configuration #5190

Closed
peppy opened this issue May 21, 2022 · 8 comments · Fixed by #5339
Closed

Startup crash on macOS with certain display configuration #5190

peppy opened this issue May 21, 2022 · 8 comments · Fixed by #5339
Assignees
Labels
broken-in-sdl platform:macOS priority:0 Showstopper. Critical to the next release.

Comments

@peppy
Copy link
Sponsor Member

peppy commented May 21, 2022


[runtime] 2022-05-21 07:55:01 [error]: Failed to get desktop display mode. Display index: -1. SDL error: displayIndex must be in the range 0 - 2

Debug does not break at any exception

System Preferences 2022-05-21 at 08 05 12@2x

https://gist.github.com/b5a5da836ecebab84c41f67d84be50bd

@peppy peppy added priority:0 Showstopper. Critical to the next release. platform:macOS labels May 21, 2022
@peppy peppy self-assigned this May 23, 2022
@Susko3
Copy link
Member

Susko3 commented May 25, 2022

Try it out with #5203 and see if you get any additional errors.

@peppy
Copy link
Sponsor Member Author

peppy commented May 27, 2022


[runtime] 2022-05-27 05:36:37 [verbose]: GL Initialized
[runtime] 2022-05-27 05:36:37 [verbose]: GL Version:                 2.1 ATI-4.8.15
[runtime] 2022-05-27 05:36:37 [verbose]: GL Renderer:                AMD Radeon Pro 580X OpenGL Engine
[runtime] 2022-05-27 05:36:37 [verbose]: GL Shader Language version: 1.20
[runtime] 2022-05-27 05:36:37 [verbose]: GL Vendor:                  ATI Technologies Inc.
[runtime] 2022-05-27 05:36:37 [verbose]: GL Extensions:              GL_ARB_color_buffer_float GL_ARB_depth_buffer_float GL_ARB_depth_clamp GL_ARB_depth_texture GL_ARB_draw_buffers GL_ARB_draw_elements_base_vertex GL_ARB_draw_instanced GL_ARB_fragment_program GL_ARB_fragment_program_shadow GL_ARB_fragment_shader GL_ARB_framebuffer_object GL_ARB_framebuffer_sRGB GL_ARB_half_float_pixel GL_ARB_half_float_vertex GL_ARB_imaging GL_ARB_instanced_arrays GL_ARB_multisample GL_ARB_multitexture GL_ARB_occlusion_query GL_ARB_pixel_buffer_object GL_ARB_point_parameters GL_ARB_point_sprite GL_ARB_provoking_vertex GL_ARB_seamless_cube_map GL_ARB_shader_objects GL_ARB_shader_texture_lod GL_ARB_shading_language_100 GL_ARB_shadow GL_ARB_shadow_ambient GL_ARB_sync GL_ARB_texture_border_clamp GL_ARB_texture_compression GL_ARB_texture_compression_rgtc GL_ARB_texture_cube_map GL_ARB_texture_env_add GL_ARB_texture_env_combine GL_ARB_texture_env_crossbar GL_ARB_texture_env_dot3 GL_ARB_texture_float GL_ARB_texture_mirrored_repeat GL_ARB_texture_non_power_of_two GL_ARB_texture_rectangle GL_ARB_texture_rg GL_ARB_transpose_matrix GL_ARB_vertex_array_bgra GL_ARB_vertex_blend GL_ARB_vertex_buffer_object GL_ARB_vertex_program GL_ARB_vertex_shader GL_ARB_window_pos GL_EXT_abgr GL_EXT_bgra GL_EXT_bindable_uniform GL_EXT_blend_color GL_EXT_blend_equation_separate GL_EXT_blend_func_separate GL_EXT_blend_minmax GL_EXT_blend_subtract GL_EXT_clip_volume_hint GL_EXT_debug_label GL_EXT_debug_marker GL_EXT_depth_bounds_test GL_EXT_draw_buffers2 GL_EXT_draw_range_elements GL_EXT_fog_coord GL_EXT_framebuffer_blit GL_EXT_framebuffer_multisample GL_EXT_framebuffer_object GL_EXT_framebuffer_sRGB GL_EXT_geometry_shader4 GL_EXT_gpu_program_parameters GL_EXT_gpu_shader4 GL_EXT_multi_draw_arrays GL_EXT_packed_depth_stencil GL_EXT_packed_float GL_EXT_provoking_vertex GL_EXT_rescale_normal GL_EXT_secondary_color GL_EXT_separate_specular_color GL_EXT_shadow_funcs GL_EXT_stencil_two_side GL_EXT_stencil_wrap GL_EXT_texture_array GL_EXT_texture_compression_dxt1 GL_EXT_texture_compression_s3tc GL_EXT_texture_env_add GL_EXT_texture_filter_anisotropic GL_EXT_texture_integer GL_EXT_texture_lod_bias GL_EXT_texture_mirror_clamp GL_EXT_texture_rectangle GL_EXT_texture_shared_exponent GL_EXT_texture_sRGB GL_EXT_texture_sRGB_decode GL_EXT_timer_query GL_EXT_transform_feedback GL_EXT_vertex_array_bgra GL_APPLE_aux_depth_stencil GL_APPLE_client_storage GL_APPLE_element_array GL_APPLE_fence GL_APPLE_float_pixels GL_APPLE_flush_buffer_range GL_APPLE_flush_render GL_APPLE_object_purgeable GL_APPLE_packed_pixels GL_APPLE_pixel_buffer GL_APPLE_rgb_422 GL_APPLE_row_bytes GL_APPLE_specular_vector GL_APPLE_texture_range GL_APPLE_transform_hint GL_APPLE_vertex_array_object GL_APPLE_vertex_array_range GL_APPLE_vertex_point_size GL_APPLE_vertex_program_evaluators GL_APPLE_ycbcr_422 GL_ATI_blend_equation_separate GL_ATI_blend_weighted_minmax GL_ATI_separate_stencil GL_ATI_texture_compression_3dc GL_ATI_texture_env_combine3 GL_ATI_texture_float GL_ATI_texture_mirror_once GL_IBM_rasterpos_clip GL_NV_blend_square GL_NV_conditional_render GL_NV_depth_clamp GL_NV_fog_distance GL_NV_light_max_exponent GL_NV_texgen_reflection GL_NV_texture_barrier GL_SGI_color_matrix GL_SGIS_generate_mipmap GL_SGIS_texture_edge_clamp GL_SGIS_texture_lod
[runtime] 2022-05-27 05:36:37 [error]: SDL error: Couldn't find the display where the window is attached to.
[runtime] 2022-05-27 05:36:37 [error]: SDL error: Couldn't find the display where the window is attached to.
[runtime] 2022-05-27 05:36:37 [error]: SDL error: displayIndex must be in the range 0 - 2
[runtime] 2022-05-27 05:36:37 [error]: Failed to get desktop display mode. Display index: -1. SDL error: displayIndex must be in the range 0 - 2
[runtime] 2022-05-27 05:36:37 [error]: SDL error: Couldn't find the display where the window is attached to.
[runtime] 2022-05-27 05:36:37 [error]: SDL error: Couldn't find the display where the window is attached to.
[runtime] 2022-05-27 05:36:37 [error]: SDL error: Couldn't find the display where the window is attached to.

Process finished with exit code 139.

@peppy
Copy link
Sponsor Member Author

peppy commented Jul 12, 2022

This is caused by the call at this line:

if (SDL.SDL_GetWindowDisplayMode(SDLWindowHandle, out var mode) >= 0)

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000000000018
Exception Codes:       0x0000000000000001, 0x0000000000000018
Exception Note:        EXC_CORPSE_NOTIFY

Termination Reason:    Namespace SIGNAL, Code 11 Segmentation fault: 11
Terminating Process:   exc handler [89171]

VM Region Info: 0x18 is not in any region.  Bytes before following region: 140737486737384
      REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      UNUSED SPACE AT START
--->  
      VM_ALLOCATE              7fffffe75000-7fffffe76000 [    4K] r-x/r-x SM=ALI  

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   libSDL2.dylib                 	       0x10a147cf2 SDL_GetClosestDisplayModeForDisplay + 338
1   libSDL2.dylib                 	       0x10a14839f SDL_GetWindowDisplayMode_REAL + 303

Guarding this call with

                if (localIndex == -1)
                    return false;

stops the crash, but then there is another on shutdown:

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000000000050
Exception Codes:       0x0000000000000001, 0x0000000000000050
Exception Note:        EXC_CORPSE_NOTIFY

Termination Reason:    Namespace SIGNAL, Code 11 Segmentation fault: 11
Terminating Process:   exc handler [89471]

VM Region Info: 0x50 is not in any region.  Bytes before following region: 140737486737328
      REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      UNUSED SPACE AT START
--->  
      VM_ALLOCATE              7fffffe75000-7fffffe76000 [    4K] r-x/r-x SM=ALI  

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   libSDL2.dylib                 	       0x10d222665 SDL_UpdateFullscreenMode + 357
1   libSDL2.dylib                 	       0x10d221f1f SDL_DestroyWindow_REAL + 143

Haven't found a solution yet, just documenting what I'm seeing.

@peppy
Copy link
Sponsor Member Author

peppy commented Jul 12, 2022

Commenting out the Position set operation also fixes the issue

Position = new Point(windowX + displayBounds.X, windowY + displayBounds.Y);

@peppy
Copy link
Sponsor Member Author

peppy commented Jul 12, 2022

Even more weirdly, if I disable yabai (window layout manager) the game still won't start, but it's not a native crash:

[runtime] 2022-07-12 09:54:06 [verbose]: SDL error log [debug]: Couldn't find the display where the window is attached to.
[runtime] 2022-07-12 09:54:06 [verbose]: SDL error log [debug]: Couldn't find the display where the window is attached to.
[runtime] 2022-07-12 09:54:06 [verbose]: SDL error log [debug]: displayIndex must be in the range 0 - 2
[runtime] 2022-07-12 09:54:06 [error]: Failed to get desktop display mode. Display index: -1. SDL error: displayIndex must be in the range 0 - 2
[runtime] 2022-07-12 09:54:06 [verbose]: SDL error log [debug]: Couldn't find the display where the window is attached to.
[runtime] 2022-07-12 09:54:06 [verbose]: SDL error log [debug]: Couldn't find the display where the window is attached to.
[runtime] 2022-07-12 09:54:06 [verbose]: SDL error log [debug]: Couldn't find the display where the window is attached to.

This is when the game window has a position of 8,1072 on my First display, which should be 2560x1440.

JetBrains Rider-EAP 2022-07-12 at 09 56 27

It still aborts execution on the same line.

@Susko3
Copy link
Member

Susko3 commented Jul 12, 2022

Short convo on discord about this: https://discord.com/channels/188630481301012481/589331078574112768/996354605388668958

Conclusion is that something fails in SDL.

@peppy
Copy link
Sponsor Member Author

peppy commented Jul 13, 2022

Managed to reproduce in an isolated project with only one line:

SDL.SDL_CreateWindow("test window", 100, 1400, 500, 500, SDL.SDL_WindowFlags.SDL_WINDOW_RESIZABLE);

😅

I also have a fix already working at the SDL end. This looks to have regressed in recent times, as it worked correctly back in a previous version of SDL2-CS.

peppy added a commit to ppy/SDL that referenced this issue Jul 13, 2022
…crash

With the introduction of this function, it is possible that for certain
monitor and window configurations, creating an SDL window will cause a
native crash.

```
Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000000000050
Exception Codes:       0x0000000000000001, 0x0000000000000050
Exception Note:        EXC_CORPSE_NOTIFY

Termination Reason:    Namespace SIGNAL, Code 11 Segmentation fault: 11
Terminating Process:   exc handler [56627]

VM Region Info: 0x50 is not in any region.  Bytes before following region: 140737486737328
      REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      UNUSED SPACE AT START
--->
      VM_ALLOCATE              7fffffe75000-7fffffe76000 [    4K] r-x/r-x SM=ALI

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   libSDL2.dylib                            0x10247f665 SDL_UpdateFullscreenMode + 357
1   libSDL2.dylib                            0x10247ec70 SDL_CreateWindow_REAL + 1504
2   ???                                      0x111262de8 ???
3   ???                                      0x110c39fff ???
4   libcoreclr.dylib                         0x101fdf2a9 CallDescrWorkerInternal + 124
```

Tracking thread from our end: ppy/osu-framework#5190
Regressed with: libsdl-org#5573

In testing, the window would not find a valid screen if created
"hanging" off a primary display with a secondary display below it. In
checking why this was the case, the `display_centre` was being
calculated with a negative y origin, causing a final negative value
falling outside all display bounds:

```
SDL error log [debug]: display_centre.y = -1296 + 1296 / 2

SDL error log [debug]: Display rect 0: 0 0 2560 1440
SDL error log [debug]: Display rect 1: 2560 -625 1080 2560
SDL error log [debug]: Display rect 2: 0 1440 1728 1296
```

The method that was being used to find the current window using the frame
origin/size seems unreliable, so I have opted to replace it with with a
tried method (https://stackoverflow.com/a/40891902).

Initial testing shows that this works with non-standard DPI screens, but
further testing would be appreciated (cc @sezero / @misl6 from the
original PR thread).
@peppy
Copy link
Sponsor Member Author

peppy commented Jul 13, 2022

libsdl-org/SDL#5914

slouken pushed a commit to libsdl-org/SDL that referenced this issue Jul 24, 2022
…crash

With the introduction of this function, it is possible that for certain
monitor and window configurations, creating an SDL window will cause a
native crash.

```
Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000000000050
Exception Codes:       0x0000000000000001, 0x0000000000000050
Exception Note:        EXC_CORPSE_NOTIFY

Termination Reason:    Namespace SIGNAL, Code 11 Segmentation fault: 11
Terminating Process:   exc handler [56627]

VM Region Info: 0x50 is not in any region.  Bytes before following region: 140737486737328
      REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      UNUSED SPACE AT START
--->
      VM_ALLOCATE              7fffffe75000-7fffffe76000 [    4K] r-x/r-x SM=ALI

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   libSDL2.dylib                            0x10247f665 SDL_UpdateFullscreenMode + 357
1   libSDL2.dylib                            0x10247ec70 SDL_CreateWindow_REAL + 1504
2   ???                                      0x111262de8 ???
3   ???                                      0x110c39fff ???
4   libcoreclr.dylib                         0x101fdf2a9 CallDescrWorkerInternal + 124
```

Tracking thread from our end: ppy/osu-framework#5190
Regressed with: #5573

In testing, the window would not find a valid screen if created
"hanging" off a primary display with a secondary display below it. In
checking why this was the case, the `display_centre` was being
calculated with a negative y origin, causing a final negative value
falling outside all display bounds:

```
SDL error log [debug]: display_centre.y = -1296 + 1296 / 2

SDL error log [debug]: Display rect 0: 0 0 2560 1440
SDL error log [debug]: Display rect 1: 2560 -625 1080 2560
SDL error log [debug]: Display rect 2: 0 1440 1728 1296
```

The method that was being used to find the current window using the frame
origin/size seems unreliable, so I have opted to replace it with with a
tried method (https://stackoverflow.com/a/40891902).

Initial testing shows that this works with non-standard DPI screens, but
further testing would be appreciated (cc @sezero / @misl6 from the
original PR thread).
@peppy peppy mentioned this issue Aug 8, 2022
PJB3005 pushed a commit to PJB3005/SDL that referenced this issue Oct 5, 2022
…crash

With the introduction of this function, it is possible that for certain
monitor and window configurations, creating an SDL window will cause a
native crash.

```
Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000000000050
Exception Codes:       0x0000000000000001, 0x0000000000000050
Exception Note:        EXC_CORPSE_NOTIFY

Termination Reason:    Namespace SIGNAL, Code 11 Segmentation fault: 11
Terminating Process:   exc handler [56627]

VM Region Info: 0x50 is not in any region.  Bytes before following region: 140737486737328
      REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      UNUSED SPACE AT START
--->
      VM_ALLOCATE              7fffffe75000-7fffffe76000 [    4K] r-x/r-x SM=ALI

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   libSDL2.dylib                            0x10247f665 SDL_UpdateFullscreenMode + 357
1   libSDL2.dylib                            0x10247ec70 SDL_CreateWindow_REAL + 1504
2   ???                                      0x111262de8 ???
3   ???                                      0x110c39fff ???
4   libcoreclr.dylib                         0x101fdf2a9 CallDescrWorkerInternal + 124
```

Tracking thread from our end: ppy/osu-framework#5190
Regressed with: libsdl-org#5573

In testing, the window would not find a valid screen if created
"hanging" off a primary display with a secondary display below it. In
checking why this was the case, the `display_centre` was being
calculated with a negative y origin, causing a final negative value
falling outside all display bounds:

```
SDL error log [debug]: display_centre.y = -1296 + 1296 / 2

SDL error log [debug]: Display rect 0: 0 0 2560 1440
SDL error log [debug]: Display rect 1: 2560 -625 1080 2560
SDL error log [debug]: Display rect 2: 0 1440 1728 1296
```

The method that was being used to find the current window using the frame
origin/size seems unreliable, so I have opted to replace it with with a
tried method (https://stackoverflow.com/a/40891902).

Initial testing shows that this works with non-standard DPI screens, but
further testing would be appreciated (cc @sezero / @misl6 from the
original PR thread).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
broken-in-sdl platform:macOS priority:0 Showstopper. Critical to the next release.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants