Hi,

I'm currently trying to get a Java-Implementation for the Recast-Navigation Project to work on Windows. The Java-side Library and the JNI-Code is not written by myself. But the author was only able to compile the native library for Linux, as he doesn't own Windows. So I wanted to help him and tried to compile the Library for Windows. I included the c++ files from the Original project and the Wrapper made with SWIG (also made by the author of the Java-Port). I then compiled it with the g++ compiler using cygwin.
But when I try to call the native Library from Java the JVM crashes every time. With the JVM option "-verbose:jni" I discovered that the crash happened most times after calling one method (rcAllocHeightfield()).
I did some tests:
1) I removed all the code from the method of the native library. Then the JVM did not crash at this point but a bit later because of the missing return statement.
2) I replaced the code of the method in the native library with some testing code e.g. write something to a file. Then the crash happened again in this method.
3) I copied the code of the method to a new project and run it directly from Netbeans. Everything was fine and it didn't crashed.
I'm neither an expert in JNI nor in C++ but it seems to me that the crash happens if there is any code in this method!?

Source Code:
From the C++ source File:
rcHeightfield* rcAllocHeightfield()
{
 
         return 0;
	rcHeightfield* hf = (rcHeightfield*)rcAlloc(sizeof(rcHeightfield), RC_ALLOC_PERM);
	memset(hf, 0, sizeof(rcHeightfield));
	return hf;
}
From the Wrapper made with SWIG:
SWIGEXPORT jlong JNICALL Java_com_jme3_ai_navigation_utils_RecastJNI_rcAllocHeightfield(JNIEnv *jenv, jclass jcls) {
  jlong jresult = 0 ;
  rcHeightfield *result = 0 ;
 
  (void)jcls;
  result = (rcHeightfield *)rcAllocHeightfield();
  *(rcHeightfield **)&jresult = result;
  return jresult;
}

If you need any more source code just say it.

I hope somebody can help me because I have no idea where to start.

hololol2