X2CommunityCore / xcom2-launcher

The Alternative Mod Launcher (AML) is a replacement for the default game launchers from XCOM 2 and XCOM Chimera Squad.
GNU General Public License v3.0
350 stars 52 forks source link

Close after lauch setting doesn't work #317

Open Ziktofel opened 2 years ago

Ziktofel commented 2 years ago

AML Version: 1.5.0

Description The close after launch setting doesn't work: The launcher always closes regardless of the setting

Tepa00 commented 2 years ago

I had similar behavior in 1.5 beta 2, disabling Send anonymous error reports in AML settings stopped it from closing on it's own. Can you try if doing that makes a difference?

Dragon-32 commented 2 years ago

Didn't get this in the beta but did with the full 1.5.0 release

What I found fixed it was setting AML's "close on launch" to true and starting the game. Exit game. Re-start AML and then set "close on launch" to False. That seems to have fixed it.

I think when I started with a fresh settings .xml file the setting was followed, only when I used my migrated settings did it fail. I compared a freshly generated settings file with my historic one using Winmerge and couldn't see any meaningful differences about the config option.

Iridar commented 1 year ago

I had this with 1.5.0 stable on a fresh installation of X2 and AML on Win 10. Launching AML as admin seems to have fixed it.

srinathupadhyayula commented 3 months ago

The Issue here is that it crashes when running the game, as it is accessing memory it should not be...

Here is the callstack of the error:

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at Steamworks.NativeMethods.SteamAPI_ManualDispatch_GetNextCallback(HSteamPipe hSteamPipe, IntPtr pCallbackMsg)
   at Steamworks.CallbackDispatcher.RunFrame(Boolean isGameServer)
   at Steamworks.SteamAPI.RunCallbacks()
   at XCOM2Launcher.Classes.Steam.SteamAPIWrapper.RunCallbacks() in E:\C#\xcom2-launcher-git\xcom2-launcher\xcom2-launcher\xcom2-launcher\Classes\Steam\SteamAPIWrapper.cs:line 17
   at XCOM2Launcher.Forms.MainForm.<>c.<.ctor>b__10_2(Object sender, EventArgs e) in E:\C#\xcom2-launcher-git\xcom2-launcher\xcom2-launcher\xcom2-launcher\Forms\MainForm.cs:line 74
   at System.Windows.Forms.Timer.OnTick(EventArgs e)
   at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at XCOM2Launcher.Program.Main() in E:\C#\xcom2-launcher-git\xcom2-launcher\xcom2-launcher\xcom2-launcher\Program.cs:line 138

The piece of code causing the crash is on line 16 of SteamAPIWrapper.cs in method RunCallbacks() where it is calling SteamAPI.RunCallbacks();

The Problem here is potentially(I am about 99% on this) caused by a combination of 2 things. 1) In Xcom2Env.cs on line 117, when the game is started, SteamAPIWrapper.Shutdown(); is called, which in turn is calling return SteamAPI.Init(); and therefore shutting down SteamAPI(whatever that means). 2) However, in MainForm.cs on line 73, in its constructor, there is a timer that is set to run every 10 seconds, which calls the method SteamAPIWrapper.RunCallbacks();. This is the cause of the crash as the timer continues to call this method even after SteamAPI is shoutdown.

Here is the offending code:

           // Run callbacks
            var t1 = new Timer();
            t1.Tick += (sender, e) => { SteamAPIWrapper.RunCallbacks(); }; // This is the cause of the crash
            t1.Interval = 10;
            t1.Start();

In my local testing, commenting out the line SteamAPIWrapper.Shutdown(); in Xcom2Env mitigates the issue. However, I am still fumbling and stumbling through the code, and have no idea what the consequences of this can be, and why Shutdown() was being called in the first place.