oldnapalm / GTACoop

GTA V multiplayer mod
GNU General Public License v3.0
29 stars 4 forks source link

Crash when entering story mode #9

Closed ItsQuadrus closed 4 months ago

ItsQuadrus commented 4 months ago

Hello. Thanks for maintaining this fork. The game crashes when the player enters story mode from the main menu (which AFAIK is the only way to be able to join multiplayer servers) No log is ever created in %localappdata%\cgmp\gtacoop.

Script hook (crash occurs at 15:19:26):

// GTA V SCRIPT HOOK (build Jun 28 2024, v1.0.3258.0)
//     (C) Alexander Blade 2015-2024
[15:18:16] INIT: Started
[15:18:16] INIT: Success, game version is VER_1_0_3258_0
[15:18:16] INIT: Registering script 'ScriptHookVDotNet.asi' (0x0000000180002830)
[15:18:21] INIT: Pool 1 extended
[15:18:21] INIT: Pool 2 extended
[15:18:21] INIT: Pool 3 extended
[15:18:21] INIT: Pool 4 extended
[15:18:26] INIT: GtaThread collection size 189
[15:18:26] INIT: wnd proc 0x00000000FFFF0025
[15:18:26] INIT: IDXGISwapChain 0x00006FFFFC522580 (0x00006FFFFC391E20)
[15:18:26] INIT: IDXGISwapChain set
[15:18:26] INIT: DX init started
[15:18:26] INIT: DX feature level B000
[15:18:26] INIT: DX init succeeded
[15:19:25] CORE: Requesting thread creation
[15:19:25] CORE: Creating threads
[15:19:26] CORE: Started control thread, id 44 active 1
[15:19:26] CORE: Started thread 'ScriptHookVDotNet.asi' (0x0000000180002830), id 45 active 1
[15:19:26] CORE: Launching main() for 'ScriptHookVDotNet.asi' (0x0000000180002830), id 45
[15:19:26] UNINIT: Unregistering script 'ScriptHookVDotNet.asi'

Script hook dotnet:

[15:19:26] [DEBUG] Loading API from .\ScriptHookVDotNet2.dll ...
[15:19:26] [DEBUG] Loading API from .\ScriptHookVDotNet3.dll ...

Trace:

Unhandled Exception:
System.ObjectDisposedException: Cannot access a disposed object.
  at System.Threading.ReaderWriterLockSlim.TryEnterWriteLockCore (System.Threading.ReaderWriterLockSlim+TimeoutTracker timeout) [0x00008] in <e94c0cd07ce34bdcb485ac2ab9838c50>:0 
  at System.Threading.ReaderWriterLockSlim.TryEnterWriteLock (System.Threading.ReaderWriterLockSlim+TimeoutTracker timeout) [0x00000] in <e94c0cd07ce34bdcb485ac2ab9838c50>:0 
  at System.Threading.ReaderWriterLockSlim.TryEnterWriteLock (System.Int32 millisecondsTimeout) [0x00007] in <e94c0cd07ce34bdcb485ac2ab9838c50>:0 
  at System.Threading.ReaderWriterLockSlim.EnterWriteLock () [0x00000] in <e94c0cd07ce34bdcb485ac2ab9838c50>:0 
  at SHVDN.ScriptDomain.InitTlsStuffForTlsContextSwitch (System.IntPtr getTlsContextFunc, System.IntPtr setTlsContextFunc, System.IntPtr tlsAddr, System.UInt32 threadId) [0x00000] in <a5cc144240574ed089a5b7a83cda074c>:0 
  at <Module>.?A0x50ad6f61.ScriptHookVDotNet_ManagedInit () [0x00384] in <a5cc144240574ed089a5b7a83cda074c>:0 
  at (wrapper native-to-managed) <Module>.?A0x50ad6f61.ScriptHookVDotNet_ManagedInit()
