Skip to content

Free fork of NotProton: Windows Steam games in Mac Steam, on CodeWeavers' Wine and Apple's Game Porting Toolkit

Offer a rebuild when a game crashes right after a build switch

NotProtonNot2d50af52437e
diff --git a/app/Tests/NotProtonAppTests/PrefixToolsTests.swift b/app/Tests/NotProtonAppTests/PrefixToolsTests.swift
index 363d63f..6bf8c30 100644
--- a/app/Tests/NotProtonAppTests/PrefixToolsTests.swift
+++ b/app/Tests/NotProtonAppTests/PrefixToolsTests.swift
@@ -353,10 +353,10 @@ struct PrefixToolsTests {
#expect(helper.upperBound == gate.lowerBound)
#expect(gate.upperBound < alert.lowerBound)
- #expect(source.ranges(of: "osascript").count == 2)
+ #expect(source.ranges(of: "osascript").count == 3)
let rebuild = try #require(source.range(of: "rebuild_prefix() {"))
let prompt = try #require(source.range(of: "choice=$(osascript"))
- #expect(source[rebuild.upperBound..<prompt.lowerBound].contains(#"[ "$verb" != run ] || exit 1"#))
+ #expect(source[rebuild.upperBound..<prompt.lowerBound].contains(#"[ "$verb" != run ] || { [ -n "$3" ] && return 0; exit 1; }"#))
let calls = source.ranges(of: " show_alert \"")
#expect(!calls.isEmpty)
diff --git a/dylib/feats/compat_run.sh b/dylib/feats/compat_run.sh
index 418e0d9..39a7f11 100755
--- a/dylib/feats/compat_run.sh
+++ b/dylib/feats/compat_run.sh
@@ -291,12 +291,27 @@ prefix_machine() {
tool_name() {
case "$1" in
- aa64) printf 'the FEX build of CrossOver' ;;
- 8664) printf 'the Rosetta build of CrossOver' ;;
- *) printf 'an older 32-bit setup' ;;
+ aa64) printf 'FEX' ;;
+ 8664) printf 'Rosetta' ;;
+ *) printf '32-bit' ;;
esac
}
+# CrossOver's previews are versioned by date, which reads as a release without the word.
+preview_name() {
+ case "$1" in
+ "CrossOver 20"[0-9][0-9]" "*) printf 'CrossOver Preview %s' "${1#CrossOver }" ;;
+ *) printf '%s' "$1" ;;
+ esac
+}
+
+# Tool names already end in the arch, which the sentence names on its own.
+running_name() {
+ run_name=$1
+ case "$run_name" in *" - Rosetta" | *" - FEX") run_name=${run_name% - *} ;; esac
+ printf '%s, running through %s' "$(preview_name "$run_name")" "$2"
+}
+
# Steam passes "run" for helpers such as install scripts, which get no dialog.
show_alert() {
[ "$verb" != run ] || return 0
@@ -312,40 +327,59 @@ alert_safe() {
printf '%s' "$1" | tr -d '"\\'
}
+# The log path reaches AppleScript as an argument, so a quote in it cannot end a string.
+show_rebuild_failure() {
+ [ "$verb" != run ] || return 0
+ exec 8>&- 9>&-
+ answer=$(osascript - "$log" <<'APPLESCRIPT'
+on run argv
+ set answer to display alert "Prefix rebuild failed!" message ("Check notproton-run.log at " & (item 1 of argv) & ".") as critical buttons {"Open Log", "OK"} default button "OK"
+ return button returned of answer
+end run
+APPLESCRIPT
+ ) || answer=""
+ [ "$answer" != "Open Log" ] || open "$log" >/dev/null 2>&1 || true
+}
+
+# $1 is the title, $2 the message. With $3, that button skips the rebuild and the launch goes on.
rebuild_prefix() {
# Install-script helpers must never prompt or rebuild behind the player's back.
- [ "$verb" != run ] || exit 1
+ [ "$verb" != run ] || { [ -n "$3" ] && return 0; exit 1; }
[ "${np_rebuilt:-0}" != 1 ] || {
- show_alert "Prefix rebuild failed" "The rebuilt prefix still does not match the selected compatibility tool. Check notproton-run.log."
+ show_rebuild_failure
exit 1
}
exec 8>&- 9>&-
- choice=$(osascript - "$1" "$np_display" <<'APPLESCRIPT'
+ choice=$(osascript - "$1" "$2" "${3:-Cancel}" <<'APPLESCRIPT'
on run argv
- set explanation to (item 1 of argv) & return & return & "Rebuild with " & (item 2 of argv) & "? Saved games will be preserved. A backup also keeps a copy of the original prefix."
- set answer to display dialog explanation with title "This game needs its prefix rebuilt" buttons {"Cancel", "Rebuild Prefix", "Backup & Rebuild Prefix"} default button "Backup & Rebuild Prefix" cancel button "Cancel" with icon caution
+ set answer to display dialog (item 2 of argv) with title (item 1 of argv) buttons {item 3 of argv, "Rebuild Prefix", "Backup & Rebuild Prefix"} default button "Backup & Rebuild Prefix" cancel button (item 3 of argv) with icon caution
return button returned of answer
end run
APPLESCRIPT
- ) || exit 1
+ ) || choice=""
case "$choice" in
'Backup & Rebuild Prefix') backup=keep-backup ;;
'Rebuild Prefix') backup=discard-backup ;;
- *) exit 1 ;;
+ *)
+ [ -n "$3" ] || exit 1
+ prepare_prefix_directory || exit 1
+ return 0
+ ;;
esac
executable=$(cat "$np_support/app-executable" 2>/dev/null) || executable=""
if [ ! -x "$executable" ]; then
- show_alert "NotProton app unavailable" "Open NotProton and install or repair it again, then relaunch the game."
+ show_alert "Couldn't find the NotProton app" "The prefix wasn't rebuilt and the game wasn't launched, because the NotProton app was moved or deleted since it was installed. Open NotProton and click Install again, then launch the game."
exit 1
fi
if ! "$executable" --rebuild-prefix "$STEAM_COMPAT_DATA_PATH" "${np_tool_dir##*/}" \
"$np_build" "$np_flavor" "$backup" >> "$log" 2>&1; then
- show_alert "Prefix rebuild failed" "The game was not launched. Check notproton-run.log for details. Quit any running game or Wine tool before trying again."
+ show_rebuild_failure
exit 1
fi
+ rm -f "$STEAM_COMPAT_DATA_PATH/notproton-switch"
# A competing launch or rebuild may have run while the dialog was open.
# Retake the normal launch lock and check both mismatches before touching Wine.
- prepare_prefix_directory
+ prepare_prefix_directory || exit 1
np_rebuilt=1
note_other_build
refuse_foreign_prefix
@@ -359,7 +393,18 @@ refuse_foreign_prefix() {
have=$(prefix_machine) || return 0
[ "$have" = "$want" ] && return 0
echo "=== prefix ntdll is $have and this compatibility tool wants $want, rebuild the prefix in NotProton ===" >> "$log" 2>&1 || true
- rebuild_prefix "This game originally ran under $(tool_name "$have"), but the selected compatibility tool uses $(tool_name "$want")."
+ had_tool=$(tool_name "$have")
+ want_tool=$(tool_name "$want")
+ explanation="$had_tool prefixes cannot be used with versions of CrossOver that run through $want_tool unless they are rebuilt."
+ # note_other_build read the build that set up the prefix.
+ case "$have:$had_display" in
+ aa64:?* | 8664:?*)
+ explanation="This game's prefix was last used by $(running_name "$had_display" "$had_tool"). $explanation"
+ ;;
+ esac
+ rebuild_prefix "This game needs its prefix rebuilt" "$explanation
+
+Do you want to rebuild the prefix for $(running_name "$np_display" "$want_tool")? Your save games will be preserved and not lost."
}
last_wine_build() {
@@ -403,9 +448,78 @@ note_other_build() {
fi
if [ -n "$had_build" ] && [ "$had_build" != "$np_build" ]; then
echo "=== prefix was last run by build $had_build (${had_display:-unknown}), Wine updates it for $np_build ===" >> "$log" 2>&1 || true
+ switch="$STEAM_COMPAT_DATA_PATH/notproton-switch"
+ rm -f "$switch"
+ # Only a build the game is known to have run on can be blamed for a crash after the switch.
+ if [ "$(head -1 "$STEAM_COMPAT_DATA_PATH/notproton-healthy" 2>/dev/null)" = "$had_build" ]; then
+ printf '%s\n%s\n0\n' "$had_build" "${had_display:-CrossOver build $had_build}" > "$switch" 2>/dev/null || true
+ fi
+ fi
+}
+
+# Healthy is a session Steam did not cut short or that lasted, with no Wine crash. Failed is a
+# crash within the first minute. Anything else says nothing about the build.
+session_health() {
+ crashed=0
+ grep -q -E 'Unhandled (page fault|exception)|err:module:import_dll' "$1" 2>/dev/null && crashed=1
+ if [ "$crashed" = 1 ] && [ "$2" -lt 60 ] && [ "$3" != 1 ]; then
+ echo failed
+ elif [ "$crashed" = 0 ] && { [ "$3" != 1 ] || [ "$2" -ge 60 ]; }; then
+ echo healthy
+ else
+ echo unknown
fi
}
+set_switch_state() {
+ if ! { sed -n 1,2p "$switch" && printf '%s\n' "$1"; } > "$switch.$$" \
+ || ! mv -f "$switch.$$" "$switch"; then
+ rm -f "$switch.$$"
+ fi
+}
+
+# The switch record is old build, its name, then the healthy sessions since or "failed".
+# Two healthy sessions clear it.
+record_session() {
+ switch="$STEAM_COMPAT_DATA_PATH/notproton-switch"
+ health=$(session_health "$1" "$2" "$3")
+ echo "=== session health: $health after $2s ===" >> "$log" 2>&1 || true
+ case "$health" in
+ healthy)
+ printf '%s\n' "$np_build" > "$STEAM_COMPAT_DATA_PATH/notproton-healthy" 2>/dev/null || true
+ [ -f "$switch" ] || return 0
+ count=$(sed -n 3p "$switch")
+ case "$count" in
+ 0) set_switch_state 1 ;;
+ *) rm -f "$switch" ;;
+ esac
+ ;;
+ failed)
+ [ -f "$switch" ] || return 0
+ set_switch_state failed
+ ;;
+ esac
+}
+
+# Asked once per switch, at the next launch after the crash.
+offer_switch_rebuild() {
+ switch="$STEAM_COMPAT_DATA_PATH/notproton-switch"
+ [ "$(sed -n 3p "$switch" 2>/dev/null)" = failed ] || return 0
+ [ "$verb" != run ] || return 0
+ old_display=$(sed -n 2p "$switch")
+ case "${wine_unix##*/}" in
+ aarch64-unix) now_arch=aa64 ;;
+ *) now_arch=8664 ;;
+ esac
+ rm -f "$switch"
+ echo "=== last session crashed after switching from $old_display, offering a rebuild ===" >> "$log" 2>&1 || true
+ rebuild_prefix "This game may need its prefix rebuilt" \
+ "Something appears to have gone wrong the last time you ran this game! Rebuilding the prefix may fix it.
+
+Rebuild your prefix for $(running_name "$np_display" "$(tool_name "$now_arch")")? Your save games will be preserved and not lost." \
+ "Launch Without Rebuilding"
+}
+
claim_prefix() {
[ -r "$STEAM_COMPAT_DATA_PATH/notproton-build" ] \
|| echo "=== prefix claimed by build $np_build ===" >> "$log" 2>&1 || true
@@ -1216,6 +1330,8 @@ if [ -n "$STEAM_COMPAT_DATA_PATH" ]; then
stage_step="prefix arch check"
refuse_foreign_prefix
claim_prefix
+ stage_step="prefix switch check"
+ offer_switch_rebuild
echo "sync: WINEMSYNC=$WINEMSYNC from $msync_from" >> "$log" 2>&1 || true
if [ "${wine_unix##*/}" = aarch64-unix ]; then
echo "fex: FEX_X87REDUCEDPRECISION=$FEX_X87REDUCEDPRECISION from $fex_from" >> "$log" 2>&1 || true
@@ -1642,6 +1758,7 @@ kill_wine_prefix() {
# termination signal to this run script, this handles it
# shellcheck disable=SC2329 # the trap below invokes this
terminate() {
+ np_terminated=1
echo "=== termination signal received, killing wine prefix ===" >> "$log" 2>&1 || true
kill_wine_prefix
[ -n "$open_pid" ] && kill "$open_pid" 2>/dev/null || true
@@ -1679,6 +1796,8 @@ set -- \
lsregister="/System/Library/Frameworks/CoreServices.framework/Versions/A"
lsregister="$lsregister/Frameworks/LaunchServices.framework/Support/lsregister"
[ -x "$lsregister" ] && "$lsregister" -f "$loader_app" >> "$log" 2>&1 || true
+np_started=$(date +%s)
+np_terminated=0
open -n -W -a "$loader_app" "$@" >> "$log" 2>&1 &
open_pid=$!
/usr/bin/caffeinate -d -i -w "$open_pid" >> "$log" 2>&1 &
@@ -1686,5 +1805,7 @@ status=0
wait "$open_pid" || status=$?
echo "=== game exited status=$status, killing wine prefix ===" >> "$log" 2>&1 || true
kill_wine_prefix
+[ -z "$STEAM_COMPAT_DATA_PATH" ] \
+ || record_session "$loader_root/notproton-wine.log" "$(($(date +%s) - np_started))" "$np_terminated"
echo "=== wine prefix killed, session ending ===" >> "$log" 2>&1 || true
exit $status
diff --git a/dylib/tests/buildcheck.sh b/dylib/tests/buildcheck.sh
index 9c3e0c6..d5275ce 100644
--- a/dylib/tests/buildcheck.sh
+++ b/dylib/tests/buildcheck.sh
@@ -118,6 +118,8 @@ is "an open alert does not keep the prefix locked" "free" "$(cat "$data/during-a
echo "== rebuild choices =="
arch_functions="$(extract prefix_machine)
+$(extract preview_name)
+$(extract running_name)
$(extract tool_name)
$(extract refuse_foreign_prefix)"
arch_data="$work/arch/pfx/drive_c/windows/system32"
@@ -127,14 +129,22 @@ dd if=/dev/zero bs=1 count=60 of="$arch_data/ntdll.dll" 2>/dev/null
printf '\100\000\000\000PE\000\000\144\206' >> "$arch_data/ntdll.dll"
arch_case() {
(
- WINEPREFIX="$work/arch/pfx" wine_unix="$1" log=/dev/null
+ WINEPREFIX="$work/arch/pfx" wine_unix="$1" log=/dev/null np_display="CrossOver 2026 10 15-ARM64 - FEX" had_display="${2:-}"
# shellcheck disable=SC2329
- rebuild_prefix() { printf 'rebuild: %s\n' "$1"; }
+ rebuild_prefix() { printf 'rebuild: %s: %s\n' "$1" "$2"; }
eval "$arch_functions"
refuse_foreign_prefix
)
}
-is "an architecture mismatch offers rebuilding" 'rebuild: This game originally ran under the Rosetta build of CrossOver, but the selected compatibility tool uses the FEX build of CrossOver.' "$(arch_case aarch64-unix)"
+is "an architecture mismatch offers rebuilding" 'rebuild: This game needs its prefix rebuilt: Rosetta prefixes cannot be used with versions of CrossOver that run through FEX unless they are rebuilt.
+
+Do you want to rebuild the prefix for CrossOver Preview 2026 10 15-ARM64, running through FEX? Your save games will be preserved and not lost.' "$(arch_case aarch64-unix)"
+is "the build that set up the prefix is named" 'rebuild: This game needs its prefix rebuilt: This game'"'"'s prefix was last used by CrossOver 26.3, running through Rosetta. Rosetta prefixes cannot be used with versions of CrossOver that run through FEX unless they are rebuilt.
+
+Do you want to rebuild the prefix for CrossOver Preview 2026 10 15-ARM64, running through FEX? Your save games will be preserved and not lost.' "$(arch_case aarch64-unix 'CrossOver 26.3')"
+is "a tool name's own arch suffix is not repeated" 'rebuild: This game needs its prefix rebuilt: This game'"'"'s prefix was last used by CrossOver Preview 2026 10 15-ARM64, running through Rosetta. Rosetta prefixes cannot be used with versions of CrossOver that run through FEX unless they are rebuilt.
+
+Do you want to rebuild the prefix for CrossOver Preview 2026 10 15-ARM64, running through FEX? Your save games will be preserved and not lost.' "$(arch_case aarch64-unix 'CrossOver 2026 10 15-ARM64 - Rosetta')"
is "a matching architecture needs no rebuild" "" "$(arch_case x86_64-unix)"
rebuild=$(extract rebuild_prefix)
mkdir -p "$work/app with spaces"
@@ -148,7 +158,7 @@ chmod +x "$work/app with spaces/NotProtonApp"
printf '%s' "$work/app with spaces/NotProtonApp" > "$np_support/app-executable"
rebuild_case() {
- choice=$1 command_status=$2 launch_verb=$3
+ choice=$1 command_status=$2 launch_verb=$3 skip=${4:-}
data=$(mktemp -d "$work/compat data.XXXXXX")
(
export TEST_DATA="$data" TEST_STATUS="$command_status"
@@ -157,10 +167,12 @@ rebuild_case() {
in its name'
verb=$launch_verb log="$data/log"
# shellcheck disable=SC2329
- osascript() { cat > "$data/prompt"; [ "$choice" != cancel ] || return 1; printf '%s\n' "$choice"; }
+ osascript() { cat > "$data/prompt"; shift; printf '%s\n' "$@" > "$data/prompt-args"; [ "$choice" != cancel ] || return 1; printf '%s\n' "$choice"; }
# shellcheck disable=SC2329
show_alert() { echo "$1" >> "$data/alerts"; }
# shellcheck disable=SC2329
+ show_rebuild_failure() { echo "rebuild failed" >> "$data/alerts"; }
+ # shellcheck disable=SC2329
prepare_prefix_directory() { exec 8>> "$data/.notproton-prefix.lock"; /usr/bin/lockf -s -t 0 8; echo locked >> "$data/checks"; }
# shellcheck disable=SC2329
note_other_build() { echo build >> "$data/checks"; }
@@ -169,8 +181,9 @@ in its name'
eval "$rebuild"
prepare_prefix_directory
: > "$data/checks"
- rebuild_prefix 'Previous "tool" with \ and a newline
-in its name'
+ echo stale > "$data/notproton-switch"
+ rebuild_prefix 'A title' 'Previous "tool" with \ and a newline
+in its name' ${skip:+"$skip"}
echo launched >> "$data/checks"
) && status=0 || status=$?
}
@@ -195,13 +208,100 @@ is "cancel never calls the app" no "$([ -f "$data/arguments" ] && echo yes || ec
rebuild_case 'Rebuild Prefix' 7 waitforexitandrun
is "a failed rebuild stops the launch" 1 "$status"
is "a failed rebuild never continues launch preparation" "" "$(cat "$data/checks")"
+is "a failed rebuild says so" "rebuild failed" "$(cat "$data/alerts")"
rebuild_case 'Rebuild Prefix' 0 run
is "install helpers refuse silently" 1 "$status"
is "install helpers never prompt" no "$([ -f "$data/prompt" ] && echo yes || echo no)"
+rebuild_case cancel 0 waitforexitandrun 'Launch Without Rebuilding'
+is "skipping an offered rebuild goes on with the launch" 0 "$status"
+is "a skipped rebuild retakes the lock and launches" "locked
+launched" "$(cat "$data/checks")"
+is "a skipped rebuild never calls the app" no "$([ -f "$data/arguments" ] && echo yes || echo no)"
+is "the skip button is labelled as asked" "Launch Without Rebuilding" "$(tail -1 "$data/prompt-args")"
+rebuild_case 'Rebuild Prefix' 0 run 'Launch Without Rebuilding'
+is "install helpers skip an offered rebuild silently" 0 "$status"
+rebuild_case 'Rebuild Prefix' 0 waitforexitandrun
+is "a finished rebuild clears the switch record" no "$([ -f "$data/notproton-switch" ] && echo yes || echo no)"
printf '%s' "$work/missing" > "$np_support/app-executable"
rebuild_case 'Rebuild Prefix' 0 waitforexitandrun
is "a moved or missing app stops the launch" 1 "$status"
-is "a missing app explains how to repair" 'NotProton app unavailable' "$(cat "$data/alerts")"
+is "a missing app explains how to repair" "Couldn't find the NotProton app" "$(cat "$data/alerts")"
+
+
+echo "== crashes after a switch =="
+health_functions="$(extract note_other_build)
+$(extract preview_name)
+$(extract running_name)
+$(extract tool_name)
+$(extract last_wine_build)
+$(extract session_health)
+$(extract set_switch_state)
+$(extract record_session)
+$(extract offer_switch_rebuild)"
+crash_log="$work/crash.log"
+printf 'wine: Unhandled page fault on execute access to 0000000001A23DA0\n' > "$crash_log"
+clean_log="$work/clean.log"
+printf 'fixme:ntdll:stub\n' > "$clean_log"
+health() {
+ (
+ log=/dev/null
+ eval "$health_functions"
+ session_health "$@"
+ )
+}
+is "a crash in the first minute is a failure" failed "$(health "$crash_log" 5 0)"
+is "a crash after a minute says nothing" unknown "$(health "$crash_log" 300 0)"
+is "a crash Steam stopped says nothing" unknown "$(health "$crash_log" 5 1)"
+is "a session without a crash is healthy" healthy "$(health "$clean_log" 3 0)"
+is "a long session Steam stopped is healthy" healthy "$(health "$clean_log" 600 1)"
+is "a short session Steam stopped says nothing" unknown "$(health "$clean_log" 5 1)"
+is "a missing log is healthy" healthy "$(health "$work/none.log" 5 0)"
+
+# Each step is one launch: switch to a build, then a session that ends healthy or failed.
+switch_world() {
+ data=$(mktemp -d "$work/switch.XXXXXX")
+ [ -z "$1" ] || printf '%s\n' "$1" > "$data/notproton-healthy"
+ printf 'old-build\nOld Tool\n' > "$data/notproton-build"
+}
+session() {
+ (
+ STEAM_COMPAT_DATA_PATH=$data np_build=$1 np_display="New Tool" log=/dev/null verb=waitforexitandrun
+ # shellcheck disable=SC2329
+ rebuild_prefix() { printf '%s|%s|%s\n' "$1" "$2" "$3" >> "$data/offers"; }
+ eval "$health_functions"
+ note_other_build
+ printf '%s\nNew Tool\n' "$1" > "$data/notproton-build"
+ offer_switch_rebuild
+ record_session "$2" "$3" 0
+ )
+}
+state() { sed -n 3p "$data/notproton-switch" 2>/dev/null || echo none; }
+
+switch_world old-build
+session new-build "$clean_log" 5
+is "a switch from a build that worked is tracked" 1 "$(state)"
+session new-build "$clean_log" 5
+is "two healthy sessions clear the record" none "$([ -f "$data/notproton-switch" ] && state || echo none)"
+is "the healthy build is remembered" new-build "$(cat "$data/notproton-healthy")"
+
+switch_world old-build
+session new-build "$crash_log" 5
+is "a crash after the switch is recorded" failed "$(state)"
+is "nothing is offered in the session that crashed" no "$([ -f "$data/offers" ] && echo yes || echo no)"
+session new-build "$crash_log" 5
+is "the next launch offers a rebuild for the selected tool" "This game may need its prefix rebuilt|Something appears to have gone wrong the last time you ran this game! Rebuilding the prefix may fix it.
+
+Rebuild your prefix for New Tool, running through Rosetta? Your save games will be preserved and not lost.|Launch Without Rebuilding" "$(cat "$data/offers")"
+is "the offer is made once per switch" none "$([ -f "$data/notproton-switch" ] && state || echo none)"
+session new-build "$crash_log" 5
+is "a crash after the offer is not offered again" 1 "$(grep -c "^This game may need" "$data/offers")"
+
+switch_world ""
+session new-build "$crash_log" 5
+is "a game never seen working is not blamed on the switch" none "$([ -f "$data/notproton-switch" ] && state || echo none)"
+switch_world other-build
+session new-build "$crash_log" 5
+is "a game seen working on another build is not blamed on this switch" none "$([ -f "$data/notproton-switch" ] && state || echo none)"
if [ "$fails" -eq 0 ]; then
echo "==> buildcheck: all assertions hold"