Fix Windows crash saving tool definitions to a read-only install dir#5
Merged
Conversation
On Windows GetDataDirectory() returned ".", so tool definitions and CSV recordings were written relative to the working directory. For an app installed under C:\Program Files\ that directory is read-only, so create_directories() failed; SaveToolDefinition() used the throwing overload, so the filesystem_error propagated to main() and terminated the app when clicking "Add Tool Definition" (reported with no device attached, but the save path is device-independent). - GetDataDirectory(): use %LOCALAPPDATA%\IR Tracking App on Windows, a writable per-user location, mirroring the macOS Application Support handling. _wdupenv_s avoids the MSVC getenv deprecation warning under /W4 and preserves non-ASCII user names. - SaveToolDefinition(): use the non-throwing create_directories overload; log and skip persistence on failure instead of crashing. The tool stays active for the session even if it can't be written to disk.
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.
Problem
On Windows, clicking Add Tool Definition crashed the app:
The reporter hit this with no camera attached, but the save path is device-independent.
Root cause
GetDataDirectory()returned"."on Windows, so tool definitions (and CSV recordings) were written relative to the process working directory. For an app installed underC:\Program Files\…that directory is read-only, sofs::create_directories(".\Tools")failed with Access is denied. BecauseSaveToolDefinition()used the throwingcreate_directoriesoverload, thefilesystem_errorpropagated up tomain()and terminated the app.This is the same class of bug already fixed for macOS (where the
.appworking directory is/); Windows/Linux had been left on".".Fix
GetDataDirectory()now returns%LOCALAPPDATA%\IR Tracking Appon Windows — a writable per-user location — mirroring the macOS~/Library/Application Supporthandling. Uses_wdupenv_s(notgetenv) to stay warning-clean under/W4and to preserve non-ASCII user names. Refactored to a single create/log/return path. Linux still falls back to".".SaveToolDefinition()now uses the non-throwingcreate_directories(dir, ec)overload (and drops the throwingfs::exists): on failure it logs and skips persistence instead of crashing. The tool remains active for the session even if it can't be saved to disk.Testing
_WIN32branch is compiled by this PR'sbuild.yml/windows-2022job (it couldn't be compiled on the macOS dev machine).Notes
%LOCALAPPDATA%. No migration needed — the old location never worked for installed users, so there's nothing to lose.LoadToolDefinition, and thefs::existsloop inWriteToCSVoncsvThread). Left out to keep this hotfix focused; happy to harden them in a follow-up.Targets a v1.3.1 patch release over v1.3.0.