[ERROR] FATAL UNHANDLED EXCEPTION: System.ObjectDisposedException: Cannot access a disposed object.
  at System.Threading.ReaderWriterLockSlim.TryEnterWriteLockCore (System.Threading.ReaderWriterLockSlim+TimeoutTracker timeout) [0x00008] in <e94c0cd07ce34bdcb485ac2ab9838c50>:0 
  at System.Threading.ReaderWriterLockSlim.TryEnterWriteLock (System.Threading.ReaderWriterLockSlim+TimeoutTracker timeout) [0x00000] in <e94c0cd07ce34bdcb485ac2ab9838c50>:0 
  at System.Threading.ReaderWriterLockSlim.TryEnterWriteLock (System.Int32 millisecondsTimeout) [0x00007] in <e94c0cd07ce34bdcb485ac2ab9838c50>:0 
  at System.Threading.ReaderWriterLockSlim.EnterWriteLock () [0x00000] in <e94c0cd07ce34bdcb485ac2ab9838c50>:0 
  at SHVDN.ScriptDomain.InitTlsStuffForTlsContextSwitch (System.IntPtr getTlsContextFunc, System.IntPtr setTlsContextFunc, System.IntPtr tlsAddr, System.UInt32 threadId) [0x00000] in <a5cc144240574ed089a5b7a83cda074c>:0 
    at <Module>.?A0x50ad6f61.ScriptHookVDotNet_ManagedInit () [0x00384] in <a5cc144240574ed089a5b7a83cda074c>:0 

Everything is latest: GTA V, Script hook, Script hook dotnet, GTACoop

Any help is appreciated!

oldnapalm commented 4 months ago

Hi. The game update 1.0.3258 broke ScriptHookVDotNet, you will need to use the nightly build (not only for GTA Coop) at least until a new stable version is released.

https://github.com/scripthookvdotnet/scripthookvdotnet-nightly/releases

If you are having the crash using the latest nightly build I suggest that you follow this issue https://github.com/scripthookvdotnet/scripthookvdotnet/issues/1454

ItsQuadrus commented 4 months ago

Yeah I'm using the latest nightly build already. This bug is pretty weird and I don't really get what the Scripthook dotnet maintainer is talking about ("TLS stuff"? how? what?). I hope there will be some sort of update soon because the core issue is still pretty blurry (for me atleast).

ItsQuadrus commented 4 months ago

For the record, I know what thread-local storage is, but I'm not too familiar with the SDK of Scripthook itself. I also find it pretty weird that people build on top of this library that you can only get from an HTTP-only website.

oldnapalm commented 4 months ago

Have you tried setting AutoLoadScripts=false in ScriptHookVDotNet.ini?

Then, if it allows you to enter story mode, open the console (F4 by default) and run the StartAllScripts() command.

Specifies whether the domain of SHVDN should auto load scripts in the scripts folder when the first game session is starting or SHVDN is reloading (recreating a new domain). If you encounter some compatibility issues such as nondeterministic game crashes (due to flaws of multithreading implementation of SHVDN), setting this value to "false" may workaround them. You will need to load scripts via console commands when set to "false", and you can use the console command StartAllScripts to start all scripts in the scripts folder. Acceptable value: "true" or "false" (case-insensitive)

ItsQuadrus commented 4 months ago

I set AutoLoadScripts=false in the config. I get the exact same results.

The loading of story mode took a while so I alt tabbed out and the second I alt tabbed back in, I saw the game fully loaded but it closed itself immediately.

Tried it again, it just crashes in the loading story mode screen.

Same error. Does ScriptHookVDotNet only load when I'm not focused on the game window?

ItsQuadrus commented 4 months ago

As you said:

game update 1.0.3258 broke ScriptHookVDotNet

Is downgrading a possibility? I have the game through Steam.

oldnapalm commented 4 months ago

The "infinite loading" with alt-tab workaround is a known issue with the nightly builds, according to https://github.com/scripthookvdotnet/scripthookvdotnet/issues/1454#issuecomment-2211766743

Downgrading the Steam version is possible https://steamcommunity.com/sharedfiles/filedetails/?id=3114772292

ItsQuadrus commented 4 months ago

Thanks! Looks like Scripthook Dotnet is not quite ready for the latest version yet. Is v1.0.3028.0 a recommended version for modding in general?

oldnapalm commented 4 months ago

Any version up to 3179 will work with the stable release of SHVDN.

https://www.reddit.com/r/Gta5Modding/comments/1dogvuy/howto_guide_on_downgrading_from_3258_to_3179/

ItsQuadrus commented 4 months ago

