Here is a diff for games/openjk that fixes singleplayer crashing and
updates to a recent commit.

Changes I proposed to upstream:
- Fixes single player crashing when toggling fullscreen.
  https://github.com/JACoders/OpenJK/pull/1037
  https://github.com/JACoders/OpenJK/issues/1036
- Fixes buffer over-read, already upstreamed.
  https://github.com/JACoders/OpenJK/pull/1040

Notable changes:
- Move the cmake modules directory, so a patch is renamed.
- Use sdl2-config.cmake from devel/sdl2's
  /usr/local/lib/cmake/SDL2/sdl2-config.cmake
  
https://github.com/JACoders/OpenJK/commit/52030235f052772008d99e6ccb16de48e7ddb688

While I was investigating the fullscreen crash, I came across a buffer
over-read. Once again, OpenBSD exposed incorrect memory access. Shooting
a rocket launcher had a decent chance of crashing.

As for the fullscreen fix, upstream is hesitant about adding it, and I
would guess it is because it is not an optimal solution. To be safe and
consistent there are two patches resetting global variables, although
multiplayer likely works without.

Read the patch comments for a summary. For some unknown reason,
dlclose() actually unloads the library for multiplayer, not single
player. After a subsequent dlopen(), global variables get initialized in
multiplayer, not singleplayer. This is consistent with the observation
that multiplayer fullscreen works but single player does not.

I tested jasp by toggling fullscreen and jamp by using the rocket
launcher to try to trigger the buffer over-read crash.

Feedback and tests are welcome.

Index: Makefile
===================================================================
RCS file: /cvs/ports/games/openjk/Makefile,v
retrieving revision 1.11
diff -u -p -r1.11 Makefile
--- Makefile    15 Dec 2019 18:03:30 -0000      1.11
+++ Makefile    11 Jun 2020 10:40:53 -0000
@@ -2,12 +2,12 @@
 
 # Avoid future EPOCH bumps.
 COMMENT =      open source reimplementation of Jedi Academy game
-DISTNAME =     openjk-0.0.0.20191129
+DISTNAME =     openjk-0.0.0.20200610
 CATEGORIES =   games x11
 
 GH_ACCOUNT =   JACoders
 GH_PROJECT =   OpenJK
-GH_COMMIT =    eed60925ad1b0d513d3747264f3bf98615fa4b2a
+GH_COMMIT =    24c5b279ce8482e160cf64f509fb02f2addcdaac
 
 HOMEPAGE =     https://openjk.org/
 MAINTAINER =   Brian Callahan <bcal...@openbsd.org>
