Fix #120969: Overlay: Assert when drawing motion paths

Avoid out of bound reads.
This commit is contained in:
Clément Foucault
2025-06-24 22:05:32 +02:00
parent 8c71719dfd
commit 92b93d6d77

View File

@@ -202,9 +202,11 @@ class MotionPath : Overlay {
UI_GetThemeColor3ubv(TH_VERTEX_SELECT, col_kf);
col.w = col_kf.w = 255;
auto safe_index = [&](int index) { return math::clamp(index, 0, mpath->length - 1); };
Span<bMotionPathVert> mpv(mpath->points, mpath->length);
for (int i = 0; i < frame_range.size(); i += stride) {
const bMotionPathVert &mpv_curr = mpv[start_index + i];
const bMotionPathVert &mpv_curr = mpv[safe_index(start_index + i)];
int frame = frame_range.start() + i;
bool is_keyframe = (mpv_curr.flag & MOTIONPATH_VERT_KEY) != 0;
@@ -230,8 +232,8 @@ class MotionPath : Overlay {
(is_keyframe) ? col_kf : col);
}
else if (show_frame_number) {
const bMotionPathVert &mpv_prev = mpv[start_index + i - stride];
const bMotionPathVert &mpv_next = mpv[start_index + i + stride];
const bMotionPathVert &mpv_prev = mpv[safe_index(start_index + i - stride)];
const bMotionPathVert &mpv_next = mpv[safe_index(start_index + i + stride)];
/* Only draw frame number if several consecutive highlighted points
* don't occur on same point. */
if (!math::is_equal(float3(mpv_curr.co), float3(mpv_prev.co)) ||