What's wrong with the following JavaCV code? I try to populate CvSeq for further work, but the JVM almost reliably crashes with EXCEPTION_ACCESS_VIOLATION at various places, most often at [msvcr100.dll+0x3c19b] memcpy+0x20b
or [opencv_core243.dll+0x61793] cvSeqPush+0x133
public static void main(String[] args) {
CvMemStorage memStorage = CvMemStorage.create();
CvSeq seq = cvCreateSeq(0, Loader.sizeof(CvSeq.class),
Loader.sizeof(CvPoint.class), memStorage);
for (int j=0; j<1000000; j++) {
CvPoint cvPoint = cvPoint(j, j+1);
System.out.println(j);
cvSeqPush(seq, cvPoint);
}
}
In my configuration it fails most often after about 50000 iterations, but sometimes at other count or not at all. There is apparently some allocation/deallocation error. And it reproduces only when not running in debug mode.
If I explicitly call System.gc()
after 20000 iterations, it fails inside cvSeqPush
right after the GC (or 1-2 iterations later, probably because pointer from deallocated space happens to point to correct address). Or if I set both Xmx
and Xms
parameters, it fails sooner or later. Probably something in use is automagically deallocated.