Sign in to follow this  
fazekaim

[java] how to create a working dll?

Recommended Posts

fazekaim    118
Hello, i would like to create a dll to an existing C code. i created the jni C and H code, i compiled it, i created a test code:
static{
  System.loadLibrary("helpsm");
  HelpSMServices.updateMtx2();
  HelpSMServices.updateMtx2();
}


this works fine... when i want to make this calls from the jogl display method i got this: # # An unexpected error has been detected by HotSpot Virtual Machine: # # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x6d73c55d, pid=1560, tid=3080 # # Java VM: Java HotSpot(TM) Client VM (1.5.0_05-b05 mixed mode, sharing) # Problematic frame: # V [jvm.dll+0x8c55d] # # An error report file with more information is saved as hs_err_pid1560.log # # If you would like to submit a bug report, please visit: # http://java.sun.com/webapps/bugreport/crash.jsp # What can i do? (i'm using visual studio 6 for the dll creation) Thanks...

Share this post


Link to post
Share on other sites
fazekaim    118
My Java class:


static {
public class LispSMServices {
System.loadLibrary("lispsm");
/*LispSMServices.updateEyeMtx2();
LispSMServices.updateEyeMtx2();
LispSMServices.updateEyeMtx2();
//double[] res = LispSMServices.getEyeView();
System.out.println( "!!!!!!!!!"+eyeView.length+" "+eyeView[0]+" "+eyeView[1]+" "+eyeView[2] );*/

}

public static native void perspectiveDeg( double vFovy, double ratio, double vNearDis, double vFarDis );
public static native double[] getEyeView();
public static native double[] getProjection();
public static native double[] getProjEyeView();
public static native double[] getInvEyeProjView();
public static native double[] getLightView();
public static native double[] getLightProjection();
public static native double[] getLightProjView();
public static native void updateEyeMtx();
public static native void updateLightMtx();
public static native void setSceneSize( double minX, double minY, double minZ, double maxX, double maxY, double maxZ );
public static native void setEyePos( double xPos, double yPos, double zPos );
public static native void setViewDir( double xDir, double yDir, double zDir );
public static native void setLightDir( double xDir, double yDir, double zDir );
}



.h generated by javah:

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class witer_engine_math_lispSM_LispSMServices */

#ifndef _Included_witer_engine_math_lispSM_LispSMServices
#define _Included_witer_engine_math_lispSM_LispSMServices
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: witer_engine_math_lispSM_LispSMServices
* Method: perspectiveDeg
* Signature: (DDDD)V
*/

JNIEXPORT void JNICALL Java_witer_engine_math_lispSM_LispSMServices_perspectiveDeg
(JNIEnv *, jclass, jdouble, jdouble, jdouble, jdouble);

/*
* Class: witer_engine_math_lispSM_LispSMServices
* Method: getEyeView
* Signature: ()[D
*/

JNIEXPORT jdoubleArray JNICALL Java_witer_engine_math_lispSM_LispSMServices_getEyeView
(JNIEnv *, jclass);

/*
* Class: witer_engine_math_lispSM_LispSMServices
* Method: getProjection
* Signature: ()[D
*/

JNIEXPORT jdoubleArray JNICALL Java_witer_engine_math_lispSM_LispSMServices_getProjection
(JNIEnv *, jclass);

/*
* Class: witer_engine_math_lispSM_LispSMServices
* Method: getProjEyeView
* Signature: ()[D
*/

JNIEXPORT jdoubleArray JNICALL Java_witer_engine_math_lispSM_LispSMServices_getProjEyeView
(JNIEnv *, jclass);

/*
* Class: witer_engine_math_lispSM_LispSMServices
* Method: getInvEyeProjView
* Signature: ()[D
*/

JNIEXPORT jdoubleArray JNICALL Java_witer_engine_math_lispSM_LispSMServices_getInvEyeProjView
(JNIEnv *, jclass);

/*
* Class: witer_engine_math_lispSM_LispSMServices
* Method: getLightView
* Signature: ()[D
*/

JNIEXPORT jdoubleArray JNICALL Java_witer_engine_math_lispSM_LispSMServices_getLightView
(JNIEnv *, jclass);

/*
* Class: witer_engine_math_lispSM_LispSMServices
* Method: getLightProjection
* Signature: ()[D
*/

JNIEXPORT jdoubleArray JNICALL Java_witer_engine_math_lispSM_LispSMServices_getLightProjection
(JNIEnv *, jclass);

/*
* Class: witer_engine_math_lispSM_LispSMServices
* Method: getLightProjView
* Signature: ()[D
*/