Index: distinfo
===================================================================
RCS file: /cvs/ports/games/openjk/distinfo,v
retrieving revision 1.9
diff -u -p -r1.9 distinfo
--- distinfo    15 Dec 2019 18:03:30 -0000      1.9
+++ distinfo    11 Jun 2020 10:40:53 -0000
@@ -1,2 +1,2 @@
-SHA256 (openjk-0.0.0.20191129-eed60925.tar.gz) = 
Q++JpWF2e7uL7vc+aSPysiocOQBQKx4em4qaZbKQVds=
-SIZE (openjk-0.0.0.20191129-eed60925.tar.gz) = 13394932
+SHA256 (openjk-0.0.0.20200610-24c5b279.tar.gz) = 
PBzCjvBDRd6HopQyAcHtIchRi3435wdkArinOAaYo70=
+SIZE (openjk-0.0.0.20200610-24c5b279.tar.gz) = 13392638
Index: patches/patch-CMakeModules_InstallConfig_cmake
===================================================================
RCS file: patches/patch-CMakeModules_InstallConfig_cmake
diff -N patches/patch-CMakeModules_InstallConfig_cmake
--- patches/patch-CMakeModules_InstallConfig_cmake      6 Mar 2019 02:20:40 
-0000       1.2
+++ /dev/null   1 Jan 1970 00:00:00 -0000
@@ -1,16 +0,0 @@
-$OpenBSD: patch-CMakeModules_InstallConfig_cmake,v 1.2 2019/03/06 02:20:40 
bcallah Exp $
-
-Index: CMakeModules/InstallConfig.cmake
---- CMakeModules/InstallConfig.cmake.orig
-+++ CMakeModules/InstallConfig.cmake
-@@ -17,8 +17,8 @@
- #============================================================================
- 
- # Subdirectories to package JK2 and JKA into
--set(JKAInstallDir "JediAcademy")
--set(JK2InstallDir "JediOutcast")
-+set(JKAInstallDir "share/JediAcademy")
-+set(JK2InstallDir "share/JediOutcast")
- 
- # Install components
- set(JKAMPCoreComponent "JKAMPCore")
Index: patches/patch-cmake_Modules_InstallConfig_cmake
===================================================================
RCS file: patches/patch-cmake_Modules_InstallConfig_cmake
diff -N patches/patch-cmake_Modules_InstallConfig_cmake
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-cmake_Modules_InstallConfig_cmake     11 Jun 2020 10:40:53 
-0000
@@ -0,0 +1,16 @@
+$OpenBSD$
+
+Index: cmake/Modules/InstallConfig.cmake
+--- cmake/Modules/InstallConfig.cmake.orig
++++ cmake/Modules/InstallConfig.cmake
+@@ -17,8 +17,8 @@
+ #============================================================================
+ 
+ # Subdirectories to package JK2 and JKA into
+-set(JKAInstallDir "JediAcademy")
+-set(JK2InstallDir "JediOutcast")
++set(JKAInstallDir "share/JediAcademy")
++set(JK2InstallDir "share/JediOutcast")
+ 
+ # Install components
+ set(JKAMPCoreComponent "JKAMPCore")
Index: patches/patch-code_rd-vanilla_tr_init_cpp
===================================================================
RCS file: patches/patch-code_rd-vanilla_tr_init_cpp
diff -N patches/patch-code_rd-vanilla_tr_init_cpp
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-code_rd-vanilla_tr_init_cpp   11 Jun 2020 10:40:53 -0000
@@ -0,0 +1,29 @@
+$OpenBSD$
+
+Hack to fix singleplayer crashing when toggling fullscreen.
+
+dlclose doesn't necessarily unload the shared library immediately. In some
+cases, the library is intentionally kept around. As a result, when the library
+is loaded up again none of the global variables get initialized. Force
+initialization of globals in case this happens. InitOpenGL() depends on
+glConfig.vidWidth == 0.
+
+Fixes: https://github.com/JACoders/OpenJK/issues/1036
+
+Sources:
+https://github.com/JACoders/OpenJK/pull/1037
+https://github.com/etfdevs/ETe/blob/master/src/renderer/tr_init.c#L2003-L2005
+
+Index: code/rd-vanilla/tr_init.cpp
+--- code/rd-vanilla/tr_init.cpp.orig
++++ code/rd-vanilla/tr_init.cpp
+@@ -1841,6 +1841,9 @@ void RE_Shutdown( qboolean destroyWindow, qboolean res
+       // shut down platform specific OpenGL stuff
+       if ( destroyWindow ) {
+               ri.WIN_Shutdown();
++              Com_Memset( &glConfig, 0, sizeof( glConfig ) );
++              Com_Memset( &glState, 0, sizeof( glState ) );
++              Com_Memset( &window, 0, sizeof( window ) );
+       }
+       tr.registered = qfalse;
+ }
Index: patches/patch-codemp_rd-vanilla_tr_init_cpp
===================================================================
RCS file: patches/patch-codemp_rd-vanilla_tr_init_cpp
diff -N patches/patch-codemp_rd-vanilla_tr_init_cpp
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-codemp_rd-vanilla_tr_init_cpp 11 Jun 2020 10:40:53 -0000
@@ -0,0 +1,30 @@
+$OpenBSD$
+
+Hack to fix singleplayer crashing when toggling fullscreen.
+
+dlclose doesn't necessarily unload the shared library immediately. In some
+cases, the library is intentionally kept around. As a result, when the library
+is loaded up again none of the global variables get initialized. Force
+initialization of globals in case this happens. InitOpenGL() depends on
+glConfig.vidWidth == 0.
+
+Fixes: https://github.com/JACoders/OpenJK/issues/1036
+
+Sources:
+https://github.com/JACoders/OpenJK/pull/1037
+https://github.com/etfdevs/ETe/blob/master/src/renderer/tr_init.c#L2003-L2005
+
+Index: codemp/rd-vanilla/tr_init.cpp
+--- codemp/rd-vanilla/tr_init.cpp.orig
++++ codemp/rd-vanilla/tr_init.cpp
+@@ -1881,6 +1881,10 @@ void RE_Shutdown( qboolean destroyWindow, qboolean res
+       // shut down platform specific OpenGL stuff
+       if ( destroyWindow ) {
+               ri.WIN_Shutdown();
++              Com_Memset( &glConfig, 0, sizeof( glConfig ) );
++              Com_Memset( &glConfigExt, 0, sizeof( glConfigExt ) );
++              Com_Memset( &glState, 0, sizeof( glState ) );
++              Com_Memset( &window, 0, sizeof( window ) );
+       }
+ 
+       tr.registered = qfalse;

Reply via email to