[HACK][REVERTME] fix: l4j doesn't init SDL

Legacy4J has code that traps us inside GLFW only, soo this is a hacky
workaround. It works but I'd prefer we don't have it at all.
This commit is contained in:
alexytomi
2025-09-13 00:51:52 +08:00
parent 83de94ec73
commit bbcbeeb4df
4 changed files with 18 additions and 1 deletions

View File

@@ -131,6 +131,7 @@ public class MainActivity extends BaseActivity implements ControlButtonMenuListe
motionListener = (View.OnGenericMotionListener)
runMethodbyReflection("org.libsdl.app.SDLActivity",
"getMotionListener");
Tools.SDL.initializeControllerSubsystems();
} catch (UnsatisfiedLinkError ignored) {
// Ignore because if SDL.setupJNI(); fails, SDL wasn't loaded.
} catch (ReflectiveOperationException e) {

View File

@@ -1586,6 +1586,8 @@ public final class Tools {
}
static class SDL {
public static native void initializeControllerSubsystems();
public static native void onNativeMouse(int button, int action, float x, float y, boolean relative);
public static native void onNativeTouch(int touchDevId, int pointerFingerId,
int action, float x,

View File

@@ -15,6 +15,7 @@ include $(CLEAR_VARS)
# Link GLESv2 for test
LOCAL_LDLIBS := -ldl -llog -landroid
# -lGLESv2
LOCAL_SHARED_LIBRARIES := SDL3
LOCAL_MODULE := pojavexec
# LOCAL_CFLAGS += -DDEBUG
# -DGLES_TEST

View File

@@ -553,4 +553,17 @@ Java_org_lwjgl_glfw_CallbackBridge_nativeCreateGamepadButtonBuffer(JNIEnv *env,
JNIEXPORT jobject JNICALL
Java_org_lwjgl_glfw_CallbackBridge_nativeCreateGamepadAxisBuffer(JNIEnv *env, jclass clazz) {
return (*env)->NewDirectByteBuffer(env, &pojav_environ->gamepadState.axes, sizeof(pojav_environ->gamepadState.axes));
}
}
// HACK: Legacy4J has faulty detection that hardwires us to GLFW unless we init SDL ourselves.
// This is a horribly made function that should really have more checks around it but meh.
#include <SDL3/SDL.h>
static inline void initSubsystem(void) {
SDL_Init(SDL_INIT_GAMEPAD | SDL_INIT_JOYSTICK | SDL_INIT_EVENTS);
}
JNIEXPORT void JNICALL
Java_net_kdt_pojavlaunch_Tools_00024SDL_initializeControllerSubsystems(JNIEnv *env, jclass clazz){
// Please ensure that you have already dlopen'ed SDL3 before calling this.
initSubsystem();
}