Search Unity

Question LobbyService.Instance.CreateLobbyAsync() crashes without reason

Discussion in 'Lobby' started by a1creator, Jan 20, 2023.

  1. a1creator

    a1creator

    Joined:
    Jan 18, 2021
    Posts:
    24
    I am currently writing a lobby for my upcoming game and everything was working fine, all errors were caught in my try/catch'es and lobby worked.
    Suddenly, my CreateLobby() function started crashing. I have deduced it with manual print-debugging to this line:
    hostLobby = await LobbyService.Instance.CreateLobbyAsync(lobbyname, playerLimit, lobbyOptions);


    I even tried copying identical code and running it and it worked, but when I deleted the faulty one the working one turned faulty.
    When I run the code, Unity stops working for a few seconds and then closes by itself. I get no Error Logs or anything!

    Here is the full code snippet that is run:
    Code (CSharp):
    1. public async void CreateLobby(string lobbyname, short playerLimit, bool isPrivate = false, bool micOnly = false)
    2.     {
    3.         if (hostLobby != null)
    4.         {
    5.             DisplayError("Tried to create a lobby while in one.");
    6.             return;
    7.         }
    8.  
    9.         // create the options for the lobby
    10.         CreateLobbyOptions lobbyOptions = new CreateLobbyOptions
    11.         {
    12.             IsPrivate = isPrivate,
    13.             Player = SteamLobbyTools.CreatePlayer(MySteamManager.AskFor.UserName,
    14.                                   MySteamManager.AskFor.UserID.m_SteamID.ToString()),
    15.             Data = SteamLobbyTools.GetLobbyDataObjects(micOnly, "Sniper", "EU")
    16.         };
    17.  
    18.         try
    19.         {
    20.             // ------------------ This is the line that crashes ------------------
    21.             hostLobby = await LobbyService.Instance.CreateLobbyAsync(lobbyname, playerLimit, lobbyOptions);
    22.         }
    23.         catch (LobbyServiceException e)
    24.         {
    25.             DisplayError(e);
    26.         }
    27.  
    28.         // if we succeeded in creating the lobby:
    29.         if (hostLobby != null)
    30.         {
    31.             a1_Logs.Log("Created lobby with code: " + hostLobby.LobbyCode);
    32.             joinedLobby = hostLobby;
    33.  
    34.             StartLobbyInformationUpdatePoll();
    35.  
    36.             // visualize playerlist
    37.             StartHosting(joinedLobby);
    38.  
    39.             LobbyUIController.AskFor.RefreshUIState(LobbyUIState.InsideLobby);
    40.         }
    41.     }


    MySteamManager is unrelated to the issue, as they return a default value even if not Initialized.
    These are the SteamTools Functions ( I tested without using them aswell, they are supposedly not the issue ):

    Code (CSharp):
    1.  
    2.  
    3. public static Player CreatePlayer(string name, string steamID)
    4.     {
    5.         return new Player
    6.         {
    7.             Data = new Dictionary<string, PlayerDataObject>
    8.             {
    9.                 { "name", new PlayerDataObject(PlayerDataObject.VisibilityOptions.Member, name) },
    10.                 { "steamid", new PlayerDataObject(PlayerDataObject.VisibilityOptions.Member, steamID) },
    11.                 { "isready", new PlayerDataObject(PlayerDataObject.VisibilityOptions.Member, "false") }
    12.             }
    13.         };
    14.     }
    15.  
    16. public static Dictionary<string, DataObject> GetLobbyDataObjects(bool micOnly, string gamemode, string region)
    17.     {
    18.         return new Dictionary<string, DataObject>
    19.         {
    20.             {"micOnly", new DataObject(DataObject.VisibilityOptions.Public, micOnly.ToString(), DataObject.IndexOptions.S1) },
    21.             {"gamemode", new DataObject(DataObject.VisibilityOptions.Public, gamemode, DataObject.IndexOptions.S2) },
    22.             {"region", new DataObject(DataObject.VisibilityOptions.Public, region, DataObject.IndexOptions.S3) }
    23.         };
    24.     }
    25.  
    Please, please help me. I am stuck in development until I solve this issue and it has already been two days
     
  2. a1creator

    a1creator

    Joined:
    Jan 18, 2021
    Posts:
    24
    *By SteamTools i meant SteamLobbyTools
    it's just a static class i created for creating new lobbydataobjects
     
  3. RobustKnittedTortoise

    RobustKnittedTortoise

    Unity Technologies

    Joined:
    Dec 10, 2018
    Posts:
    16
    Its hard to say what the issue is with this much info but perhaps you could find out the exact error by adding a more general exception catch after the lobby specific one:

    Code (CSharp):
    1.     try
    2.         {
    3.             // ------------------ This is the line that crashes ------------------
    4.             hostLobby = await LobbyService.Instance.CreateLobbyAsync(lobbyname, playerLimit, lobbyOptions);
    5.         }
    6.         catch (LobbyServiceException e)
    7.         {
    8.             DisplayError(e);
    9.         }
    10.         catch (Exception ex)
    11.         {
    12.             // Something really bad happened
    13.             DisplayError(ex);
    14.         }
    15.  
    16.  
    Off the top of my head, things that could have changed independently of this code block are possibly the player not being signed in or the project no longer being linked to a valid project with lobby enabled.
     
    a1creator likes this.
  4. a1creator

    a1creator

    Joined:
    Jan 18, 2021
    Posts:
    24
    Thanks for replying so quickly. I will check if I unlinked it by accident and try with a more general exception. Thank you!
     
  5. a1creator

    a1creator

    Joined:
    Jan 18, 2021
    Posts:
    24
    Okay. The project is indeed still linked and I do sign in. Catching a generic error did not help either.
    I get no information about the crash, as Unity doesn't go further than the line. It doesn't get to the catch clause.

    As soon as it gets to "await LobbyService.Instance.CreateLobbyAsync()" it stops running and Unity closes itself without any information.
     
  6. MiTschMR

    MiTschMR

    Joined:
    Aug 28, 2018
    Posts:
    487
    a1creator likes this.
  7. a1creator

    a1creator

    Joined:
    Jan 18, 2021
    Posts:
    24
    Thank you for replying. I hadn't thought of this, and just did. As I feared, this is what it says:

    =================================================================
    Native Crash Reporting
    =================================================================
    Got a UNKNOWN while executing native code. This usually indicates
    a fatal error in the mono runtime or one of the native libraries
    used by your application.
    =================================================================

    =================================================================
    Managed Stacktrace:
    =================================================================
    =================================================================



    I have no idea what to do with this. My code is as it was when it worked two weeks ago. The crash seemingly doesn't happen by something I've written (?) It has to be, but anything I've tried does not work
     
  8. a1creator

    a1creator

    Joined:
    Jan 18, 2021
    Posts:
    24
    I fixed it.
    Not to worry for anyone else; it was completely my fault.
    Unity didn't help debug it but still, my fault.

    I had created a function that used another function that used the root function again, creating an infinite loop.
    I think the reason it never showed was because of the "async await" in the Lobby Creation funciton.
    Everything works now.

    Thank you to the heroes that tried to rescue me
     
    Last edited: Feb 5, 2023
    MiTschMR likes this.