rlabrecque / Steamworks.NET

Steamworks wrapper for Unity / C#
http://steamworks.github.io
MIT License
2.84k stars 369 forks source link

Steamworks.NET crashes Unity 2017.2.0f3 #195

Closed plmayer closed 3 years ago

plmayer commented 7 years ago

I am using the current version of the wrapper, and the current version of SteamManager.cs (1.0.5). I experience crashes in the Unity editor - AFAIK, only after having hit PLAY at least once (and stopping the game again, so not WHILE the game is running, but afterwards). The issue goes away if I remove the Steamworks.NET folder from Unity.

I use the SteamManager class, and do set some achievements and stats in the game.

There is no error message or entry in the log. Not even the Unity crash reporter shows up.

Is anyone else experiencing this issue?

plmayer commented 7 years ago

By the way, I am NOT registering any callbacks and forgetting to Dispose() them. I entertained the thought that this might be the issue for a while (despite the fact that the examples don't Dispose() either), but unfortunately, without any callbacks registered at all, the problem persists.

Also, commenting out all code in SteamManager.cs resolves the problem as well, so it is not some weird DLL loading issue.

rlabrecque commented 7 years ago

Hey @plmayer, I've been following your Unity forum post too, what OS are you on? And what graphics settings?

Could you try something for me: Remove Steamworks.NET and add the Unity Editor to Steam as a shortcut. Try launching it from there and see if you can reproduce this like that?

plmayer commented 7 years ago

Hi, thanks for your reply. I am on Windows 10 64bit, Unity 2017.2.0f3 on top. I'm not sure what you are referring to with "graphics settings", but I am developing for SteamVR (Vive/Rift), so we are talking about the native Vive/Rift resolution for VR plus the left eye mirrored onto the regular screen (windowed). Achievements may pop up in VR when starting from the editor, but may also not (I am not sure what this is dependent on).

As per your request, I've removed the Steamworks code and added Unity as an external game to Steam and launched it. The first time I launched Unity this way, it immediately crashed after calculating lighting (before I even started my game) - lighting is the last entry in the log, no "Crash!!!" as sometimes happens. On the second launch, Unity did start up and I could start my game four times without crashes, on the 5th, it crashed on me after stopping the game - as it does when using Steamworks.NET (it never crashes WHILE the game is running, always afterwards). From the timing, it is quite possible that it is the same reason. Again, no "Crash!!!" in the log, but that doesn't always appear.

rlabrecque commented 7 years ago

Mmmmmm yeah that's worrying. The only thing that happens when you add a shortcut in Steam like that is Steam injects the overlay into the process. There was a Steam beta update that fixed a memory leak when running under Vulkan, but I'm not sure if Unity on Windows uses Vulkan at all.

https://steamcommunity.com/groups/SteamClientBeta#announcements/detail/1456213434738131018

Try changing your Graphics API as outlined by this post: https://blogs.unity3d.com/2016/09/29/introducing-the-vulkan-renderer-preview/

plmayer commented 7 years ago

We're not using Vulkan in our game (it has to be enabled explicitly as far as I can see) so I don't think that this issue affects us. However, since you mention the overlay: I will try disabling the Steam overlay entirely (Steam settings) and see if that fixes the issue. I'll report back.

plmayer commented 7 years ago

Nope, Unity still crashes if using Steamworks.net code and having the Steam overlay disabled. EDIT: Apparently Steam doesn't honor that checkbox anyway. I have the setting disabled "[ ] Enable the Steam Overlay while in-game" in "In-Game" settings - and I still see achievement popups.

rlabrecque commented 7 years ago

Yeah, If I remember correctly disabling it doesn't stop the injection/hooking. And... it doesn't work as well with Shortcuts? :/

rlabrecque commented 7 years ago

I wonder if your editor was using DX12? Another crash fix from Steam for that: http://steamcommunity.com/groups/SteamClientBeta/announcements/detail/1461843851749212399

teamninjathumbs commented 6 years ago

Also experiencing this issue. I was getting it with 5.6, and upgraded to 2017.2.0p4 in hopes of a magic cure - no luck though. Same behaviour as described by @plmayer - after 1 or more play sessions; not during play, but some time after pressing stop.

Notes:

Will update with more info if I think of anything! Cheers :)

