Im pretty sure the issue is related to multi-thread. which explains why it only happens sometimes:
This is the code that Im using to load in another thread. If I do this in the main thread, the program works every time.
But when I move it back into the loading thread, it crashes sometimes
ByteBuffer ttf = IOUtil.ioResourceToByteBuffer(name, 160 * 1024);
STBTruetype.stbtt_PackBegin(pc, bitmap, BITMAP_W, BITMAP_H, 0, 1);
for ( int i = 0; i < scale.length; i++ ) {
int z = 0;
for (int s = 0; s < samples; s++) {
if (sf[s + (samples * i)] == 0) {
int p = (i * samples + z) * 128 + 32;
chardata.limit(p + 95);
chardata.position(p);
org.lwjgl.stb.STBTruetype.stbtt_PackSetOversampling(pc, 1, 1);
org.lwjgl.stb.STBTruetype.stbtt_PackFontRange(pc, ttf, 0, scale[i], 32, chardata);
z++;
}
if (sf[s + (samples * i)] == 1) {
int p = (i * samples + z) * 128 + 32;
chardata.limit(p + 95);
chardata.position(p);
org.lwjgl.stb.STBTruetype.stbtt_PackSetOversampling(pc, 2, 2);
org.lwjgl.stb.STBTruetype.stbtt_PackFontRange(pc, ttf, 0, scale[i], 32, chardata);
z++;
}
if (sf[s + (samples * i)] == 2) {
int p = (i * samples + z) * 128 + 32;
chardata.limit(p + 95);
chardata.position(p);
org.lwjgl.stb.STBTruetype.stbtt_PackSetOversampling(pc, 3, 1);
org.lwjgl.stb.STBTruetype.stbtt_PackFontRange(pc, ttf, 0, scale[i], 32, chardata);
z++;
}
}
}
STBTruetype.stbtt_PackEnd(pc);
chardata.position(0);
if a call to memory allocate is called at the same time from 2 different threads, will this likely be the cause of the error?
Should all memory allocation be done on a single thread?
This is strange as this issue didn't exist in the previous version (LWJGL 3.1.1 SNAPSHOT build 1), any thoughts on why this may be the case?