Skip to content

Commit 2ee4332

Browse files
authored
JNI improvements (#886)
Large refactoring of the Java Wrapper, focussing on error handling, documentation, completeness, and usability improvements. Fixes #880. This includes several breaking changes. Not all breaking changes are listed here explicitly. But in all cases, it should be easy for clients to update their code to the new state. The most important changes for the Java Wrapper are: - Made `deflateZstd`, `deflateZLIB`, and `createFromMemory` available in the `KtxTexture2` class - Fixed a bug where the `KtxBasisParams#setInputSwizzle` function caused data corruption - Increased the consistency of the naming and handling of constants: - All constant names are `UPPER_SNAKE_CASE`, omitting common prefixes - Classes that define constants offer a `stringFor` function that returns the string representation of a constant - The `KtxCreateStorage` class was renamed to `KtxTextureCreateStorage` - The `KtxPackUASTCFlagBits` class was renamed to `KtxPackUastcFlagBits` - Improved error handling: - When functions receive a parameter that is `null`, then this will no longer crash the JVM, but throw a `NullPointerException` instead - When `setInputSwizzle` receives invalid arguments, then an `IllegalArgumentException` will be thrown - When one of the `create...` family of functions causes an error, meaning that the respective `KtxTexture2` object cannot be created, then a `KtxException` will be thrown - Added JavaDocs, and enabled the generation of JavaDocs as part of the Maven build process - Internal improvements (like JNI field caching, and avoiding to call JNI functions with pending exceptions)
1 parent 4c8a2e0 commit 2ee4332

35 files changed

+4565
-955
lines changed

interface/java_binding/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ add_library(ktx-jni SHARED
2828
src/main/cpp/KtxTexture.cpp
2929
src/main/cpp/KtxTexture1.cpp
3030
src/main/cpp/KtxTexture2.cpp
31+
src/main/cpp/KtxErrorCode.cpp
3132
src/main/cpp/libktx-jni.cpp
3233
${CMAKE_CURRENT_BINARY_DIR}/ktx-jni.manifest
3334
)

interface/java_binding/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,19 @@
144144
</execution>
145145
</executions>
146146
</plugin>
147+
<plugin>
148+
<groupId>org.apache.maven.plugins</groupId>
149+
<artifactId>maven-javadoc-plugin</artifactId>
150+
<version>3.6.3</version>
151+
<executions>
152+
<execution>
153+
<id>attach-javadocs</id>
154+
<goals>
155+
<goal>jar</goal>
156+
</goals>
157+
</execution>
158+
</executions>
159+
</plugin>
147160
<!--
148161
<plugin>
149162
<groupId>org.codehaus.mojo</groupId>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (c) 2024, Khronos Group and Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include "libktx-jni.h"
7+
#include <iostream>
8+
9+
extern "C" JNIEXPORT jstring JNICALL Java_org_khronos_ktx_KtxErrorCode_createString(JNIEnv *env, jclass, jint error)
10+
{
11+
KTX_error_code errorNative = KTX_error_code(error);
12+
const char* errorStringNative = ktxErrorString(errorNative);
13+
14+
// If this causes an OutOfMemoryError, then it will return
15+
// 'null', with the OutOfMemoryError pending
16+
jstring errorString = env->NewStringUTF(errorStringNative);
17+
return errorString;
18+
}
19+

0 commit comments

Comments
 (0)