Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AssertionError: Invalid Matrix4f value in GLRenderer.updateUniform() #2209

Closed
stephengold opened this issue Mar 2, 2024 · 5 comments · Fixed by #2210
Closed

AssertionError: Invalid Matrix4f value in GLRenderer.updateUniform() #2209

stephengold opened this issue Mar 2, 2024 · 5 comments · Fixed by #2210
Labels
bug Something that is supposed to work, but doesn't. More severe than a "defect".

Comments

@stephengold
Copy link
Member

I began testing JMonkeyEngine 3.7.0-alpha1 and soon encountered the following crash while rendering a scene with directional-light shadows:

Mar 01, 2024 7:17:36 PM com.jme3.system.JmeDesktopSystem initialize
INFO: Running on jMonkeyEngine 3.7.0-SNAPSHOT
 * Branch: master
 * Git Hash: 56fecab
 * Build Date: 2024-03-01
Mar 01, 2024 7:17:36 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: LWJGL 3.3.3+5 context running on thread jME3 Main
 * Graphics Adapter: GLFW 3.4.0 Wayland X11 GLX Null EGL OSMesa monotonic shared
Mar 01, 2024 7:17:36 PM com.jme3.renderer.opengl.GLRenderer loadCapabilitiesCommon
INFO: OpenGL Renderer Information
 * Vendor: NVIDIA Corporation
 * Renderer: GeForce GT 545/PCIe/SSE2
 * OpenGL Version: 3.2.0 NVIDIA 390.157
 * GLSL Version: 1.50 NVIDIA via Cg compiler
 * Profile: Core
Mar 01, 2024 7:17:36 PM com.jme3.audio.openal.ALAudioRenderer initOpenAL
INFO: Audio Renderer Information
 * Device: OpenAL Soft
 * Vendor: OpenAL Community
 * Renderer: OpenAL Soft
 * Version: 1.1 ALSOFT 1.23.1
 * Supported channels: 64
 * ALC extensions: ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE ALC_EXT_DEDICATED ALC_EXT_disconnect ALC_EXT_EFX ALC_EXT_thread_local_context ALC_SOFT_device_clock ALC_SOFT_HRTF ALC_SOFT_loopback ALC_SOFT_loopback_bformat ALC_SOFT_output_limiter ALC_SOFT_output_mode ALC_SOFT_pause_device ALC_SOFT_reopen_device
 * AL extensions: AL_EXT_ALAW AL_EXT_BFORMAT AL_EXT_DOUBLE AL_EXT_EXPONENT_DISTANCE AL_EXT_FLOAT32 AL_EXT_IMA4 AL_EXT_LINEAR_DISTANCE AL_EXT_MCFORMATS AL_EXT_MULAW AL_EXT_MULAW_BFORMAT AL_EXT_MULAW_MCFORMATS AL_EXT_OFFSET AL_EXT_source_distance_model AL_EXT_SOURCE_RADIUS AL_EXT_STATIC_BUFFER AL_EXT_STEREO_ANGLES AL_LOKI_quadriphonic AL_SOFT_bformat_ex AL_SOFTX_bformat_hoa AL_SOFT_block_alignment AL_SOFT_buffer_length_query AL_SOFT_callback_buffer AL_SOFTX_convolution_reverb AL_SOFT_deferred_updates AL_SOFT_direct_channels AL_SOFT_direct_channels_remix AL_SOFT_effect_target AL_SOFT_events AL_SOFT_gain_clamp_ex AL_SOFTX_hold_on_disconnect AL_SOFT_loop_points AL_SOFTX_map_buffer AL_SOFT_MSADPCM AL_SOFT_source_latency AL_SOFT_source_length AL_SOFT_source_resampler AL_SOFT_source_spatialize AL_SOFT_source_start_delay AL_SOFT_UHJ AL_SOFT_UHJ_ex
