sejda-pdf / webp-imageio

Java ImageIO WebP support
Apache License 2.0
198 stars 74 forks source link

JVM Crash with SIGSEGV #3

Closed Firstmol closed 4 years ago

Firstmol commented 4 years ago

Hello, I'm using the lib, but I got the error like here https://bitbucket.org/luciad/webp-imageio/issues/19/jvm-crash. @ediweissmann @pepijnve What do you think about that? Do you mind if I do an MR with a possible solution to this problem?

pepijnve commented 4 years ago

A cleaner way to solve this than the suggested PR (while still requiring minimal code changes) might be to add a ThreadLocal encode and decode options field to WebP class. Then wrap the native encode and decode calls in something like this

try {
  decodeThreadLocal.set(aOptions);
  int[] pixels = decode(aOptions.fPointer, aData, aOffset, aLength, aOut, ByteOrder.nativeOrder().equals(ByteOrder.BIG_ENDIAN));
} finally {
  decodeThreadLocal.remove();
}

The end result is the same, but this is a more explicit way of expressing what you're actually trying to do.

pepijnve commented 4 years ago

You can apply the same pattern wherever native objects need to be retained of course. I saw in the original PR that this was needed for aImage in encode as well.

Firstmol commented 4 years ago

Thank you! I think it is not necessary for the aImage(We discussed about that in the PR) .

Firstmol commented 4 years ago

@ediweissmann сould you post a new version to mavencentral repo pls? For now there is only 0.1.2 latest

ediweissmann commented 4 years ago

thanks for the PR, 0.1.5 should be on it's way to Maven Central