2 messages in net.java.dev.jna.usersproblems getting back results in nest...
FromSent OnAttachments
sylv...@free.frJan 9, 2008 2:08 am 
Timothy WallJan 14, 2008 6:37 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:problems getting back results in nested structuresActions...
From:sylv...@free.fr (sylv@free.fr)
Date:Jan 9, 2008 2:08:29 am
List:net.java.dev.jna.users

Hi Timothy !

First of all, best wishes for this new year.

I am using more and more of the JNA tools in my code. So far everything was ok but since yesterday I face a new problem and I still can get rid of it...

I am calling this C function from my Java code: int GcFitVarioMap (VMAP_FIT_PARAM *vmap_fit_param, VARIO_MAP *vario_map_fit_xy, VARIO_MAP *vario_map_fit_xz, VARIO_MAP *vario_map_fit_yz) Parameters: vmap_fit_param Structure containing the parameters for variogram map fitting (Input) vario_map_fit_xy Structure containing the resulting fitted variogram map in the XY plan (Output) vario_map_fit_xz Structure containing the resulting fitted variogram map in the XZ plan (Output) vario_map_fit_yz Structure containing the resulting fitted variogram map in the YZ plan (Output)

From some fprintf placed in the C sources, fields of the VMAP_FIT_PARAM input are correctly passed to the C function.

The VARIO_MAP structure fields are defined as follows (as from the doc of the library): int dimension GRID_INFO grid int vario_type VARIO_LAG_INFO * vmp_main VARIO_LAG_INFO * vmp_co VARIO_LAG_INFO * vmp_cross float missing_float

grid is a GRID_INFO structure. I also checked that it was correctly passed to and read in the library. It is ok. vmp_main, vmp_co and vmp_cross are arrays of grid.nx*grid.ny*grid.nz VARIO_LAG_INFO structures into which the computation results are stored by the library.

Here is how I put together the call to the library (I only focus on the VARIO_MAP structure initialisation here):

GRID_INFO.ByReference gi = new GRID_INFO.ByReference(0f, 0f, 0f, 0f, vmp.getLag(), vmp.getLag(), 0f, vmp.getNblag(), vmp.getNblag(), 1); VARIO_LAG_INFO.ByReference vli_main = new VARIO_LAG_INFO.ByReference(); VARIO_LAG_INFO.ByReference[] vlis_main = (VARIO_LAG_INFO.ByReference[]) vli_main.toArray((2* vmp.getNblag() +1)*(2* vmp.getNblag() +1)); VARIO_LAG_INFO.ByReference vli_co = new VARIO_LAG_INFO.ByReference(); VARIO_LAG_INFO.ByReference[] vlis_co = (VARIO_LAG_INFO.ByReference[]) vli_co.toArray((2* vmp.getNblag() +1)*(2* vmp.getNblag() +1)); VARIO_LAG_INFO.ByReference vli_cross = new VARIO_LAG_INFO.ByReference(); VARIO_LAG_INFO.ByReference[] vlis_cross = (VARIO_LAG_INFO.ByReference[]) vli_cross.toArray((2* vmp.getNblag() +1)*(2* vmp.getNblag() +1)); VARIO_MAP map_xy = new VARIO_MAP(DIMENSION.TWO_D, gi, VARIOGRAPHY_TYPE.DIRECT_VARIOGRAPHY, vlis_main, vlis_co, vlis_cross, GcAPIconstants.FLT_NOVALUE); int retour = GcAPIcalls.INSTANCE.GcFitVarioMap(vmapfp, map_xy, null, null); // I have two null outputs because I am in a situation where I do not need vario_map_fit_xz and vario_map_fit_yz. This situation is managed by my library.

public class VARIO_MAP extends Structure {

public int dimension; public GRID_INFO.ByReference grid; public int vario_type; public VARIO_LAG_INFO.ByReference[] vmp_main; public VARIO_LAG_INFO.ByReference[] vmp_co; public VARIO_LAG_INFO.ByReference[] vmp_cross; public float missing_float;

public VARIO_MAP(int dimension, GRID_INFO.ByReference grid, int vario_type, VARIO_LAG_INFO.ByReference[] vlis_main, VARIO_LAG_INFO.ByReference[] vlis_co, VARIO_LAG_INFO.ByReference[] vlis_cross, float missing_float) { this.dimension = dimension; this.grid = grid; this.vario_type = vario_type; this.vmp_main = vlis_main; this.vmp_co = vlis_co; this.vmp_cross = vlis_cross; this.missing_float = missing_float; } }

I checked that for all elements of vmp_main (a 101x101 map = 10201 elements in my case), values I want to get back (field "semi_vario" from each VARIO_LAG_INFO of vmap_main) are computed by the library. Everything is fine during the computation. But just at the very end, I have a crash with the following report:

# # An unexpected error has been detected by HotSpot Virtual Machine: # # SIGSEGV (0xb) at pc=0x00002aaab6114c03, pid=32361, tid=1095125328 # # Java VM: Java HotSpot(TM) 64-Bit Server VM (1.5.0_08-b03 mixed mode) # Problematic frame: # C [jna35720.tmp+0x6c03] Java_com_sun_jna_Pointer__1getLong+0x74 #

[...I cut this part of the report I am not sure all these numbers were helpful...]

Stack: [0x0000000041364000,0x0000000041465000), sp=0x00000000414634f0, free space=1021k Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code) C [jna35720.tmp+0x6c03] Java_com_sun_jna_Pointer__1getLong+0x74

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code) J com.sun.jna.Pointer._getLong(J)J J com.sun.jna.Structure.readField(Lcom/sun/jna/Structure$StructField;)V J com.sun.jna.Structure.read()V v ~I2CAdapter j com.sun.jna.Structure.readField(Lcom/sun/jna/Structure$StructField;)V+1286 v ~C2IAdapter J com.sun.jna.Structure.read()V v ~I2CAdapter j com.sun.jna.Function.invoke(Ljava/lang/Class;[Ljava/lang/Object;Ljava/util/Map;)Ljava/lang/Object;+304 j com.sun.jna.Library$Handler.invoke(Ljava/lang/Object;Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object;+344 j $Proxy0.GcFitVarioMap(Lstructures/VMAP_FIT_PARAM;Lstructures/VARIO_MAP;Lstructures/VARIO_MAP;Lstructures/VARIO_MAP;)I+29 j sismage.math.statsAndGeostats.Variogram.compute_2DVariogramModel_GCAPI(Lsismage/math/statsAndGeostats/GcAPIutils$VarioModelParameters;)[[F+254 j sismage.gui.depth.AdjustDepthMapDialog$VarioComputationThread.run()V+607 v ~StubRoutines::call_stub

Sorry for the length of the e-mail, but as you have seen, the structures I use are highly nested, and I wanted to provide you with the most precise information. Let me know if you need more details.

So finally my question is: what's wrong with what I did...and how can I make it to get back my results in my Java code ?

Thanks in advance for your help.

Sylvain.