wip fix: buttons array now being ref'ed from native side to avoid GC'ing
This commit is contained in:
parent
c0bc4b1899
commit
310526a254
|
@ -70,6 +70,7 @@ JNIEnv* cEnvironment; // JNIEnvironment copy
|
|||
|
||||
bool cCreate_success; // bool used to determine successfull creation
|
||||
bool cFirstTimeInitialization = true; // boolean to determine first time initialization
|
||||
jobject cButtonsReference = NULL; // reference to buttons array so it won't get GC'ed
|
||||
|
||||
// Cached fields of Controller.java
|
||||
jclass clsController;
|
||||
|
@ -179,6 +180,9 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_input_Controller_nCreate(JNIEnv *env,
|
|||
if(cCreate_success) {
|
||||
/* Do setup of Controller */
|
||||
SetupController();
|
||||
|
||||
/* Initialize any fields on the Controller */
|
||||
InitializeControllerFields();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -241,6 +245,9 @@ void ShutdownController() {
|
|||
cDIDevice->Release();
|
||||
cDIDevice = NULL;
|
||||
}
|
||||
|
||||
//delete global reference, since we're done
|
||||
cEnvironment->DeleteGlobalRef(cButtonsReference);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -461,9 +468,14 @@ void SetupController() {
|
|||
* Sets the fields on the Controller
|
||||
*/
|
||||
void InitializeControllerFields() {
|
||||
//create buttons array
|
||||
jbooleanArray cButtonsArray = cEnvironment->NewBooleanArray(cButtoncount);
|
||||
|
||||
//create reference so it won't get GC'ed
|
||||
cButtonsReference = cEnvironment->NewGlobalRef(cButtonsArray);
|
||||
|
||||
//set buttons array
|
||||
jbooleanArray buttonsArray = cEnvironment->NewBooleanArray(cButtoncount);
|
||||
cEnvironment->SetStaticObjectField(clsController, fidCButtons, buttonsArray);
|
||||
cEnvironment->SetStaticObjectField(clsController, fidCButtons, (jbooleanArray) cButtonsReference);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -60,6 +60,7 @@ JNIEnv* mEnvironment; // JNIEnvironment copy
|
|||
|
||||
bool mCreate_success; // bool used to determine successfull creation
|
||||
bool mFirstTimeInitialization = true; // boolean to determine first time initialization
|
||||
jobject mButtonsReference = NULL; // reference to buttons array so it won't get GC'ed
|
||||
|
||||
// Cached fields of Mouse.java
|
||||
jclass clsMouse;
|
||||
|
@ -129,6 +130,9 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_input_Mouse_nCreate(JNIEnv *env, jclas
|
|||
if(mCreate_success) {
|
||||
/* Do setup of Mouse */
|
||||
SetupMouse();
|
||||
|
||||
/* Initialize any fields on the Mouse */
|
||||
InitializeMouseFields();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -171,6 +175,9 @@ void ShutdownMouse() {
|
|||
mDIDevice->Unacquire();
|
||||
mDIDevice->Release();
|
||||
}
|
||||
|
||||
//delete global reference, since we're done
|
||||
mEnvironment->DeleteGlobalRef(mButtonsReference);
|
||||
}
|
||||
/**
|
||||
* Enumerates the capabilities of the Mouse attached to the system
|
||||
|
@ -253,9 +260,14 @@ void SetupMouse() {
|
|||
* Sets the fields on the Mouse
|
||||
*/
|
||||
void InitializeMouseFields() {
|
||||
//create buttons array
|
||||
jbooleanArray mButtonsArray = mEnvironment->NewBooleanArray(mButtoncount);
|
||||
|
||||
//create reference so it won't get GC'ed
|
||||
mButtonsReference = mEnvironment->NewGlobalRef(mButtonsArray);
|
||||
|
||||
//set buttons array
|
||||
jbooleanArray buttonsArray = mEnvironment->NewBooleanArray(mButtoncount);
|
||||
mEnvironment->SetStaticObjectField(clsMouse, fidMButtons, buttonsArray);
|
||||
mEnvironment->SetStaticObjectField(clsMouse, fidMButtons, (jbooleanArray) mButtonsReference);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -271,7 +283,6 @@ void UpdateMouseFields() {
|
|||
diMouseState.lX = 0;
|
||||
diMouseState.lY = 0;
|
||||
diMouseState.lZ = 0;
|
||||
|
||||
// did the read fail because we lost input for some reason?
|
||||
// if so, then attempt to reacquire.
|
||||
if(hRes == DIERR_INPUTLOST || hRes == DIERR_NOTACQUIRED) {
|
||||
|
@ -290,7 +301,6 @@ void UpdateMouseFields() {
|
|||
mEnvironment->SetStaticIntField(clsMouse, fidMDY, (jint) diMouseState.lY);
|
||||
mEnvironment->SetStaticIntField(clsMouse, fidMDWheel, (jint) diMouseState.lZ);
|
||||
|
||||
jbooleanArray buttonsArray = (jbooleanArray) mEnvironment->GetStaticObjectField(clsMouse, fidMButtons);
|
||||
for (int i = 0; i < mButtoncount; i++) {
|
||||
if (diMouseState.rgbButtons[i] != 0) {
|
||||
diMouseState.rgbButtons[i] = JNI_TRUE;
|
||||
|
@ -298,7 +308,7 @@ void UpdateMouseFields() {
|
|||
diMouseState.rgbButtons[i] = JNI_FALSE;
|
||||
}
|
||||
}
|
||||
mEnvironment->SetBooleanArrayRegion(buttonsArray, 0, mButtoncount, diMouseState.rgbButtons);
|
||||
mEnvironment->SetBooleanArrayRegion((jbooleanArray) mButtonsReference, 0, mButtoncount, diMouseState.rgbButtons);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue