Matlab crashes on library initialize when called from Java

Posted by David Sauter on Stack Overflow See other posts from Stack Overflow or by David Sauter
Published on 2010-04-30T09:33:07Z Indexed on 2010/04/30 9:37 UTC
Read the original article Hit count: 505

Hello everyone. The setup I have is I'm using a Java application to call native C-code with JNI, which in turn starts up the MATLAB runtime and calls functions on it (I know there are other solutions to call MATLAB methods from Java).

The problem is that the MATLAB engine crashes at some point during the initialization and I don't know what's causing it exactly. The crash causes my jvm to terminate, I assume it's some kind of memory corruption.

The C++ code calling MATLAB functions that is actually crashing is

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;
      }
    } ...

The function <library>Initialize() crashes here, the Java error log reads

Stack Trace:
  [0] jmi.dll:0x793f4175(0x7934cdca, 1, 0x7937e67c "à;.y`[email protected] 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

I really have no idea what could be wrong. Is there not enough memory from the jvm? I guess the problem is somehow related to Java, since calling the JNI functions from a simple test C++ program works fine...

Thanks

© Stack Overflow or respective owner

Related posts about matlab

Related posts about java-native-interface