From c0b5fea525594ce2e34274c7c82bb9bf156932b6 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Thu, 28 Jul 2022 00:40:18 +0200 Subject: [PATCH] Prevent re-entry in EOF command processing cmdqueue will run commands when EOF is reached without returning to the main loop, which is already incorrect. However, since it needs to ensure the queue is empty, an st_synchronize call can result in a re-entrant call to get_command, which will reprocess EOF again. Even if we removed st_synchronize, another command could be picked by an unsuspecting manage_inactivity() somewhere else. Short-circuit EOF processing by closing the file early and checking for the file state early in get_command. This should fix #3549 --- Firmware/cmdqueue.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Firmware/cmdqueue.cpp b/Firmware/cmdqueue.cpp index 0380c16d..e53122a4 100755 --- a/Firmware/cmdqueue.cpp +++ b/Firmware/cmdqueue.cpp @@ -534,7 +534,7 @@ void get_command() } #ifdef SDSUPPORT - if(!card.sdprinting || serial_count!=0){ + if(!card.sdprinting || !card.isFileOpen() || serial_count!=0){ // If there is a half filled buffer from serial line, wait until return before // continuing with the serial line. return; @@ -631,6 +631,10 @@ void get_command() // cleared by printingHasFinished after peforming all remaining moves. if(!cmdqueue_calc_sd_length()) { + // queue is complete, but before we process EOF commands prevent + // re-entry by disabling SD processing from any st_synchronize call + card.closefile(); + SERIAL_PROTOCOLLNRPGM(_n("Done printing file"));////MSG_FILE_PRINTED stoptime=_millis(); char time[30];