JNIEXPORT jdoubleArray JNICALL Java_witer_engine_math_lispSM_LispSMServices_getLightProjView
(JNIEnv *, jclass);

/*
* Class: witer_engine_math_lispSM_LispSMServices
* Method: updateEyeMtx
* Signature: ()V
*/

JNIEXPORT void JNICALL Java_witer_engine_math_lispSM_LispSMServices_updateEyeMtx
(JNIEnv *, jclass);

/*
* Class: witer_engine_math_lispSM_LispSMServices
* Method: updateLightMtx
* Signature: ()V
*/

JNIEXPORT void JNICALL Java_witer_engine_math_lispSM_LispSMServices_updateLightMtx
(JNIEnv *, jclass);

/*
* Class: witer_engine_math_lispSM_LispSMServices
* Method: setSceneSize
* Signature: (DDDDDD)V
*/

JNIEXPORT void JNICALL Java_witer_engine_math_lispSM_LispSMServices_setSceneSize
(JNIEnv *, jclass, jdouble, jdouble, jdouble, jdouble, jdouble, jdouble);

/*
* Class: witer_engine_math_lispSM_LispSMServices
* Method: setEyePos
* Signature: (DDD)V
*/

JNIEXPORT void JNICALL Java_witer_engine_math_lispSM_LispSMServices_setEyePos
(JNIEnv *, jclass, jdouble, jdouble, jdouble);

/*
* Class: witer_engine_math_lispSM_LispSMServices
* Method: setViewDir
* Signature: (DDD)V
*/

JNIEXPORT void JNICALL Java_witer_engine_math_lispSM_LispSMServices_setViewDir
(JNIEnv *, jclass, jdouble, jdouble, jdouble);

/*
* Class: witer_engine_math_lispSM_LispSMServices
* Method: setLightDir
* Signature: (DDD)V
*/

JNIEXPORT void JNICALL Java_witer_engine_math_lispSM_LispSMServices_setLightDir
(JNIEnv *, jclass, jdouble, jdouble, jdouble);

#ifdef __cplusplus
}
#endif
#endif




and an implementation:

#include "witer_engine_math_lispSM_LispSMServices.h"
#include "lispSM\LispSM.h"
/* Header for class witer_engine_math_lispSM_LispSMServices */


jdoubleArray result;

/*
* Class: witer_engine_math_lispSM_LispSMServices
* Method: perspectiveDeg
* Signature: (DDDD)V
*/

JNIEXPORT void JNICALL Java_witer_engine_math_lispSM_LispSMServices_perspectiveDeg
(JNIEnv *env, jclass cls, jdouble vFovy, jdouble ratio, jdouble vNearDis, jdouble vFarDis){
perspectiveDeg( eyeProjection, vFovy, ratio, vNearDis, vFarDis );
}

/*
* Class: witer_engine_math_lispSM_LispSMServices
* Method: getEyeView
* Signature: ()[D
*/

JNIEXPORT jdoubleArray JNICALL Java_witer_engine_math_lispSM_LispSMServices_getEyeView
(JNIEnv *env, jclass cls){
if( result == 0) result = (*env)->NewDoubleArray( env, 16 );

(*env)->SetDoubleArrayRegion( env, result, 0, 16, eyeView);

return result;
}

/*
* Class: witer_engine_math_lispSM_LispSMServices
* Method: getProjection
* Signature: ()[D
*/

JNIEXPORT jdoubleArray JNICALL Java_witer_engine_math_lispSM_LispSMServices_getProjection
(JNIEnv *env, jclass cls ){
if( result == 0) result = (*env)->NewDoubleArray( env, 16 );

(*env)->SetDoubleArrayRegion( env, result, 0, 16, eyeProjection);

return result;
}

/*
* Class: witer_engine_math_lispSM_LispSMServices
* Method: getProjEyeView
* Signature: ()[D
*/

JNIEXPORT jdoubleArray JNICALL Java_witer_engine_math_lispSM_LispSMServices_getProjEyeView
(JNIEnv *env, jclass cls ){
if( result == 0) result = (*env)->NewDoubleArray( env, 16 );

(*env)->SetDoubleArrayRegion( env, result, 0, 16, eyeProjView);

return result;

}

/*
* Class: witer_engine_math_lispSM_LispSMServices
* Method: getInvEyeProjView
* Signature: ()[D
*/

JNIEXPORT jdoubleArray JNICALL Java_witer_engine_math_lispSM_LispSMServices_getInvEyeProjView
(JNIEnv *env, jclass cls ){
if( result == 0) result = (*env)->NewDoubleArray( env, 16 );

(*env)->SetDoubleArrayRegion( env, result, 0, 16, invEyeProjView);

return result;
}

