Reputation: 1048
Heyho,
I have some kine of weird problem. I created a c library which contains the definition of a struct:
typedef struct rgb_ rgb;
struct rgb_ {
uint8_t r;
uint8_t g;
uint8_t b;
};
Definition of the struct: https://github.com/p000ison/rgb-lm/blob/master/src/lm/led-matrix.h#L12
On the java side I'm calling the libraries' functions:
LmLibrary.lmFontLibrary library = lm.lm_fonts_init();
LmLibrary.lmFont font = lm.lm_fonts_font_new(library, ... font ..., 20);
for (int x = 0; x < 32; x++) {
for (int y = 0; y < 32; y++) {
new rgb_.ByValue(); //<-------- Important line
lm.lm_matrix_set_pixel(matrix, (short) x, (short) y, RED);
}
}
lm.lm_fonts_print_string(library, matrix, "test", font, (short) 0, (short) 2, RED);
lm.lm_fonts_font_free(library, font);
(https://github.com/p000ison/rgb-lm/blob/master/java/src/main/java/lm/Main.java#L35)
When calling with the "Important line" my programm get's a SIGSEGV at some "random" point. By removing that line it works just fine.
It's no problem of the c library as the test c programm runs fine:
lmFontLibrary *library = lm_fonts_init();
lmFont *font = lm_fonts_font_new(library, "/usr/share/fonts/truetype/msttcorefonts/arial.ttf", 20);
for (x = 0; x < 32; ++x) {
for (y = 0; y < 32; ++y) {
rgb blue = {0, 0, 255};
lm_matrix_set_pixel(matrix, x, y, blue);
};
}
lm_fonts_print_string(library, matrix, "Fuck", font, 0, 2, color);
(https://github.com/p000ison/rgb-lm/blob/master/examples/simple_pixels.c)
The functions which get called: https://github.com/p000ison/rgb-lm/blob/master/src/lm/font.c
EDIT: I figured out which line caused my library to crash: https://github.com/p000ison/rgb-lm/blob/master/src/lm/font.c#L97 I think this is random and has nothing to do with the font library.
EDIT: Running JNA 4.1.0
Upvotes: 0
Views: 88
Reputation: 1048
So after tying a new more things which always lead to some kind of memory corruption I tried to use the jna version distributed by my linux distribution. The provided version was 3.2.7 by the libjna-java debian package.
After installing the packet and running my java programm with it everything workes great.
Not a bit c pro, but it seems like JNA overwrote some parts of my heap.
Some more information about the test envirnoment:
JVM crash: http://pastebin.com/dFFx4abC
Upvotes: 1