From 19dc79114df38eae5fa15188861f5a2744dbf947 Mon Sep 17 00:00:00 2001 From: lawnjelly Date: Thu, 15 Sep 2022 13:20:12 +0100 Subject: [PATCH] Prevent drawing MultiMesh with zero instance count Issuing a driver drawcall for MultiMesh with zero instances crashes some drivers. --- drivers/gles2/rasterizer_canvas_gles2.cpp | 16 +++++++++------- drivers/gles2/rasterizer_scene_gles2.cpp | 4 ++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/drivers/gles2/rasterizer_canvas_gles2.cpp b/drivers/gles2/rasterizer_canvas_gles2.cpp index 624fa30ca..44f349d58 100644 --- a/drivers/gles2/rasterizer_canvas_gles2.cpp +++ b/drivers/gles2/rasterizer_canvas_gles2.cpp @@ -935,7 +935,15 @@ void RasterizerCanvasGLES2::render_batches(Item *p_current_clip, bool &r_reclip, break; } - state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_INSTANCE_CUSTOM, multi_mesh->custom_data_format != RS::MULTIMESH_CUSTOM_DATA_NONE); + int amount = MIN(multi_mesh->size, multi_mesh->visible_instances); + + if (amount == -1) { + amount = multi_mesh->size; + } + + if (!amount) { + break; + } state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_INSTANCING, true); _set_texture_rect_mode(false); @@ -953,12 +961,6 @@ void RasterizerCanvasGLES2::render_batches(Item *p_current_clip, bool &r_reclip, //reset shader and force rebind - int amount = MIN(multi_mesh->size, multi_mesh->visible_instances); - - if (amount == -1) { - amount = multi_mesh->size; - } - int stride = multi_mesh->color_floats + multi_mesh->custom_data_floats + multi_mesh->xform_floats; int color_ofs = multi_mesh->xform_floats; diff --git a/drivers/gles2/rasterizer_scene_gles2.cpp b/drivers/gles2/rasterizer_scene_gles2.cpp index 73b8ce5cb..ea55e0891 100644 --- a/drivers/gles2/rasterizer_scene_gles2.cpp +++ b/drivers/gles2/rasterizer_scene_gles2.cpp @@ -1710,6 +1710,10 @@ void RasterizerSceneGLES2::_render_geometry(RenderList::Element *p_element) { amount = multi_mesh->size; } + if (!amount) { + return; + } + int stride = multi_mesh->color_floats + multi_mesh->custom_data_floats + multi_mesh->xform_floats; int color_ofs = multi_mesh->xform_floats;