/*
* Class: witer_engine_math_lispSM_LispSMServices
* Method: getLightView
* Signature: ()[D
*/

JNIEXPORT jdoubleArray JNICALL Java_witer_engine_math_lispSM_LispSMServices_getLightView
(JNIEnv *env, jclass cls ){
if( result == 0) result = (*env)->NewDoubleArray( env, 16 );

(*env)->SetDoubleArrayRegion( env, result, 0, 16, lightView );

return result;
}

/*
* Class: witer_engine_math_lispSM_LispSMServices
* Method: getLightProjection
* Signature: ()[D
*/

JNIEXPORT jdoubleArray JNICALL Java_witer_engine_math_lispSM_LispSMServices_getLightProjection
(JNIEnv *env, jclass cls ){
if( result == 0) result = (*env)->NewDoubleArray( env, 16 );

(*env)->SetDoubleArrayRegion( env, result, 0, 16, lightProjection);

return result;
}

/*
* Class: witer_engine_math_lispSM_LispSMServices
* Method: getLightProjView
* Signature: ()[D
*/

JNIEXPORT jdoubleArray JNICALL Java_witer_engine_math_lispSM_LispSMServices_getLightProjView
(JNIEnv *env, jclass cls ){
if( result == 0) result = (*env)->NewDoubleArray( env, 16 );

(*env)->SetDoubleArrayRegion( env, result, 0, 16, lightProjection );

return result;
}

/*
* Class: witer_engine_math_lispSM_LispSMServices
* Method: updateEyeMtx
* Signature: ()V
*/

JNIEXPORT void JNICALL Java_witer_engine_math_lispSM_LispSMServices_updateEyeMtx
(JNIEnv *env, jclass cls ){
updateEyeMtx();
}

/*
* Class: witer_engine_math_lispSM_LispSMServices
* Method: updateLightMtx
* Signature: ()V
*/

JNIEXPORT void JNICALL Java_witer_engine_math_lispSM_LispSMServices_updateLightMtx
(JNIEnv *env, jclass cls ){
updateLightMtx();
}

/*
* Class: witer_engine_math_lispSM_LispSMServices
* Method: setSceneSize
* Signature: (DDDDDD)V
*/

JNIEXPORT void JNICALL Java_witer_engine_math_lispSM_LispSMServices_setSceneSize
(JNIEnv *env, jclass cls, jdouble minX, jdouble minY, jdouble minZ, jdouble maxX, jdouble maxY, jdouble maxZ ){
sceneAABox.min[0] = minX; sceneAABox.min[1] = minY; sceneAABox.min[2] = minZ;
sceneAABox.min[0] = maxX; sceneAABox.min[1] = maxY; sceneAABox.min[2] = maxZ;
}

/*
* Class: witer_engine_math_lispSM_LispSMServices
* Method: setEyePos
* Signature: (DDD)V
*/

JNIEXPORT void JNICALL Java_witer_engine_math_lispSM_LispSMServices_setEyePos
(JNIEnv *env, jclass cls, jdouble xPos, jdouble yPos, jdouble zPos){
eyePos[0] = xPos; eyePos[1] = yPos; eyePos[2] = zPos;
}

/*
* Class: witer_engine_math_lispSM_LispSMServices
* Method: setViewDir
* Signature: (DDD)V
*/

JNIEXPORT void JNICALL Java_witer_engine_math_lispSM_LispSMServices_setViewDir
(JNIEnv *env, jclass cls, jdouble eyeX, jdouble eyeY, jdouble eyeZ){
viewDir[0] = eyeX; viewDir[1] = eyeY; viewDir[2] = eyeZ;
}

/*
* Class: witer_engine_math_lispSM_LispSMServices
* Method: setLightDir
* Signature: (DDD)V
*/

JNIEXPORT void JNICALL Java_witer_engine_math_lispSM_LispSMServices_setLightDir
(JNIEnv *env, jclass cls, jdouble lightX, jdouble lightY, jdouble lightZ){
lightDir[0] = lightX; lightDir[1] = lightY; lightDir[2] = lightZ;
}



i hope, somebody could help me...

Share this post


Link to post
Share on other sites
Son of Cain    480
Hey, I also have that recent JVM, and I got the SAME error doing something extremely different (I can't remember exactly what it was, but I was programming for swing).

So, it seems there's nothing wrong with our code, but with the JVM itself.

[Edit: Now I see, we weren't doing "something extremely different" if you had the error while calling the JOGL display... which increases the chance of this being a bug, since I was doing swing work]

Son Of Cain

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this