Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Steam client initialization fails with VersionMismatch error (Unity, Windows, IL2CPP) #802

Open
ndepoel opened this issue Jan 22, 2025 · 0 comments · May be fixed by #803
Open

Steam client initialization fails with VersionMismatch error (Unity, Windows, IL2CPP) #802

ndepoel opened this issue Jan 22, 2025 · 0 comments · May be fixed by #803
Assignees

Comments

@ndepoel
Copy link

ndepoel commented Jan 22, 2025

Describe the bug
In standalone Unity IL2CPP builds on Windows, about 1 in 10 times Steam initialization will fail with a message similar to:

Exception: SteamApi_Init failed with VersionMismatch - error: No ����������G����

Apparently the Steam library is returning an error message string containing garbage bytes from adjacent memory, indicating that it's not constructing the string correctly or failing to properly null-terminate it.

This issue is similar to the bug reported for SteamDeck here, however what we are seeing is intermittent and not happening consistently. Also the other issue mentioned Steam initialization working as expected on Windows, which is not what we're experiencing.

We're using the latest Facepunch release 2.4.1 with Steamworks 1.61.

To Reproduce
Steps to reproduce the behavior:

  1. Create a blank Unity project and open it for the default Windows build target
  2. Add the Facepunch Steamworks plugin for Unity to the project, underneath the Assets/Plugins directory
  3. Add a new script to the SampleScene containing the following code:
using System;
using Steamworks;
using UnityEngine;

public class SteamTest : MonoBehaviour
{
    public uint appId;
    
    void Start()
    {
        try
        {
            Debug.Log("Initializing Steam client...");
            SteamClient.Init(appId, asyncCallbacks: true);
            Debug.LogError("Steam successfully initialized!");  // Logging as error to get some visual feedback
        }
        catch (Exception ex)
        {
            Debug.LogException(ex);
        }
    }

    private void OnDestroy()
    {
        Debug.Log("Shutting down Steam client...");
        SteamClient.Shutdown();
    }
}
  1. Enter an existing Steam App ID on the script component in the scene, and save the scene
  2. In the project's Player Settings -> Other Settings, set Scripting Backend to IL2CPP
  3. In File -> Build Profiles, select the Windows build target and enable Development Build and Script Debugging
  4. Create a Windows build with the SampleScene included
  5. Run the standalone build several times and observe that sometimes an exception will be logged

Calling Code

SteamClient.Init(appId, asyncCallbacks: true);

Expected behavior
Steam initialization should succeed and behave consistently between application runs.

Desktop (please complete the following information):

  • OS: Windows 10
  • Unity: Unity 6000.0.34f1

Additional context
The intermittent nature as well as the memory corruption leads me to believe this may be some kind of race condition.

Other things I've tried:

  • Created a standalone C++ console application that compiles directly against the Steamworks SDK which replicates the initialization steps from Facepunch. I have not been able to reproduce the error with this.
  • Created a standalone C# console application that uses P/Invoke to initialize Steamworks, similar to how Facepunch does this. I have not been able to reproduce the error with this.
  • Included Facepunch Steamworks as source code in our Unity project instead of using the precompiled DLLs. The issue is still reproducible with this.
  • Rebuilt my Unity test project using the Mono scripting backend. With this I have not been able to reproduce the error.

So it appears that this problem is unique to Unity's interaction with the Steamworks native library, specifically when using the IL2CPP scripting backend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants