fix: prevent re-entrant reset crash in GCodeViewer::load() - #611
Open
zackaree-shen wants to merge 1 commit into
Open
fix: prevent re-entrant reset crash in GCodeViewer::load()#611zackaree-shen wants to merge 1 commit into
zackaree-shen wants to merge 1 commit into
Conversation
The modal progress dialog in load_toolpaths() pumps the event loop, allowing dispatched events to re-enter reset() and zero m_moves_count. This causes unsigned underflow in reserve(m_moves_count - biased_seams_ids.size()), throwing std::length_error. Guard reset() with an m_loading flag armed via RAII ScopeGuard, and move reset() before the flag is set. Replace manual gcode_result.unlock() with ScopeGuard for exception safety. Also add a defensive clamp on the ssid_count computation in load_toolpaths() as a belt-and-suspenders measure.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes a crash that occurs when importing/loading G-code repeatedly. The modal progress dialog in
load_toolpaths()pumps the wxWidgets event loop, which allows dispatched events (e.g. a plate switch or re-import) to re-enterGCodeViewer::reset()viareset_gcode_toolpaths()mid-flight. This zeroesm_moves_count, causing an unsigned underflow inreserve(m_moves_count - biased_seams_ids.size())which throwsstd::length_error.Root Cause
load_toolpaths()displays aProgressDialogand callsUpdate()periodically, pumping the event loop. A re-entrantreset()call zeroesm_moves_countwhileload_toolpaths()is still running, and the subsequentreserve()/ loop bound computation wraps around.Changes
m_loadingguard onreset(): Added anm_loadingflag armed via RAIIScopeGuardaround theload_toolpaths()call.reset()early-returns whenm_loadingis set, preventing re-entrant zeroing. The initialreset()at the top ofload()runs before the flag is armed so cleanup is not skipped.gcode_result.unlock(): Replaced manualunlock()calls inload()andrefresh()withScopeGuardfor exception safety on all exit paths.ssid_count: Added a bounds check inload_toolpaths()so thereserve()and loop use a clampedssid_countinstead of a raw subtraction, as a belt-and-suspenders measure.Impact
GCodeViewer.cpp(27 lines),GCodeViewer.hpp(1 line). No new dependencies, no API changes.Screenshots/Recordings/Graphs
N/A -- crash fix, no UI changes.
Tests