Exception Thrown at GetStaticMethodId

1

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

java
jni
asked on Stack Overflow Jul 2, 2018 by Quinten Mooij • edited Jul 3, 2018 by Quinten Mooij

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0