Skip to content

NPE on AbstractShadowFilter Deserialization #2404

@capdevon

Description

@capdevon

here is the test class to reproduce the error:
(The problem affects all xxxLightShadowFilter classes…)

package com.test;

import com.jme3.app.SimpleApplication;
import com.jme3.export.binary.BinaryExporter;
import com.jme3.light.DirectionalLight;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.post.FilterPostProcessor;
import com.jme3.post.filters.FXAAFilter;
import com.jme3.post.filters.TranslucentBucketFilter;
import com.jme3.shadow.DirectionalLightShadowFilter;
import com.jme3.system.AppSettings;

public class Issue_DirLightShadowFilter_Deser extends SimpleApplication {

    public static void main(String[] args) {
        AppSettings settings = new AppSettings(true);
        settings.setResolution(640, 480);
        settings.setFrameRate(60);

        Issue_DirLightShadowFilter_Deser app = new Issue_DirLightShadowFilter_Deser();
        app.setSettings(settings);
        app.setShowSettings(false);
        app.setPauseOnLostFocus(false);
        app.start();
    }
    
    @Override
    public void simpleInitApp() {
        DirectionalLight light = new DirectionalLight();
        light.setDirection(new Vector3f(-1, -2, -3).normalizeLocal());
        light.setColor(new ColorRGBA(0.8f, 0.8f, 0.8f, 1f));
        rootNode.addLight(light);

        DirectionalLightShadowFilter dlsf = new DirectionalLightShadowFilter(assetManager, 2048, 1);
        dlsf.setLight(light);

        FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
        fpp.addFilter(dlsf);
        fpp.addFilter(new FXAAFilter());
        fpp.addFilter(new TranslucentBucketFilter(true));

        fpp = BinaryExporter.saveAndLoad(assetManager, fpp);
        viewPort.addProcessor(fpp);
    }

}

Stacktrace:

apr 16, 2025 4:04:32 PM com.jme3.app.LegacyApplication handleError
SEVERE: Uncaught exception thrown in Thread[#23,jME3 Main,5,main]
java.lang.NullPointerException: Cannot invoke "com.jme3.material.Material.setTexture(String, com.jme3.texture.Texture)" because the return value of "com.jme3.post.Filter.getMaterial()" is null
	at com.jme3.post.Filter.setDepthTexture(Filter.java:310)
	at com.jme3.post.FilterPostProcessor.initFilter(FilterPostProcessor.java:192)
	at com.jme3.post.FilterPostProcessor.reshape(FilterPostProcessor.java:520)
	at com.jme3.post.FilterPostProcessor.initialize(FilterPostProcessor.java:171)
	at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:1184)
	at com.jme3.renderer.RenderManager.render(RenderManager.java:1298)
	at com.jme3.app.SimpleApplication.update(SimpleApplication.java:283)
	at com.jme3.system.lwjgl.LwjglWindow.runLoop(LwjglWindow.java:629)
	at com.jme3.system.lwjgl.LwjglWindow.run(LwjglWindow.java:719)
	at java.base/java.lang.Thread.run(Thread.java:1589)

apr 16, 2025 4:04:32 PM com.jme3.system.JmeSystemDelegate lambda$new$0
WARNING: JmeDialogsFactory implementation not found.
Uncaught exception thrown in Thread[#23,jME3 Main,5,main]
NullPointerException: Cannot invoke "com.jme3.material.Material.setTexture(String, com.jme3.texture.Texture)" because the return value of "com.jme3.post.Filter.getMaterial()" is null
16:04:33: Execution finished ':com.test.Issue_DirLightShadowFilter_Deser.main()'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions