Skip to content

Fix crash on startup with KSA r3646#57

Merged
KlaasWhite merged 1 commit intoStarMapLoader:feature/external/pr-57from
Maximilian-Nesslauer:fix/appbase-directory-dev
Feb 21, 2026
Merged

Fix crash on startup with KSA r3646#57
KlaasWhite merged 1 commit intoStarMapLoader:feature/external/pr-57from
Maximilian-Nesslauer:fix/appbase-directory-dev

Conversation

@Maximilian-Nesslauer
Copy link
Contributor

The problem: in KSA Version v2026.2.32.3646 (most likely commit https://discord.com/channels/1260011486735241329/1260112103134724146/1474293335723347999) added Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory) at the top of Program.Main() in Program.cs to fix a Linux startup crash.

When StarMap launches KSA via reflection, AppDomain.CurrentDomain.BaseDirectory resolves to StarMap's install directory (not KSA's), because it's the same process/AppDomain.
StarMap already sets the CWD correctly, but KSA's new code immediately overrides it.

The fix sets APP_CONTEXT_BASE_DIRECTORY to the game directory via AppContext.SetData().

This works because in .NET, AppDomain.CurrentDomain.BaseDirectory delegates to AppContext.BaseDirectory, which checks the APP_CONTEXT_BASE_DIRECTORY data store first before falling back to the process executable path.
By setting this to the game directory, KSA's Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory) will now correctly resolve to the game directory even when launched through StarMap.

Tested and verified with KSA r3646 and StarMap 0.3.6

Fixes #55

KSA r3646 added `Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory)`
at the top of Program.Main() to fix a Linux startup crash. When launched via StarMap,
AppDomain.CurrentDomain.BaseDirectory resolves to StarMap's directory instead of the
game directory, causing the game to look for assets in the wrong location.

Fix by setting APP_CONTEXT_BASE_DIRECTORY to the game directory, which is the backing
store for AppDomain.CurrentDomain.BaseDirectory in .NET.

Fixes StarMapLoader#55
@KlaasWhite KlaasWhite changed the base branch from dev to feature/external/pr-57 February 21, 2026 12:40
@KlaasWhite KlaasWhite merged commit 9c7da40 into StarMapLoader:feature/external/pr-57 Feb 21, 2026
1 check failed
KlaasWhite added a commit that referenced this pull request Feb 21, 2026
KSA r3646 added `Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory)`
at the top of Program.Main() to fix a Linux startup crash. When launched via StarMap,
AppDomain.CurrentDomain.BaseDirectory resolves to StarMap's directory instead of the
game directory, causing the game to look for assets in the wrong location.

Fix by setting APP_CONTEXT_BASE_DIRECTORY to the game directory, which is the backing
store for AppDomain.CurrentDomain.BaseDirectory in .NET.

Fixes #55

Co-authored-by: Maximilian Neßlauer <maximiliannesslauer@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants