@@ -581,7 +581,8 @@ JNIEXPORT jobject JNICALL Java_dev_silenium_multimedia_core_mpv_MPVKt_createRend
581581 const auto object = env->NewGlobalRef (self);
582582
583583 mpv_opengl_init_params gl_params{
584- .get_proc_address = fnptr<void *(void *, const char *)>([object, jvm](void *ctx, const char *name) -> void * {
584+ .get_proc_address = fnptr<void *(void *, const char *)>([jvm](void *opaque, const char *name) -> void * {
585+ const auto javaRender = static_cast <jobject>(opaque);
585586 JNIEnv *jni_env;
586587 const auto res = jvm->AttachCurrentThread (reinterpret_cast <void **>(&jni_env), nullptr );
587588 if (res != JNI_OK) {
@@ -590,19 +591,20 @@ JNIEXPORT jobject JNICALL Java_dev_silenium_multimedia_core_mpv_MPVKt_createRend
590591 }
591592
592593 // TODO: Fix crash here during renderer disposal
593- const auto glProcMethod = jni_env->GetMethodID (jni_env->GetObjectClass (object ), " getGlProc" , " (Ljava/lang/String;)J" );
594+ const auto glProcMethod = jni_env->GetMethodID (jni_env->GetObjectClass (javaRender ), " getGlProc" , " (Ljava/lang/String;)J" );
594595 if (glProcMethod == nullptr ) {
595596 std::cerr << " Method not found: getGlProc" << std::endl;
596597 return nullptr ;
597598 }
598599
599600 const auto nameStr = jni_env->NewStringUTF (name);
600- const auto ret = jni_env->CallLongMethod (object , glProcMethod, nameStr);
601+ const auto ret = jni_env->CallLongMethod (javaRender , glProcMethod, nameStr);
601602 jni_env->DeleteLocalRef (nameStr);
602603 jvm->DetachCurrentThread ();
603604 // const auto ret = glXGetProcAddress(reinterpret_cast<const GLubyte *>(name));
604605 return reinterpret_cast <void *>(ret);
605606 }),
607+ .get_proc_address_ctx = object,
606608 };
607609 params.emplace_back (MPV_RENDER_PARAM_OPENGL_INIT_PARAMS, &gl_params);
608610 int advControl = advancedControl ? 1 : 0 ;
@@ -614,26 +616,26 @@ JNIEXPORT jobject JNICALL Java_dev_silenium_multimedia_core_mpv_MPVKt_createRend
614616 env->DeleteGlobalRef (object);
615617 return mpvResultFailure (env, " mpv_render_context_create" , ret);
616618 }
619+ const auto ctx = new RenderContext{handle, object, display};
617620 mpv_render_context_set_update_callback (
618621 handle,
619- fnptr<void (void *)>([object, jvm](void *) {
622+ fnptr<void (void *)>([jvm](void *opaque) {
623+ const auto render_context = static_cast <RenderContext *>(opaque);
620624 JNIEnv *jni_env;
621625 const auto res = jvm->AttachCurrentThread (reinterpret_cast <void **>(&jni_env), nullptr );
622626 if (res != JNI_OK) {
623627 std::cerr << " Failed to attach current thread" << std::endl;
624628 return ;
625629 }
626- const auto updateMethod = jni_env->GetMethodID (jni_env->GetObjectClass (object ), " requestUpdate" , " ()V" );
630+ const auto updateMethod = jni_env->GetMethodID (jni_env->GetObjectClass (render_context-> gref ), " requestUpdate" , " ()V" );
627631 if (updateMethod == nullptr ) {
628632 std::cerr << " Method not found: requestUpdate" << std::endl;
629633 return ;
630634 }
631- std::cerr << " Requesting update: " << object << " , " << updateMethod << std::endl;
632- jni_env->CallVoidMethod (object, updateMethod);
635+ jni_env->CallVoidMethod (render_context->gref , updateMethod);
633636 jvm->DetachCurrentThread ();
634637 }),
635- nullptr );
636- const auto ctx = new RenderContext{handle, object, display};
638+ ctx);
637639 return resultSuccess (env, reinterpret_cast <jlong>(ctx));
638640}
639641
0 commit comments