I see you've closed the issue @oldnapalm. Could you reopen it because the crash is still happening in 3179 with the stable version of SHVDN? This time it outputs the error in the log file of SHVDN:

[17:41:32] [ERROR] Failed to create console: System.NullReferenceException: Object reference not set to an instance of an object
  at System.AppDomain.CreateInstanceFromAndUnwrap (System.String assemblyName, System.String typeName) [0x00000] in <f1249a148cfb4110b9a02139e12e4308>:0 
  at <Module>.?A0xc1aa4bd5.ScriptHookVDotnet_ManagedInit () [0x00188] in <0f1133baa2e243d2802541074a8dc0b4>:0 
ItsQuadrus commented 4 months ago

I believe I have downgraded correctly both GTA V and SHVDN...? I'm not sure if I'm doing something wrong.

oldnapalm commented 4 months ago

Make sure you are using the stable release https://github.com/scripthookvdotnet/scripthookvdotnet/releases/tag/v3.6.0

Post the full ScriptHookVDotNet.log (the error above doesn't seem to be from GTA Coop).

oldnapalm commented 4 months ago

Also check "properties - details" of GTA5.exe and ScriptHookV.log (INIT: Success, game version is VER_1_0_3179_0) to make sure the game is properly downgraded.

ItsQuadrus commented 4 months ago

Full logs from earlier:

// GTA V SCRIPT HOOK (build Jun 28 2024, v1.0.3258.0)
//     (C) Alexander Blade 2015-2024
[17:37:55] INIT: Started
[17:37:55] INIT: Success, game version is VER_1_0_3179_0
[17:37:55] INIT: Registering script 'ScriptHookVDotNet.asi' (0x0000000180001480)
[17:38:00] INIT: Pool 1 extended
[17:38:00] INIT: Pool 2 extended
[17:38:00] INIT: Pool 3 extended
[17:38:00] INIT: Pool 4 extended
[17:38:05] INIT: GtaThread collection size 189
[17:38:05] INIT: wnd proc 0x00000000FFFF0025
[17:38:05] INIT: IDXGISwapChain 0x00006FFFFC522580 (0x00006FFFFC391E20)
[17:38:05] INIT: IDXGISwapChain set
[17:38:05] INIT: DX init started
[17:38:05] INIT: DX feature level B000
[17:38:05] INIT: DX init succeeded
[17:41:32] CORE: Requesting thread creation
[17:41:32] CORE: Creating threads
[17:41:32] CORE: Started control thread, id 41 active 1
[17:41:32] CORE: Started thread 'ScriptHookVDotNet.asi' (0x0000000180001480), id 42 active 1
[17:41:32] CORE: Launching main() for 'ScriptHookVDotNet.asi' (0x0000000180001480), id 42
[17:41:32] [DEBUG] Loading API from .\ScriptHookVDotNet2.dll ...
[17:41:32] [DEBUG] Loading API from .\ScriptHookVDotNet3.dll ...
[17:41:32] [ERROR] Failed to create console: System.NullReferenceException: Object reference not set to an instance of an object
  at System.AppDomain.CreateInstanceFromAndUnwrap (System.String assemblyName, System.String typeName) [0x00000] in <f1249a148cfb4110b9a02139e12e4308>:0 
  at <Module>.?A0xc1aa4bd5.ScriptHookVDotnet_ManagedInit () [0x00188] in <0f1133baa2e243d2802541074a8dc0b4>:0 

When the game starts, the bottom right-hand corner does show 3179.

oldnapalm commented 4 months ago

SHVDN is crashing before loading scripts, apparently this error is caused by missing requirement (.NET Framework 4.8)

https://github.com/scripthookvdotnet/scripthookvdotnet?tab=readme-ov-file#requirements

ItsQuadrus commented 4 months ago

This is not really releated but I get this error now when I launch the game (with .NET Framework 4.8 installed) https://learn.microsoft.com/en-us/dotnet/framework/install/application-not-started?version=(null)&processName=rundll32.exe&platform=0009&osver=3&isServer=0&shimver=4.0.30319.0

I'm going to try to fix this.

ItsQuadrus commented 4 months ago

Done. I had some issues but now it works really well. I'll let you know if I have any more issues with the script.

Thanks for all the help!