Fix a few major nivision Java wrapper issues.

- sliceByteBuffer() was not setting native order on the duplicated buffer.
  This caused all array-copyin functions to generate bad values.
- Correctly handle unsigned byte and unsigned short values.  These could
  read/write to bad locations previously.
- Implement custom version of imaqReadFile() to always pass in NULL for
  the colorTable.  Eventually a more-complete version should be written.

Also this works around a crash in imaqGetErrorText() by not calling it from
throwJavaException().  It's not clear why imaqGetErrorText() is crashing at
present (my best guess is there's still something fishy with multiple C++
lib versions getting loaded somehow), as this used to work.  Instead,
the exception now just gives the error code without the error message,
which is not user friendly but at least doesn't crash.  This will be fixed
in a future commit by creating our own version of imaqGetErrorText() based
on the information available in the header file.

Change-Id: I4d099e62ee41f8e2a50089806561be191cb5d9d7
This commit is contained in:
Peter Johnson
2015-01-13 22:18:17 -08:00
parent 34d515debb
commit ce7a56284f
4 changed files with 117 additions and 102 deletions

View File

@@ -14,10 +14,12 @@
static void throwJavaException(JNIEnv *env) {
jclass je = env->FindClass("com/ni/vision/VisionException");
int err = imaqGetLastError();
char* err_text = imaqGetErrorText(err);
char* full_err_msg = (char*)malloc(30+strlen(err_text));
sprintf(full_err_msg, "imaqError: %d: %s", err, err_text);
imaqDispose(err_text);
//char* err_text = imaqGetErrorText(err);
//char* full_err_msg = (char*)malloc(30+strlen(err_text));
//sprintf(full_err_msg, "imaqError: %d: %s", err, err_text);
//imaqDispose(err_text);
char* full_err_msg = (char*)malloc(30);
sprintf(full_err_msg, "imaqError: %d", err);
env->ThrowNew(je, full_err_msg);
free(full_err_msg);
}
@@ -1456,11 +1458,6 @@ JNIEXPORT jint JNICALL Java_com_ni_vision_NIVision__1imaqOpenAVI(JNIEnv* env, jc
return (jint)rv;
}
/* J: void imaqReadFile(Image image, String fileName)
* JN: void imaqReadFile(long image, long fileName, long colorTable, long numColors)
* C: int imaqReadFile(Image* image, const char* fileName, RGBValue* colorTable, int* numColors)
*/
JNIEXPORT void JNICALL Java_com_ni_vision_NIVision__1imaqReadFile(JNIEnv* env, jclass , jlong image, jlong fileName, jlong colorTable, jlong numColors)
{
int rv = imaqReadFile((Image*)image, (const char*)fileName, (RGBValue*)colorTable, (int*)numColors);