godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.3k stars 21.05k forks source link

Division by float 0 in rasterizer_scene_high_end_rd.cpp #41291

Open qarmin opened 4 years ago

qarmin commented 4 years ago

Godot version: 4.0.dev.custom_build. 69c81309c

OS/device including version:

Issue description: When I open project then dividing by float 0 happens:

servers/rendering/rasterizer_rd/rasterizer_scene_high_end_rd.cpp:1136:52: runtime error: division by zero
servers/rendering/rasterizer_rd/rasterizer_scene_high_end_rd.cpp:1137:52: runtime error: division by zero

https://github.com/godotengine/godot/blob/e0ee38b128fa84b8e7db499ead66264ca4ec9c60/servers/rendering/rasterizer_rd/rasterizer_scene_high_end_rd.cpp#L1134-L1137

Steps to reproduce:

  1. Open minimal project with undefined sanitizer support

Minimal reproduction project: https://github.com/qarmin/RegressionTestProject/archive/3.2.zip

clayjohn commented 4 years ago

I guess we should just check for when sas is (0,0) and then not do the division.

if (Math::is_equal_approx(sas.x, 0.0) || Math::is_equal_approx(sas.y, 0.0) {
    scene_state.ubo.shadow_atlas_pixel_size[0] = 1.0; 
    scene_state.ubo.shadow_atlas_pixel_size[1] = 1.0; 
} else {
    scene_state.ubo.shadow_atlas_pixel_size[0] = 1.0 / sas.x; 
    scene_state.ubo.shadow_atlas_pixel_size[1] = 1.0 / sas.y; 
}
Calinou commented 1 year ago

@qarmin Is still still relevant? I couldn't find scene_state.ubo.shadow_atlas_pixel_size anywhere in the current master codebase.