java - JNA : Exception_Access_Violation

标签 java jna

我用JNA在libpotrace.dll中调用了这个函数,这个函数是:

potrace_state_t *potrace_trace(const potrace_param_t *param,
const potrace_bitmap_t *bm);

库中的参数是:

typedef unsigned long potrace_word;

struct potrace_bitmap_s {
  int w, h;              /* width and height, in pixels */
  int dy;                /* words per scanline (not bytes) */
  potrace_word *map;     /* raw data, dy*h words */
};
typedef struct potrace_bitmap_s potrace_bitmap_t;

struct potrace_param_s {
  int turdsize;        /* area of largest path to be ignored */
  int turnpolicy;      /* resolves ambiguous turns in path decomposition */
  double alphamax;     /* corner threshold */
  int opticurve;       /* use curve optimization? */
  double opttolerance; /* curve optimization tolerance */
  potrace_progress_t progress; /* progress callback function */
};
typedef struct potrace_param_s potrace_param_t;

在我的java代码中我有:

public class Potrace_bitmap_t extends Structure{
    public int w=36;
    public int h=2; /* width and height, in pixels */
    public int dy=2; /* words per scanline (not bytes) */   
    public long [] map =new long[dy*h];
}

public class potrace_param_t  extends Structure{    
    //public static class ByValue extends Nat implements Structure.ByValue { }

    public int turdsize=0;
    public int turnpolicy=0;
    public double alphamax=0;
    public int opticurve=0;
    public double opttolerance=0;   

}

potrace_param_t na=lib.potrace_param_default();/*This function returns a fresh set of tracing parameters, initialized to defaults.
Potrace_bitmap_t bm=new Potrace_bitmap_t();
bm.map[0]=1113215L;
bm.map[1]=4026531840L;
bm.map[2]=3276415L;
bm.map[3]=4026531840L;
Potrace_state_t pt=lib.potrace_trace(na, bm);

当我执行 potrace_trace() 时出现此错误:

An unexpected error has been detected by Java Runtime Environment:

 EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x6504fbee, pid=2728, tid=2436

 Java VM: Java HotSpot(TM) Client VM (1.6.0_03-b05 mixed mode, sharing)
 Problematic frame:
 C  [libpotrace.dll+0xfbee]

 An error report file with more information is saved as hs_err_pid2728.log

 If you would like to submit a bug report, please visit:
  http://java.sun.com/webapps/bugreport/crash.jsp

我不明白为什么。 谢谢。

最佳答案

Potrace_bitmap_t 的第四个字段应该是一个指针,而不是 64 位值的数组。您缺少 potrace_param_t 的最后一个字段。

关于java - JNA : Exception_Access_Violation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/947069/

相关文章:

java - 在不传递上下文的情况下访问类中的共享首选项

java - 在现有代码中添加/删除某些代码的设计/模式应该是什么

java - JNA - 在从 DLL 传回的 C++ 实例上调用方法

java - 如何使用 java 实现类似 alt+tab 的功能?

java - 是由 jvm 限制的 C 代码在 JNA(或 JNI)中分配的内存(参数 -Xmx 或架构 32/64)

java - 将架构名称添加到 Spring 数据中的实体?

java - ZK 日期框与 java.time

java - JNA 传递的值未更新

java - 使用 JNA 从 Win32 ListView 检索项目文本

java - 将 Jersey JUL 日志记录重定向到 Log4j2