Bug fix: game stills run after close window

This commit is contained in:
khanhduytran0 2020-12-11 18:47:25 +07:00
parent 6f40ecfc7d
commit 86deaf55c0
3 changed files with 28 additions and 1 deletions

View File

@ -190,8 +190,20 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL_nativeRegalMakeCurrent(JNIEnv *e
RegalMakeCurrent(potatoBridge.eglContext);
}
bool stopMakeCurrent;
JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_GLFW_nativeEglSwapBuffers(JNIEnv *env, jclass clazz) {
return eglSwapBuffers(potatoBridge.eglDisplay, potatoBridge.eglSurface);
if (stopMakeCurrent) {
return JNI_FALSE;
}
jboolean result = (jboolean) eglSwapBuffers(potatoBridge.eglDisplay, potatoBridge.eglSurface);
if (!result) {
if (eglGetError() == EGL_BAD_SURFACE) {
stopMakeCurrent = true;
closeGLFWWindow();
}
}
return result;
}
JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_GLFW_nativeEglSwapInterval(JNIEnv *env, jclass clazz, jint interval) {

View File

@ -138,6 +138,19 @@ void sendData(int type, int i1, int i2, int i3, int i4) {
);
}
void closeGLFWWindow() {
jclass glfwClazz = (*runtimeJNIEnvPtr_JRE)->FindClass(runtimeJNIEnvPtr_JRE, "org/lwjgl/glfw/GLFW");
assert(glfwClazz != NULL);
jmethodID glfwMethod = (*runtimeJNIEnvPtr_JRE)->GetStaticMethodID(runtimeJNIEnvPtr_JRE, glfwMethod, "glfwSetWindowShouldClose", "(JZ)V");
assert(glfwMethod != NULL);
(*runtimeJNIEnvPtr_JRE)->CallStaticVoidMethod(
runtimeJNIEnvPtr_JRE,
glfwClazz, glfwMethod,
(jlong) showingWindow, JNI_TRUE
);
}
JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeAttachThreadToOther(JNIEnv* env, jclass clazz, jboolean isAndroid, jboolean isUseStackQueueBool) {
#ifdef DEBUG
LOGD("Debug: JNI attaching thread, isUseStackQueue=%d\n", isUseStackQueue);

View File

@ -22,5 +22,7 @@ char** convert_to_char_array(JNIEnv *env, jobjectArray jstringArray);
jobjectArray convert_from_char_array(JNIEnv *env, char **charArray, int num_rows);
void free_char_array(JNIEnv *env, jobjectArray jstringArray, const char **charArray);
void closeGLFWWindow();
#endif // _BINARY_UTILS_H_