openframeworks / openframeworks/openFrameworks
Closing Windows console window causes ofTessellator destructor to crash (sometimes)
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 10.4k
- Forks
- 2.6k
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 9
Description
I am using the released version of openFrameworks version 0.9.3 on Windows 10.
When I run my app and close it by closing the console window (as opposed to using e.g. the Escape key or closing the GUI window), I occasionally see a crash in ofTessellator::~ofTessellator - it happens perhaps 30-40% of the time in a release build but never seems to show up in debug builds.
I tracked down the cause:
- When the console window is closed, Windows spawns a new thread to handle the console interrupt (it does the same if you press Ctrl+C over the console window)
- This new thread creates a
thread_local ofTessellator ofPath::tessellator(fromofPath.cpp). - The new thread kills off all the other threads, since it is running a console interrupt whose job it is to close down the program
- The new thread then exits, destructing the
ofTessellator.
However, during destruction, a certain race condition might occur which causes the tessellator cache to be in a bad state. My suspicion is that this happens if the thread tries to exit after everything else has already been destroyed (since every crash I've seen features the console interrupt thread standing alone as the last thread in the process).
This is a somewhat nasty bug. I'm not clear yet on what the actual cause of the crash is, but it's clear that the issue is caused by the thread_local definition of the ofTessellator.
One possible fix, on Windows, might be to register a SetConsoleCtrlHandler and have that call the usual openFrameworks exit machinery.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in ofPath.cpp at the thread_local ofTessellator ofPath::tessellator and trace its destructor during Windows console shutdown. Investigate the suggested SetConsoleCtrlHandler approach alongside the existing exit machinery, then reproduce repeated console-window closes in a release build. Done means the intermittent ofTessellator destructor crash no longer occurs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- desktop, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100