fix: cache invalidation from .env prevents multiple launch attempts

for all env related, it is necessary to clear cache first, otherwise on few launch attempts the game wouldn't run
This commit is contained in:
Fazri Gading
2026-02-02 06:09:14 +08:00
parent d8d7702d9d
commit 2e0bdeee5a

View File

@@ -117,6 +117,20 @@ function generateLocalTokens(uuid, name) {
} }
async function launchGame(playerNameOverride = null, progressCallback, javaPathOverride, installPathOverride, gpuPreference = 'auto', branchOverride = null) { async function launchGame(playerNameOverride = null, progressCallback, javaPathOverride, installPathOverride, gpuPreference = 'auto', branchOverride = null) {
// ==========================================================================
// CACHE INVALIDATION: Clear proxyClient module cache to force fresh .env load
// This prevents stale cached values from affecting multiple launch attempts
// ==========================================================================
try {
const proxyClientPath = require.resolve('../utils/proxyClient');
if (require.cache[proxyClientPath]) {
delete require.cache[proxyClientPath];
console.log('[Launcher] Cleared proxyClient cache for fresh .env load');
}
} catch (cacheErr) {
console.warn('[Launcher] Could not clear proxyClient cache:', cacheErr.message);
}
// ========================================================================== // ==========================================================================
// STEP 1: Validate player identity FIRST (before any other operations) // STEP 1: Validate player identity FIRST (before any other operations)
// ========================================================================== // ==========================================================================
@@ -345,7 +359,6 @@ exec "$REAL_JAVA" "\${ARGS[@]}"
Object.assign(env, waylandEnv); Object.assign(env, waylandEnv);
const gpuEnv = setupGpuEnvironment(gpuPreference); const gpuEnv = setupGpuEnvironment(gpuPreference);
Object.assign(env, gpuEnv); Object.assign(env, gpuEnv);
// Linux: Replace bundled libzstd.so with system version to fix glibc 2.41+ crash // Linux: Replace bundled libzstd.so with system version to fix glibc 2.41+ crash
// The bundled libzstd causes "free(): invalid pointer" on Steam Deck / Ubuntu LTS // The bundled libzstd causes "free(): invalid pointer" on Steam Deck / Ubuntu LTS
if (process.platform === 'linux' && process.env.HYTALE_NO_LIBZSTD_FIX !== '1') { if (process.platform === 'linux' && process.env.HYTALE_NO_LIBZSTD_FIX !== '1') {
@@ -461,21 +474,15 @@ exec "$REAL_JAVA" "\${ARGS[@]}"
} }
}); });
// Monitor game process status in background - wait 5 seconds for verification // Process is detached and unref'd - it runs independently from the launcher
launchCheckTimeout = setTimeout(() => { // We cannot reliably detect if the game window actually appears from here,
if (!hasExited) { // so we report success after spawning. stdout/stderr logging above provides debugging info.
console.log('Game appears to be running successfully'); console.log('Game process spawned and detached successfully');
// Keep process reference active - don't unref() immediately
// This ensures the launcher stays alive while the game is running
if (progressCallback) { if (progressCallback) {
progressCallback('Game launched successfully', 100, null, null, null); progressCallback('Game launched successfully', 100, null, null, null);
} }
} else if (!outputReceived) {
console.warn('Game process exited immediately with no output - possible issue with game files or dependencies');
}
}, 5000);
// Return immediately, don't wait for setTimeout // Return immediately after spawn
return { success: true, installed: true, launched: true, pid: child.pid }; return { success: true, installed: true, launched: true, pid: child.pid };
} catch (spawnError) { } catch (spawnError) {
console.error(`Error spawning game process: ${spawnError.message}`); console.error(`Error spawning game process: ${spawnError.message}`);