LWJGL / lwjgl3

LWJGL is a Java library that enables cross-platform access to popular native APIs useful in the development of graphics (OpenGL, Vulkan, bgfx), audio (OpenAL, Opus), parallel computing (OpenCL, CUDA) and XR (OpenVR, LibOVR, OpenXR) applications.
https://www.lwjgl.org
BSD 3-Clause "New" or "Revised" License
4.76k stars 636 forks source link

NPE on Assimp.aiReleaseImport #827

Closed Nerogar closed 1 year ago

Nerogar commented 1 year ago

Version

3.3.2 (nightly)

Platform

Windows x64

JDK

jdk-18.0.1.10-hotspot (temurin)

Module

Assimp

Bug description

Calling Assimp.aiReleaseImport right after Assimp.aiImportFileFromMemoryWithProperties on a collada file throws a NPE. The same code does not throw exceptions with version 3.3.1, only the 3.3.2 snapshot. The line that throws the exception is check(memGetAddress(struct + AIScene.MSKELETONS)); in AIScene.validate, introduced with this commit: 91a982dd5e8f2e0019dbf0a509ca6a9b00d69670

Tested with jdk 18 and 19. Both throw the same exception.

Example code:

Main.java: ``` package test; import org.lwjgl.BufferUtils; import org.lwjgl.assimp.*; import java.io.File; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.file.Files; public class Main { private static ByteBuffer readFile(String filename) { byte[] fileBytes; try { File file = new File(filename); fileBytes = Files.readAllBytes(file.toPath()); } catch (IOException e) { e.printStackTrace(); return null; } ByteBuffer fileByteBuffer = BufferUtils.createByteBuffer(fileBytes.length + 1); fileByteBuffer.put(fileBytes); fileByteBuffer.put((byte) 0); fileByteBuffer.flip(); return fileByteBuffer; } public static void load(String filename) { ByteBuffer fileByteBuffer = readFile(filename); AIScene aiScene = Assimp.aiImportFileFromMemoryWithProperties( fileByteBuffer, 0, (ByteBuffer) null, Assimp.aiCreatePropertyStore() ); Assimp.aiReleaseImport(aiScene); } public static void main(String[] args) { load("test.dae"); } } ``` build.gradle: ``` plugins { id 'java' id 'application' } repositories { mavenCentral() maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } } version = '0.1.0' sourceCompatibility = 1.17 // lwjgl project.ext.lwjglVersion = "3.3.2-SNAPSHOT" // <- this does not work //project.ext.lwjglVersion = "3.3.1" // <- this works project.ext.lwjglNatives = "natives-windows" dependencies { implementation platform("org.lwjgl:lwjgl-bom:$lwjglVersion") implementation "org.lwjgl:lwjgl:$lwjglVersion" runtimeOnly "org.lwjgl:lwjgl:$lwjglVersion:$lwjglNatives" implementation "org.lwjgl:lwjgl-assimp:$lwjglVersion" runtimeOnly "org.lwjgl:lwjgl-assimp:$lwjglVersion:$lwjglNatives" } mainClassName = 'test.Main' ``` test.dae (blender default cube exported with default settings): ``` Blender User Blender 3.0.1 commit date:2022-01-25, commit time:17:19, hash:dc2d18018171 2022-11-16T22:51:59 2022-11-16T22:51:59 Z_UP 39.59775 1.777778 0.1 100 0 0 10 1000 1000 1000 1 0 0.00111109 0 0 1 1 1 1 1 0 0 0 1000 29.99998 75 0.15 0 1 2 0.04999995 30.002 1 3 2880 3 1 1 0.1 0.1 1 0 0 0 1 0.8 0.8 0.8 1 1.45 1 1 1 1 1 -1 1 -1 1 1 -1 -1 -1 1 1 -1 1 -1 -1 -1 1 -1 -1 -1 0 0 1 0 -1 0 -1 0 0 0 0 -1 1 0 0 0 1 0 0.875 0.5 0.625 0.75 0.625 0.5 0.625 0.75 0.375 1 0.375 0.75 0.625 0 0.375 0.25 0.375 0 0.375 0.5 0.125 0.75 0.125 0.5 0.625 0.5 0.375 0.75 0.375 0.5 0.625 0.25 0.375 0.5 0.375 0.25 0.875 0.5 0.875 0.75 0.625 0.75 0.625 0.75 0.625 1 0.375 1 0.625 0 0.625 0.25 0.375 0.25 0.375 0.5 0.375 0.75 0.125 0.75 0.625 0.5 0.625 0.75 0.375 0.75 0.625 0.25 0.625 0.5 0.375 0.5

4 0 0 2 0 1 0 0 2 2 1 3 7 1 4 3 1 5 6 2 6 5 2 7 7 2 8 1 3 9 7 3 10 5 3 11 0 4 12 3 4 13 1 4 14 4 5 15 1 5 16 5 5 17 4 0 18 6 0 19 2 0 20 2 1 21 6 1 22 7 1 23 6 2 24 4 2 25 5 2 26 1 3 27 3 3 28 7 3 29 0 4 30 2 4 31 3 4 32 4 5 33 0 5 34 1 5 35

0.6859207 -0.3240135 0.6515582 7.358891 0.7276763 0.3054208 -0.6141704 -6.925791 0 0.8953956 0.4452714 4.958309 0 0 0 1 -0.2908646 -0.7711008 0.5663932 4.076245 0.9551712 -0.1998834 0.2183912 1.005454 -0.05518906 0.6045247 0.7946723 5.903862 0 0 0 1 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1
```

Stacktrace or crash log output

Exception in thread "main" java.lang.NullPointerException
    at org.lwjgl.system.Checks.check(Checks.java:188)
    at org.lwjgl.assimp.AIScene.validate(AIScene.java:541)
    at org.lwjgl.assimp.Assimp.naiReleaseImport(Assimp.java:3348)
    at org.lwjgl.assimp.Assimp.aiReleaseImport(Assimp.java:3361)
    at test.Main.load(Main.java:41)
    at test.Main.main(Main.java:45)
Spasi commented 1 year ago

Thank you @Nerogar, it will be fixed in the next snapshot.