From 0f20e8173fe1a9c636a7ca4d2014fdc0915a6c23 Mon Sep 17 00:00:00 2001
From: Gon Solo <gonsolo@gmail.com>
Date: Tue, 25 Oct 2022 17:37:24 +0200
Subject: [PATCH] Negative cnt crashes ardour at the end of a loop.

---
 libs/ardour/plugin_insert.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libs/ardour/plugin_insert.cc b/libs/ardour/plugin_insert.cc
index 46795dc807..330eb6924b 100644
--- a/libs/ardour/plugin_insert.cc
+++ b/libs/ardour/plugin_insert.cc
@@ -1379,7 +1379,8 @@ PluginInsert::automate_and_run (BufferSet& bufs, samplepos_t start, samplepos_t
 	while (nframes) {
 
 		samplecnt_t cnt = min (timepos_t (start).distance (next_event.when).samples(), (samplecnt_t) nframes);
-		assert (cnt > 0);
+		//assert (cnt > 0);
+		if (cnt < 0) cnt = 0;
 
 		connect_and_run (bufs, start, start + cnt * speed, speed, cnt, offset, true);
 
-- 
2.37.2

