Simple Directmedia Layer
Go to file
Dean Herbert ce8aae1419 Fix Cocoa_GetWindowDisplayIndex failing and causing a catastrophic 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: https://github.com/ppy/osu-framework/issues/5190
Regressed with: https://github.com/libsdl-org/SDL/pull/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).
2022-07-24 09:25:16 -07:00
.github Revert 6fa7d62 and 856c99e5 2022-07-23 17:29:45 +02:00
acinclude imported two libtool mainstream commits 28fbcb6a and b55b1cc8 2022-03-16 17:15:20 +03:00
android-project Added support for the 8BitDo Ultimate Wired Controller for Xbox 2022-07-20 11:05:55 -07:00
android-project-ant Added the old ant Android build project structure 2017-10-28 12:11:25 -07:00
build-scripts Revert 6fa7d62 and 856c99e5 2022-07-23 17:29:45 +02:00
cmake cmake: allow cmake re-configuration after installation of x11 library 2022-07-21 18:38:12 +02:00
docs Xbox GDKX support (#5869) 2022-07-01 13:59:14 -07:00
include video: Improve the SDL_WINDOW_ALLOW_HIGHDPI flag documentation 2022-07-22 13:01:57 -04:00
mingw/pkg-support/cmake Fix MinGW SDK redist: sdl2-config.cmake needs to set SDL2_FOUND 2022-06-03 21:05:55 -07:00
src Fix Cocoa_GetWindowDisplayIndex failing and causing a catastrophic crash 2022-07-24 09:25:16 -07:00
test cmake: only build testnative when X11 is available 2022-07-21 14:49:35 +02:00
VisualC Added a utility function to calculate the next power of 2 for a value 2022-07-17 08:31:16 -07:00
VisualC-GDK Added a utility function to calculate the next power of 2 for a value 2022-07-17 08:31:16 -07:00
VisualC-WinRT Added a utility function to calculate the next power of 2 for a value 2022-07-17 08:31:16 -07:00
visualtest remove all unnecessary stuff from visualtest configury. 2021-12-21 20:01:02 +03:00
wayland-protocols video: wayland: Use wp-viewporter for fullscreen with non-native resolutions 2022-03-28 13:18:26 -04:00
Xcode Enable bitcode by default for iOS and tvOS builds 2022-07-22 10:58:32 -07:00
Xcode-iOS Updated iOS build instructions 2021-11-30 12:19:26 -08:00
.clang-format Disable formatting not supported by Visual Studio 2019 2022-05-27 15:29:21 -07:00
.editorconfig Separated controller type data into a C file 2022-06-03 15:03:08 -07:00
.gitignore Xbox GDKX support (#5869) 2022-07-01 13:59:14 -07:00
.wikiheaders-options wikiheaders.pl: changes to make this usable with external projects. 2022-06-15 23:26:24 -04:00
Android.mk mark Android.mk as non-executable 2021-11-12 12:55:28 +03:00
autogen.sh Simplified autogen.sh, thanks to @smcv for the tip 2022-05-05 11:54:24 -07:00
BUGS.txt Cleaned up a few more Bugzilla mentions. 2021-02-12 14:46:49 -05:00
cmake_uninstall.cmake.in Fixed bug 3867 - Can't find install_manifest.txt when running 'uninstall' target 2017-10-12 08:44:45 -07:00
CMakeLists.txt Revert "cmake: don't add -mwindows to link flags in sdl2.pc" 2022-07-23 18:05:35 +02:00
configure Sort libraries by version and pick the shortest symlink (thanks @jpalus!) 2022-07-12 13:00:43 -07:00
configure.ac Sort libraries by version and pick the shortest symlink (thanks @jpalus!) 2022-07-12 13:00:43 -07:00
CREDITS.txt Fixed crash if initialization of EGL failed but was tried again later. 2015-06-21 17:33:46 +02:00
INSTALL.txt INSTALL.txt: Say "macOS" instead of "Mac OS X" in modern times. 2022-03-15 13:07:55 -04:00
LICENSE.txt Updated copyright for 2022 2022-01-03 09:40:21 -08:00
Makefile.in We want to ship the CMake input file, not the generated file 2022-07-11 08:55:49 -07:00
Makefile.minimal build libSDL2_test too with Makefile.minimal 2021-11-14 01:10:32 +03:00
Makefile.os2 Added a utility function to calculate the next power of 2 for a value 2022-07-17 08:31:16 -07:00
Makefile.pandora more fixes to standalone makefiles. 2021-11-13 21:56:20 +03:00
Makefile.w32 Added a utility function to calculate the next power of 2 for a value 2022-07-17 08:31:16 -07:00
README-SDL.txt More HTTPS changes in the documentation. 2017-02-16 16:52:03 -05:00
README.md Update and rename README.txt to README.md 2021-03-20 18:46:37 -04:00
sdl2-config-version.cmake.in Add documentation to autotoo'ls sdl2-config-version.cmake.in 2022-05-31 00:10:55 +02:00
sdl2-config.cmake.in cmake: fix name+location of SDL2.dll in configure generated SDL2::SDL2 target 2022-06-28 23:09:28 +02:00
sdl2-config.in cmake+ci: fix+test sdl2-config + sdl2.pc for all supported platforms 2022-06-23 14:17:38 +02:00
sdl2.m4 acinclude & sdl2.m4 updates: 2020-12-22 17:00:28 +03:00
sdl2.pc.in rename PKG_CONFIG_LIBS_PRIV to PKGCONFIG_LIBS_PRIV 2021-04-14 21:40:50 +03:00
SDL2.spec.in license: Fixed references to COPYING.txt that are now LICENSE.txt. 2021-02-18 11:07:26 -05:00
SDL2Config.cmake.in ci: Test cmake build script on Android 2022-06-15 11:11:49 -07:00
TODO.txt Fixed up legacy MoinMoin URLs at wiki.libsdl.org 2021-04-01 12:20:33 -04:00
WhatsNew.txt better wording. 2022-07-22 20:37:28 +03:00

Simple DirectMedia Layer (SDL) Version 2.0

https://www.libsdl.org/

Simple DirectMedia Layer is a cross-platform development library designed to provide low level access to audio, keyboard, mouse, joystick, and graphics hardware via OpenGL and Direct3D. It is used by video playback software, emulators, and popular games including Valve's award winning catalog and many Humble Bundle games.

More extensive documentation is available in the docs directory, starting with README.md

Enjoy!

Sam Lantinga (slouken@libsdl.org)