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

Fix crash on Windows machines without OpenGL #811

Merged
merged 5 commits into from
Oct 9, 2023

Conversation

igordmn
Copy link
Collaborator

@igordmn igordmn commented Oct 4, 2023

Some Windows CI machines don't contain OpenGL, so Skiko/Compose will crash on them. It shouldn't crash, it should fallback to Software rendering

To properly fallback, we need to load opengl32.dll dynamically in runtime.

Fixes JetBrains/compose-multiplatform#3243

Test 1

  • gradlew publishToMavenLocal is successful (if we use functions directly, it fails with "error LNK2019: unresolved external symbol")
  • SkiaLayerTest is successful (it tests OpenGL as well)

Test 2

  1. Remove C:\Windows\System32\opengl32.dll
  2. SkiaLayerTest still should be successful, but logs should contain that it fallbacks to Software rendering.

Test 3

  1. Compile local skiko
  2. Run Compose run1 and tests

Some Windows CI machines don't contain OpenGL, so Skiko/Compose will crash on them. It shouldn't crash, it should fallback to Software rendering

To properly fallback, we need to load opengl32.dll dynamically in runtime.

Fixes JetBrains/compose-multiplatform#3243

# Test 1
- `gradlew publishToMavenLocal` is successful (if we use functions directly, it fails with "error LNK2019: unresolved external symbol")
- `SkiaLayerTest` is successful (it tests OpenGL as well)

# Test 2
1. Remove `C:\Windows\System32\opengl32.dll`
2. `SkiaLayerTest` still should be successful, but logs should contain that it fallbacks to Software rendering.

# Test 3
1. Compile local skiko
2. Run Compose run1 and tests
skiko/src/awtMain/cpp/windows/OpenGLLibrary.cc Outdated Show resolved Hide resolved
skiko/src/awtMain/cpp/windows/OpenGLLibrary.cc Outdated Show resolved Hide resolved
skiko/src/jvmMain/cpp/common/openglapi.cc Show resolved Hide resolved
skiko/src/awtMain/cpp/windows/OpenGLLibrary.cc Outdated Show resolved Hide resolved
skiko/src/awtMain/cpp/windows/OpenGLLibrary.cc Outdated Show resolved Hide resolved
skiko/src/awtMain/cpp/windows/OpenGLLibrary.cc Outdated Show resolved Hide resolved
skiko/src/awtMain/cpp/windows/OpenGLLibrary.cc Outdated Show resolved Hide resolved
skiko/src/awtMain/cpp/windows/OpenGLLibrary.cc Outdated Show resolved Hide resolved
skiko/src/awtMain/cpp/windows/OpenGLLibrary.cc Outdated Show resolved Hide resolved
skiko/src/awtMain/cpp/windows/OpenGLLibrary.cc Outdated Show resolved Hide resolved
skiko/src/awtMain/cpp/windows/OpenGLLibrary.cc Outdated Show resolved Hide resolved
It isn't valid to use FormatMessage for code from GetLastError
@igordmn igordmn merged commit 2fac686 into master Oct 9, 2023
5 checks passed
@igordmn igordmn deleted the igor.demin/fix-opengl-crash branch October 9, 2023 10:54
@K-o-d-y
Copy link

K-o-d-y commented Nov 23, 2023

1
I'm using lwjgl which started crashing after this push

@K-o-d-y
Copy link

K-o-d-y commented Nov 23, 2023

@igordmn

igordmn added a commit that referenced this pull request Feb 9, 2024
It is a regression after #811

After that PR, OpenGL functions are linked in runtime via function `loadOpenGLLibrary`. We didn't call it in `makeGL` functions. Now we call.

Adding also `isLoaded` to avoid loading it multiple times

Fixes https://youtrack.jetbrains.com/issue/COMPOSE-642/Fix-Skiko-API-regression-for-creating-OpenGL-context
igordmn added a commit that referenced this pull request Feb 9, 2024
It is a regression after #811

After that PR, OpenGL functions are linked in runtime via function `loadOpenGLLibrary`. We didn't call it in `makeGL` functions. Now we call.

Adding also `isLoaded` to avoid loading it multiple times

Fixes https://youtrack.jetbrains.com/issue/COMPOSE-642/Fix-Skiko-API-regression-for-creating-OpenGL-context
igordmn added a commit that referenced this pull request Feb 9, 2024
It is a regression after #811

After that PR, OpenGL functions are linked in runtime via function `loadOpenGLLibrary`. We didn't call it in `makeGL` functions. Now we call.

Adding also `isLoaded` to avoid loading it multiple times

Fixes https://youtrack.jetbrains.com/issue/COMPOSE-642/Fix-Skiko-API-regression-for-creating-OpenGL-context
igordmn added a commit that referenced this pull request Feb 9, 2024
It is a regression after #811

After that PR, OpenGL functions are linked in runtime via function `loadOpenGLLibrary`. We didn't call it in `makeGL` functions. Now we call.

Adding also `isLoaded` to avoid loading it multiple times

Fixes https://youtrack.jetbrains.com/issue/COMPOSE-642/Fix-Skiko-API-regression-for-creating-OpenGL-context
igordmn added a commit that referenced this pull request Feb 9, 2024
It is a regression after #811

After that PR, OpenGL functions are linked in runtime via function `loadOpenGLLibrary`. We didn't call it in `makeGL` functions. Now we call.

Adding also `isLoaded` to avoid loading it multiple times

Fixes https://youtrack.jetbrains.com/issue/COMPOSE-642/Fix-Skiko-API-regression-for-creating-OpenGL-context
igordmn added a commit that referenced this pull request Feb 9, 2024
It is a regression after #811

After that PR, OpenGL functions are linked in runtime via function `loadOpenGLLibrary`. We didn't call it in `makeGL` functions. Now we call.

Adding also `isLoaded` to avoid loading it multiple times

Fixes https://youtrack.jetbrains.com/issue/COMPOSE-642/Fix-Skiko-API-regression-for-creating-OpenGL-context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invoking the skiko library causes runtime error on windows
3 participants