"Fix" random crash inside stbi_load_from_memory caused by JVM releasing DirectByteBuffer while it is being used
This commit is contained in:
parent
cb38ecfde7
commit
bd8d0e58df
@ -315,12 +315,16 @@ class Image private constructor(
|
|||||||
val getHeight = intArrayOf(0)
|
val getHeight = intArrayOf(0)
|
||||||
val components = intArrayOf(0)
|
val components = intArrayOf(0)
|
||||||
|
|
||||||
|
val idata = it.readDirect()
|
||||||
|
|
||||||
val data = STBImage.stbi_load_from_memory(
|
val data = STBImage.stbi_load_from_memory(
|
||||||
it.readDirect(),
|
idata,
|
||||||
getWidth, getHeight,
|
getWidth, getHeight,
|
||||||
components, 0
|
components, 0
|
||||||
) ?: throw IllegalArgumentException("File $it is not an image or it is corrupted")
|
) ?: throw IllegalArgumentException("File $it is not an image or it is corrupted")
|
||||||
|
|
||||||
|
synchronized(idata) {} // memory barrier
|
||||||
|
|
||||||
val address = MemoryUtil.memAddress(data)
|
val address = MemoryUtil.memAddress(data)
|
||||||
Starbound.CLEANER.register(data) { STBImage.nstbi_image_free(address) }
|
Starbound.CLEANER.register(data) { STBImage.nstbi_image_free(address) }
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user