mgsx-dev / gdx-gltf

GLTF 2.0 3D format support and PBR shader implementation for LibGDX
Apache License 2.0
214 stars 50 forks source link

Native memory leak: pixmaps are never released #109

Closed dar-dev closed 1 year ago

dar-dev commented 1 year ago

Pixmaps are never released after loading glTF images, see: https://github.com/mgsx-dev/gdx-gltf/blob/00dc40ea58b99e4aefb01644c595916e0a512cee/gltf/src/net/mgsx/gltf/loaders/shared/GLTFLoaderBase.java#L145

Here's a simple test code to replicate:

for (;;)
{
    final GLBLoader loader = new GLBLoader();
    SceneAsset asset = loader.load(Gdx.files.absolute(filename), true);

    Thread.sleep(100);

    loader.dispose();
    asset.dispose();
}
mgsx-dev commented 1 year ago

Good catch, it was a regression introduced in https://github.com/mgsx-dev/gdx-gltf/commit/df61161368beef8e36ba4590b788e2e968e5b6a3 It should be OK now

dar-dev commented 1 year ago

That's good. Now, how can I avoid the pixmap loading when loading glTF textures? (are pixmaps needed?)

--

mgsx-dev commented 1 year ago

Yes, that was the purpose of the change : sometimes you want to get texture pixels. And they were disposed at the wrong time. If you don't want to keep them, you could dispose them after SceneAsset loading (by disposing them and nullify the array)

mgsx-dev commented 1 year ago

no, you need to decode PNG/JPG into Pixmap prior to upload pixels to GPU.