From c2ef2daa2c4091c8e6d3b2d989f0f72aae2cb801 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Tue, 6 Feb 2024 11:14:53 +0100 Subject: [PATCH] Fix: DRW: Out of bound index in PassSortable This was caused by hair subpass growing the subpass vector but not adding anything to the sorting_values_ vector. This means the indices that was return by `sub_passes_.append_and_get_index` were dereferencing the `sorting_values_` vector out of bounds on this line: `float a_val = sorting_values_[a.index];` --- source/blender/draw/intern/draw_pass.hh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/source/blender/draw/intern/draw_pass.hh b/source/blender/draw/intern/draw_pass.hh index ed73bc339b5..0ca3fe9271e 100644 --- a/source/blender/draw/intern/draw_pass.hh +++ b/source/blender/draw/intern/draw_pass.hh @@ -496,7 +496,15 @@ class PassSortable : public PassMain { int64_t index = sub_passes_.append_and_get_index( PassBase(name, draw_commands_buf_, sub_passes_, shader_)); headers_.append({Type::SubPass, uint(index)}); - sorting_values_.append(sorting_value); + /* Some sub-pass can also create sub-sub-passes (curve, point-clouds...) which will de-sync + * the `sub_passes_.size()` and `sorting_values_.size()`, making the `Header::index` not + * reusable for the sorting value in the `sort()` function. To fix this, we flood the + * `sorting_values_` to ensure the same index is valid for `sorting_values_` and + * `sub_passes_`. */ + int64_t sorting_index; + do { + sorting_index = sorting_values_.append_and_get_index(sorting_value); + } while (sorting_index != index); return sub_passes_[index]; }