Skip to content

Commit

Permalink
Fix JNI function name for getDataSizeUncompressed (#957)
Browse files Browse the repository at this point in the history
A small fix for the JNI bindings:

 The function signature for `getDataSizeUncompressed` was given as 
`Java_org_khronos_KTXTexture_getDataSizeUncompressed` but must be
`Java_org_khronos_ktx_KtxTexture_getDataSizeUncompressed` (matching the
full package- and class name)

Currently, calling this function would result in a
`java.lang.UnsatisfiedLinkError:
org.khronos.ktx.KtxTexture.getDataSizeUncompressed()J`

I also added a test that _might_ look useless at the first glance: It
just creates a texture, and calls all the `native` "getter" functions on
that (without any assertion). The point of that test is that it would
have _prevented_ this kind of error...
  • Loading branch information
javagl authored Nov 15, 2024
1 parent 21659f8 commit f3902db
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion interface/java_binding/src/main/cpp/KtxTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_khronos_ktx_KtxTexture_getDataSize(J
return static_cast<jlong>(ktxTexture_GetDataSize(texture));
}

extern "C" JNIEXPORT jlong JNICALL Java_org_khronos_KTXTexture_getDataSizeUncompressed(JNIEnv *env, jobject thiz)
extern "C" JNIEXPORT jlong JNICALL Java_org_khronos_ktx_KtxTexture_getDataSizeUncompressed(JNIEnv *env, jobject thiz)
{
ktxTexture *texture = get_ktx_texture(env, thiz);
if (texture == NULL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,4 +599,47 @@ public void testSupercompressionZLIB() throws IOException {

t.destroy();
}

@Test
public void testBindings() {
Path testKtxFile = Paths.get("")
.resolve("../../tests/testimages/astc_ldr_4x4_FlightHelmet_baseColor.ktx2")
.toAbsolutePath()
.normalize();

// The purpose of this test is to check the bindings for the 'native'
// functions that only return a value. When the binding for one of
// these functions is not implemented properly, then trying to call
// it will cause an 'UnsatisfiedLinkError'.
// This does not cover all 'native' functions: Some of them can only
// sensibly be called in the context of the other tests.

KtxTexture2 texture = KtxTexture2.createFromNamedFile(testKtxFile.toString(),
KtxTextureCreateFlagBits.NO_FLAGS);

// Native getter methods from the 'KtxTexture2' class
texture.getOETF();
texture.getPremultipliedAlpha();
texture.needsTranscoding();
texture.getSupercompressionScheme();
texture.getVkFormat();

// Native getter methods from the 'KtxTexture' class
texture.isArray();
texture.isCubemap();
texture.isCompressed();
texture.getGenerateMipmaps();
texture.getBaseWidth();
texture.getBaseHeight();
texture.getBaseDepth();
texture.getNumDimensions();
texture.getNumLevels();
texture.getNumFaces();
texture.getDataSize();
texture.getDataSizeUncompressed();
texture.getElementSize();
texture.getRowPitch(0);
texture.getImageSize(0);
}

}

0 comments on commit f3902db

Please sign in to comment.