plmayer commented 6 years ago

I've not had a chance to test this further since my last post :-(. Since @teamninjathumbs you are probably using the newest Steam runtime, plus DX11, it is not the DX12 issue which @rlabrecque mentioned. @teamninjathumbs Are you using Virtual Reality or is this unrelated to VR? The crash log sure is interesting, maybe this issue should be brought to Valve's attention?

teamninjathumbs commented 6 years ago

I'm not using VR in this project, no - although I do have the Steam VR devkit stuff installed on the system. I could always try uninstalling that and see if it makes a difference at all. Might be worth a go, even if it's a long shot :) Will report back in a bit.

teamninjathumbs commented 6 years ago

Well, I haven't had the Unity Editor crash so far since uninstalling the SteamVR SDK. Not exactly definitive proof (as crash frequency was pretty random), but potentially interesting!

teamninjathumbs commented 6 years ago

Damn, got a 'gameoverlayrenderer64.dll' access violation crash this morning with all the SteamVR stuff uninstalled, so there goes that theory I suppose.. :(

I followed the steps in https://docs.unity3d.com/Manual/WindowsDebugging.html in order to launch MSVC in debug mode when Unity crashes. Not too much extra info though, other than that the pointer the overlay was trying to dereference was set to 0xFFFFFFFF.

rlabrecque commented 6 years ago

Hey @teamninjathumbs, could you check if you have any files in C:\Path\to\Steam\dumps? If you have some gameoverlayrenderer64[...].dmp files could you email one or more of them to me? support [a t] rileylabrecque.com, I'll try to get them to someone at Valve that can take a look at them!

teamninjathumbs commented 6 years ago

Sure thing! I have 5 dumps in there - they are all of the assert_testhost.x86.exe[...].dmp flavor though, nothing specfically mentioning gameoverlayrenderer64. Would those be of any interest? If not, I can continue to monitor the dumps folder and keep an eye out for instances of gameoverlayrenderer64[...].dmp.

rlabrecque commented 6 years ago

Hmm, interesting, could you try https://voidtools.com and seeing if there's any other .mdmp or .dmp files laying around anywhere? How are you starting Visual Studio? testhost.exe comes from it, so I wonder if it's something to do with gameoverlayrenderer64.exe hooking into VS, which it can do unfortunately... but only if you start VS after entering play mode the first time.

teamninjathumbs commented 6 years ago

Using that tool, found some Unity.exe .dmp files in my AppData\Local. These look interesting, as they mention gameoverlayrenderer64.dll in the stack trace:

image

Happy to send one or more of those .dmp files through if you want.

I have noticed some odd rendering artifacts from time to time in VS, and previously just have assumed that the Steam overlay stuff was a bit 'promiscuous' in its hooking. Lately I've been tending to launch VS from the taskbar to try and avoid having it as a child process of Unity. I'm not very consistent though - sometimes I forget and launch by double-clicking a script in Unity. It could well be that the crashes occur when I have taken the latter approach and the overlay has hooked into VS - I will pay close attention to that from now on.

Thanks for your help, much appreciated BTW!

rlabrecque commented 6 years ago

Yeah for sure forward both those and the testhost dumps to me and I'll pass them on!

plmayer commented 6 years ago

I just tried to reproduce this with Unity 2017.3.0f3, and was not able to. So either Unity changed something or SteamVR was updated, or both. @teamninjathumbs can you try in 2017.3.0f3? Maybe the issue solved itself.

teamninjathumbs commented 6 years ago

I've had to roll back to 5.6.4f1 for now unfortunately, due to a different showstopper crash in 2017.x builds (looks like some kinda regression with UGUI). Might have another go at 2017.3 in a bit, but have probably burned a bit too much time on the upgrade for now. Will certainly post an update here if/when that happens.

I haven't been experiencing the crash at all lately in 5.6.4f1. Have been sticking to a regimen of opening Visual Studio separately so that the Steam overlay doesn't hook into it (@rlabrecque was thinking it might be something to do with that), and that seems to be working as far as I can tell. It could also be that they have fixed something in Unity lately though, as you say.

Note that I uninstalled the Steam VR SDK a while back but it didn't stop the crashes, so I've been assuming it isn't specific to VR.

@plmayer Do you use VS for editing the scripts, and do you launch it from within Unity, or separately?

plmayer commented 6 years ago

Yes, I use VS (Community, 2017), and I launch it from within Unity.

lilnukey commented 6 years ago

Does this only happen in the editor? I've been recently getting a crash

steam_api64.dll caused an Access Violation

everytime I stop playing my game within the editor. I didn't change anything so I'm not sure why it is crashing now because it was working fine before. Kind of bummed I have to restart the Editor everytime I run the game.

@rlabrecque Were you ever able to find out a fix for this?

coty-crg commented 6 years ago

Same issue on 2017.3.1p4 and 2017.4.5f1

commenting out SteamAPI.Init() "fixes" it, but of course we cant do this.

edit: im a dummy, was calling SteamNetworking from another thread and it was crashing unity. don't call things from the steam api on another thread

hymerman commented 6 years ago

I'm getting this in Unity 2018.1.0f2, game is built as Win 64 Standalone, .NET 4.6 runtime. Same kind of callstack as @teamninjathumbs . I can find very little information on this, but I'm fairly sure that it's not a Steamworks.NET issue, but a Steam issue! Lots of other games crash with similar issues. I have found that deleting the DLL and disabling the in-game overlay 'fixes' the problem.

Exception thrown at 0x00007FFAA3AE5848 (ntdll.dll) in TPH.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.

>   ntdll.dll!RtlDosApplyFileIsolationRedirection_Ustr()    Unknown
ntdll.dll!LdrpApplyFileNameRedirection()   Unknown
ntdll.dll!LdrpPreprocessDllName()   Unknown
ntdll.dll!LdrpFindLoadedDll()   Unknown
ntdll.dll!LdrGetDllHandleEx()   Unknown
ntdll.dll!LdrGetDllHandle()    Unknown
KernelBase.dll!00007ffa9ffe9d53()   Unknown
GameOverlayRenderer64.dll!00007ffa85179bca()    Unknown
GameOverlayRenderer64.dll!00007ffa8517afa0()    Unknown
GameOverlayRenderer64.dll!00007ffa8517b1c9()    Unknown
mono-2.0-bdwgc.dll!00007ffa5fdd096a()   Unknown
mono-2.0-bdwgc.dll!00007ffa5fdd195c()   Unknown
mono-2.0-bdwgc.dll!00007ffa5fdca8ef()   Unknown
[External Code]
SniperED007 commented 6 years ago

Having the same issue where Unity crashes after I stop running the game... Unity 2018.2.8f1 I removed this line of code from OnDestroy() in SteamManager and now it doesn't crash: SteamAPI.Shutdown();

flashmandv commented 5 years ago

I have the issue as well. I'm trying with Unity 2017.1.2 and Mac OS X HIgh Sierra. Using v12 of the steam unity plugin..but it simply crashes the editor when I press Editor play button

rlabrecque commented 3 years ago

This seems to have magically fixed itself in the last couple years. Likely a Steam bug?

purpleTurtle08 commented 8 months ago

Steamworks.NET is still crashing Unity 2021.3.10f1 Editor..... I tried commenting every SteamAPI.Shutdown but no luck.... it's so frustrating because the editor crashes randomly. It is 100% related to steamworks sdk because with it disabled, the editor never crashes.