From 45096ee62c4910c088b16b72f8824c0d71c1f21f Mon Sep 17 00:00:00 2001 From: Marcelo Fernandez Date: Sun, 6 Aug 2017 10:37:37 -0300 Subject: [PATCH] Add missing NULL checks to prevent possible crashes on _add_geometry --- drivers/gles2/rasterizer_gles2.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp index 335c032de0e..c9984de800a 100644 --- a/drivers/gles2/rasterizer_gles2.cpp +++ b/drivers/gles2/rasterizer_gles2.cpp @@ -4621,16 +4621,19 @@ void RasterizerGLES2::_add_geometry(const Geometry *p_geometry, const InstanceDa if (duplicate) { ec = render_list->add_element(); - memcpy(ec, e, sizeof(RenderList::Element)); + if (ec) + memcpy(ec, e, sizeof(RenderList::Element)); } else { ec = e; duplicate = true; } - ec->light_type = light_type; - ec->light = sort_key; - ec->additive_ptr = &e->additive; + if (ec) { + ec->light_type = light_type; + ec->light = sort_key; + ec->additive_ptr = &e->additive; + } } const RID *liptr = p_instance->light_instances.ptr(); @@ -4651,16 +4654,18 @@ void RasterizerGLES2::_add_geometry(const Geometry *p_geometry, const InstanceDa if (duplicate) { ec = render_list->add_element(); - memcpy(ec, e, sizeof(RenderList::Element)); + if (ec) + memcpy(ec, e, sizeof(RenderList::Element)); } else { - duplicate = true; ec = e; } - ec->light_type = light_type; - ec->light = sort_key; - ec->additive_ptr = &e->additive; + if (ec) { + ec->light_type = light_type; + ec->light = sort_key; + ec->additive_ptr = &e->additive; + } } }