@@ -580,20 +580,22 @@ JNIEXPORT jobject JNICALL Java_dev_silenium_multimedia_core_mpv_MPVKt_createRend
580580 }
581581 const auto object = env->NewGlobalRef (self);
582582
583- const auto glProcMethod = env->GetMethodID (env->GetObjectClass (self), " getGlProc" , " (Ljava/lang/String;)J" );
584- if (glProcMethod == nullptr ) {
585- std::cerr << " Method not found: getGlProc" << std::endl;
586- return mpvResultFailure (env, " GetMethodID" , MPV_ERROR_GENERIC);
587- }
588583 mpv_opengl_init_params gl_params{
589- .get_proc_address = fnptr<void *(void *, const char *)>([= ](void *ctx, const char *name) -> void * {
584+ .get_proc_address = fnptr<void *(void *, const char *)>([object, jvm ](void *ctx, const char *name) -> void * {
590585 JNIEnv *jni_env;
591586 const auto res = jvm->AttachCurrentThread (reinterpret_cast <void **>(&jni_env), nullptr );
592587 if (res != JNI_OK) {
593588 std::cerr << " Failed to attach current thread" << std::endl;
594589 return nullptr ;
595590 }
596591
592+ // TODO: Fix crash here during renderer disposal
593+ const auto glProcMethod = jni_env->GetMethodID (jni_env->GetObjectClass (object), " getGlProc" , " (Ljava/lang/String;)J" );
594+ if (glProcMethod == nullptr ) {
595+ std::cerr << " Method not found: getGlProc" << std::endl;
596+ return nullptr ;
597+ }
598+
597599 const auto nameStr = jni_env->NewStringUTF (name);
598600 const auto ret = jni_env->CallLongMethod (object, glProcMethod, nameStr);
599601 jni_env->DeleteLocalRef (nameStr);
@@ -609,22 +611,24 @@ JNIEXPORT jobject JNICALL Java_dev_silenium_multimedia_core_mpv_MPVKt_createRend
609611
610612 mpv_render_context *handle{nullptr };
611613 if (const auto ret = mpv_render_context_create (&handle, reinterpret_cast <mpv_handle *>(mpvHandle), params.data ()); ret < 0 ) {
614+ env->DeleteGlobalRef (object);
612615 return mpvResultFailure (env, " mpv_render_context_create" , ret);
613616 }
614- const auto updateMethod = env->GetMethodID (env->GetObjectClass (self), " requestUpdate" , " ()V" );
615- if (updateMethod == nullptr ) {
616- std::cerr << " Method not found: requestUpdate" << std::endl;
617- return mpvResultFailure (env, " GetMethodID" , MPV_ERROR_GENERIC);
618- }
619617 mpv_render_context_set_update_callback (
620618 handle,
621- fnptr<void (void *)>([= ](void *) {
619+ fnptr<void (void *)>([object, jvm ](void *) {
622620 JNIEnv *jni_env;
623621 const auto res = jvm->AttachCurrentThread (reinterpret_cast <void **>(&jni_env), nullptr );
624622 if (res != JNI_OK) {
625623 std::cerr << " Failed to attach current thread" << std::endl;
626624 return ;
627625 }
626+ const auto updateMethod = jni_env->GetMethodID (jni_env->GetObjectClass (object), " requestUpdate" , " ()V" );
627+ if (updateMethod == nullptr ) {
628+ std::cerr << " Method not found: requestUpdate" << std::endl;
629+ return ;
630+ }
631+ std::cerr << " Requesting update: " << object << " , " << updateMethod << std::endl;
628632 jni_env->CallVoidMethod (object, updateMethod);
629633 jvm->DetachCurrentThread ();
630634 }),
0 commit comments