Mar 01, 2024 7:17:36 PM com.jme3.audio.openal.ALAudioRenderer initOpenAL
INFO: Audio effect extension version: 1.0
Mar 01, 2024 7:17:36 PM com.jme3.audio.openal.ALAudioRenderer initOpenAL
INFO: Audio max auxiliary sends: 2
Mar 01, 2024 7:17:37 PM com.jme3.anim.SkinningControl controlRender
INFO: Hardware skinning engaged for Oto-ogremesh (Node)
Mar 01, 2024 7:17:37 PM com.jme3.app.LegacyApplication handleError
SEVERE: Uncaught exception thrown in Thread[jME3 Main,5,main]
java.lang.AssertionError: Invalid Matrix4f value Matrix4f
[
 NaN  NaN  NaN  NaN 
 NaN  NaN  NaN  NaN 
 0.0  -4.98721E-4  0.0  1.0 
 0.0  0.0  0.0  1.0 
] for WorldViewProjectionMatrix
	at com.jme3.renderer.opengl.GLRenderer.updateUniform(GLRenderer.java:1390)
	at com.jme3.renderer.opengl.GLRenderer.updateShaderUniforms(GLRenderer.java:1516)
	at com.jme3.renderer.opengl.GLRenderer.setShader(GLRenderer.java:1758)
	at com.jme3.material.logic.DefaultTechniqueDefLogic.render(DefaultTechniqueDefLogic.java:97)
	at com.jme3.material.Technique.render(Technique.java:168)
	at com.jme3.material.Material.render(Material.java:1089)
	at com.jme3.renderer.RenderManager.renderGeometry(RenderManager.java:678)
	at com.jme3.renderer.queue.RenderQueue.renderGeometryList(RenderQueue.java:273)
	at com.jme3.renderer.queue.RenderQueue.renderShadowQueue(RenderQueue.java:283)
	at com.jme3.shadow.AbstractShadowRenderer.renderShadowMap(AbstractShadowRenderer.java:448)
	at com.jme3.shadow.AbstractShadowRenderer.postQueue(AbstractShadowRenderer.java:420)
	at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:1221)
	at com.jme3.renderer.RenderManager.render(RenderManager.java:1292)
	at com.jme3.app.SimpleApplication.update(SimpleApplication.java:283)
	at com.jme3.system.lwjgl.LwjglWindow.runLoop(LwjglWindow.java:631)
	at com.jme3.system.lwjgl.LwjglWindow.run(LwjglWindow.java:721)
	at java.base/java.lang.Thread.run(Thread.java:829)

The following test app crashes immediately when run with assertions enabled:

import com.jme3.app.SimpleApplication;
import com.jme3.light.DirectionalLight;
import com.jme3.renderer.queue.RenderQueue;
import com.jme3.scene.Node;
import com.jme3.shadow.DirectionalLightShadowRenderer;

public class TestIssue extends SimpleApplication {

    public static void main(String[] args) {
        new TestIssue().start();
    }

    @Override
    public void simpleInitApp() {
        DirectionalLight dl = new DirectionalLight();
        rootNode.addLight(dl);

        DirectionalLightShadowRenderer dlsr
                = new DirectionalLightShadowRenderer(assetManager, 4_096, 3);
        dlsr.setLight(dl);
        viewPort.addProcessor(dlsr);

        Node player = (Node) assetManager.loadModel("Models/Oto/Oto.mesh.xml");
        player.setShadowMode(RenderQueue.ShadowMode.Cast);
        rootNode.attachChild(player);
    }
}

I plan to perform a bisection search for the commit that introduced this bug.

@stephengold stephengold added the bug Something that is supposed to work, but doesn't. More severe than a "defect". label Mar 2, 2024
@stephengold
Copy link
Member Author

The bug was absent at f33d4a8 (17 August) but present at 7dfffb5 (19 August).
In hindsight, this makes perfect sense because 7dfffb5 was PR #2058, which added the failing assertion.
I'm unsure whether we should simply remove the assertion or if there's a deeper issue here.
Can you advise us @riccardobl ?

@riccardobl
Copy link
Member

Well, the assertion is working as expected here.
I added it because i've noticed that deep in the engine there is some code that sends NaN values to the shaders causing unexpected results in some implementations.

If you disable assertions the engine will work, it is not a breaking bug, but we should figure out where these NaNs come from in the shadow renderer

@riccardobl
Copy link
Member

I suspect it might be related to this #2112

@riccardobl
Copy link
Member

riccardobl commented Mar 2, 2024

So, i've quickly debugged it, basically having an empty scene or a scene where caster and receiver are at the same position, will lead to the distance from caster-receiver being 0 causing a divide by zero in ShadowUtils causing the value to become infinite that will result in NaN values down stream.

This PR should fix it #2210 .

@stephengold
Copy link
Member Author

stephengold commented Mar 2, 2024

Nice work, @riccardobl, and much appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that is supposed to work, but doesn't. More severe than a "defect".
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants