Exception Thrown at GetStaticMethodId


Exception Thrown at GetStaticMethodId



I am trying to use JNI to check if the mouse is held. I am using this in an enviroment where I have access to the "org/lwjgl/input/Mouse" class however I get an Access violation when trying to do GetStaticMethodId. Here is my code


jclass mouse_class = lm->m_jenv->FindClass("org/lwjgl/input/Mouse");
jmethodID method = lm->m_jenv->GetStaticMethodID(mouse_class, "isButtonDown", "(I)Z"); <- error is here
jboolean down = lm->m_jenv->CallStaticBooleanMethod(mouse_class, method, 0);



I can confirm that the mouse_class and m_jenv variable aren't null and that the signature is correct.



This is the exception it throws:


Exception thrown at 0x00000000597EB921 (jvm.dll) in javaw.exe: 0xC0000005:
Access violation reading location 0x0000000000000140.
Unhandled exception at 0x00000000597EB921 (jvm.dll) in javaw.exe: 0xC0000005:
Access violation reading location 0x0000000000000140.



Current code:


bool is_mouse_down()
{
jclass mouse_class = lm->m_jenv->FindClass("org/lwjgl/input/Mouse");
if (lm->m_jenv->ExceptionCheck())
{
lm->m_jenv->ExceptionDescribe();
return false;
}
if (NULL != mouse_class) {
jmethodID method = lm->m_jenv->GetStaticMethodID(mouse_class, "isButtonDown", "(I)Z");
if (lm->m_jenv->ExceptionCheck())
{
lm->m_jenv->ExceptionDescribe();
return false;
}
jboolean down = lm->m_jenv->CallBooleanMethod(mouse_class, method, 0);
if (lm->m_jenv->ExceptionCheck())
{
lm->m_jenv->ExceptionDescribe();
return false;
}
return (bool)(down == JNI_TRUE);
}

return false;
}



EDIT: PROBLEM HAS BEEN RESOLVED
It was a multi-threading issue, I was the wrong thread





Please call ExceptionCheck() after each of those calls.
– EJP
Jul 2 at 23:56


ExceptionCheck()





@EJP I did that, no results. Same error when debugged. Updated post with what code I have now
– Quinten Mooij
Jul 3 at 13:26









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

api-platform.com Unable to generate an IRI for the item of type

How to set up datasource with Spring for HikariCP?

Display dokan vendor name on Woocommerce single product pages