Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: JVM crashing on Method call

  1. #1
    Junior Member
    Join Date
    Aug 2014
    Thanked 0 Times in 0 Posts

    Default JVM crashing on Method call


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


  2. #2

    Default Re: JVM crashing on Method call

    I guess your Thread can already be attached to the VM, so AttachCurrentThread is not needed. Maybe you just need to check the thread state like this:

    How to obtain JNI interface pointer (JNIEnv *) for asynchronous calls

Similar Threads

  1. HashMap to Call a Method
    By AbarthGT in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 10th, 2012, 01:30 PM
  2. How to call a value from a different method to main
    By CrimsonFlash in forum What's Wrong With My Code?
    Replies: 13
    Last Post: October 22nd, 2011, 06:29 PM
  3. How do I call a method from the main method?
    By JavaStudent1988 in forum Java Theory & Questions
    Replies: 5
    Last Post: October 19th, 2011, 08:37 PM
  4. Call method(s) within the same class
    By mwr76 in forum Object Oriented Programming
    Replies: 8
    Last Post: September 26th, 2011, 12:58 AM
  5. Can i call init() method in destroy method.?
    By muralidhar in forum Java Servlet
    Replies: 1
    Last Post: October 22nd, 2010, 11:18 AM

Tags for this Thread