Repository navigation
Fix crash when an echo export is followed by another -o output - #7161
Merged
t-paul merged 1 commit intoOct 31, 2026
Merged
Conversation
Echostream registers itself as the global message handler and passes itself as the user data. It only lives for the duration of one cmdline() call, but its destructor never unregistered the handler. With several -o options, the next export printed its messages through a handler pointing at the destroyed object, so that for example openscad -o y.echo -o y.stl y.scad crashed with a segmentation fault. Unregister the handler in the destructor, and add a test that runs an echo export followed by an STL export. Fixes openscad#5614
Member
|
There's a PR #7127 for solving a much wider issue which should fix this one too. I tend to think it might be useful to get this small fix in first anyway. What do you think @jordanbrown0? |
Contributor
|
I haven't reviewed this one yet - need to leave momentarily, will check later today - but by all means apply a simple fix now. Indeed, my bigger rework makes significant changes in this area, but it's also much higher risk and I haven't decided whether it should go into the current release. |
thalisantunes
marked this pull request as ready for review
October 31, 2026 19:04
Contributor
Author
|
Thanks, both. Agreed on keeping this one minimal: it only detaches the output handler before the stream closes, so it should not get in the way of #7127. Happy to rebase if that lands first. |
t-paul
approved these changes
Oct 31, 2026
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.
Title: Fix crash when an echo export is followed by another -o output
openscad -o y.echo -o y.stl y.scadterminates with a segmentation fault while the second output is being exported. The same options in the other order (-o y.stl -o y.echo) work. I reproduced it with the 2026.01.02 nightly, and a backtrace of the crash ends inEchostream::output(), called throughPRINT_NOCACHE()fromRenderStatistic::printAll()of the second export.Root cause
In
src/openscad.cc,EchostreamregistersEchostream::outputwithset_output_handler()and passes itself as the user data. The object lives incmdline()and is destroyed when that call returns, but its destructor never unregistered the handler. With more than one-o, the nextcmdline()call prints its messages through a handler that points at the destroyed object, which writes to anstd::ofstreamthat no longer exists.Fix
Unregister the handler in
Echostream::~Echostream(), so that messages go back to stderr once the echo export is done.Test
Added
multiple-outputs_echo-stl_runandmultiple-outputs_echo-stl_checktotests/CMakeLists.txt, in the style of the existingrelative-output_*tests. The first one runsopenscad cube-tests.scad -o multiple-outputs.echo -o multiple-outputs.stl, the second checks that the STL was written.Build: Ninja, Release,
-DEXPERIMENTAL=ON -DHEADLESS=ON -DENABLE_GLX=OFF -DENABLE_CAIRO=OFF -DUSE_BUILTIN_OPENCSG=ONon Ubuntu 26.04 (headless build, EGL offscreen).src/openscad.ccreverted):multiple-outputs_echo-stl_runfails with***Exception: SegFault.ctest -j16on master: 2716 tests, 6 failed. With the change: 2718 tests, the same 6 failed and nothing new. The 6 are theexport-pdf*tests (export-pdf_centered,export-pdf-fill_*,export-pdf_utf8-☠-2D), which fail on master in this environment as well, so they are unrelated to this change.Fixes #5614