Skip to content

Commit

Permalink
added safety check in case .dll could not be loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisVeigl committed Jan 31, 2024
1 parent e6788b8 commit 6dca015
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ARE/components/sensor.trackir/src/main/c++/TrackIRBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ JavaVM * jvm = NULL;
jobject trackObj_ms = NULL;
HINSTANCE hLib;
jmethodID processData = NULL;
int dllAvailable = 0;


extern "C"
Expand Down Expand Up @@ -222,11 +223,12 @@ int start_TrackIR() {
result = (*stopCursor)();
printf("C++: TrackIR Brigde Calling NP_StartDataTransmission\n");
result = (*startDataTransmission)();

dllAvailable = 1;
return (1);
}

int stop_TrackIR() {
if (!dllAvailable) return(0);
printf("Calling NP_StopDataTransmission\n");
int result = (*stopDataTransmission)();
printf("Calling NP_StartCursor\n");
Expand Down Expand Up @@ -269,6 +271,7 @@ JNIEXPORT jint JNICALL Java_eu_asterics_component_sensor_trackir_jni_Bridge_getU
(JNIEnv* env, jobject obj)
{

if (!dllAvailable) return(0);
memset(&pTrackIRData, 0, sizeof(TRACKIRDATA));
(*getData)(&pTrackIRData);
//printf("C++: send test callback\n");
Expand All @@ -280,6 +283,7 @@ JNIEXPORT jint JNICALL Java_eu_asterics_component_sensor_trackir_jni_Bridge_getU
JNIEXPORT jint JNICALL Java_eu_asterics_component_sensor_trackir_jni_Bridge_centerCoordinates
(JNIEnv* env, jobject obj)
{
if (!dllAvailable) return(0);
(*reCenter)();
return (jint)0;
}
Expand Down

0 comments on commit 6dca015

Please # to comment.