Matlab crashes when initializing a library when calling from Java

I have an application that uses a Java application to call its own C-code with JNI, which, in turn, starts the MATLAB runtime and calls functions on it (I know there are other solutions for calling MATLAB methods from Java).

The problem is that during initialization, the MATLAB engine will work, and I donโ€™t know what exactly causes it. The crash causes my jvm to stop working, I assume this is some kind of corruption in my memory.

C ++ code calling MATLAB functions that actually crash,

JNIEXPORT void JNICALL 
some_jni_vodoo_initializeLibrary(JNIEnv* env, jclass thisClass) {
  try {
      if (!mclInitializeApplication(NULL, 0)) {
          THROW_EXCEPTION(env, "Could not initialize the application properly.");
          return;
      }
      if (!<library>Initialize()) {
          THROW_EXCEPTION(env, "Could not initialize the library.");
          return;
      }
    } ...

Here the function fails <library>Initialize(), the Java error log reads

Stack Trace:
  [0] jmi.dll:0x793f4175(0x7934cdca, 1, 0x7937e67c "ร ;.y`E.y@E.ychar in C:\BUILD_ARE..", 0x792d6a32)
  [1] jvm.dll:0x792df9a5(0xc0000005, 0x79356791, 0x4961b400 "ร\8y", 0x6d8b29de)
  [2] jvm.dll:0x792e0431(0x8b515008, 0x70f0e8ce, 0x8b5ffffa, 0xc25d5ec6)

------------------------------------------------------------------------
        Fatal Java Exception detected at Fri Apr 30 11:08:08 2010
------------------------------------------------------------------------

Configuration:
  MATLAB Version:   7.8.0.347 (R2009a)
  MATLAB License:   unknown
  Operating System: Microsoft Windows Vista
  Window System:    Version 6.0 (Build 6002: Service Pack 2)
  Processor ID:     x86 Family 6 Model 10 Stepping 5, GenuineIntel
  Virtual Machine:  Java is not enabled
  Default Encoding:  windows-1252

Java is not enabled

, . jvm? , - Java, JNI- ++ ...

+3
1

, - , - MATLAB - .

- Java. MATLAB Java, , . : . !

MATLAB Engine? MATLAB - "system" "exec"? .


. :

MATLAB- , JVM, MATLAB JVM, -nojvm mclInitializeApplication, , JVM , MATLAB_JAVA JVM, , C:\Program Files\Java\jre6, .

MATLAB, JVM, .

+3

Source: https://habr.com/ru/post/1743478/


All Articles