aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Weissflog <floooh@gmail.com>2020-10-02 18:09:03 +0200
committerAndre Weissflog <floooh@gmail.com>2020-10-02 18:09:03 +0200
commitaf9ba80ea3779a9c72f4feb97cdfcbc17aefe9c2 (patch)
tree0ae7ede680e1d8883da331829323b43581246df1
parentc1fbd86ddcc866470abc88a8f916b86ae8236f92 (diff)
sokol_gfx.h: skip draw with zero elements or instances (fixes #397)
-rw-r--r--sokol_gfx.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/sokol_gfx.h b/sokol_gfx.h
index 3e6cd9a5..57cde6cb 100644
--- a/sokol_gfx.h
+++ b/sokol_gfx.h
@@ -14566,6 +14566,7 @@ SOKOL_API_IMPL void sg_apply_uniforms(sg_shader_stage stage, int ub_index, const
SOKOL_API_IMPL void sg_draw(int base_element, int num_elements, int num_instances) {
SOKOL_ASSERT(_sg.valid);
+ SOKOL_ASSERT((base_element >= 0) && (num_elements >= 0) && (num_instances >= 0));
#if defined(SOKOL_DEBUG)
if (!_sg.bindings_valid) {
SOKOL_LOG("attempting to draw without resource bindings");
@@ -14583,6 +14584,13 @@ SOKOL_API_IMPL void sg_draw(int base_element, int num_elements, int num_instance
_SG_TRACE_NOARGS(err_bindings_invalid);
return;
}
+ /* attempting to draw with zero elements or instances is not technically an
+ error, but might be handled as an error in the backend API (e.g. on Metal)
+ */
+ if ((0 == num_elements) || (0 == num_instances)) {
+ _SG_TRACE_NOARGS(err_draw_invalid);
+ return;
+ }
_sg_draw(base_element, num_elements, num_instances);
_SG_TRACE_ARGS(draw, base_element, num_elements, num_instances);
}