# HG changeset patch # User Adam Kaminski # Date 1627017742 14400 # Fri Jul 23 01:22:22 2021 -0400 # Node ID 3cfa4aa5d621be7112c88b4fb4a298281d196b01 # Parent 068ab3534f45bc313c22cd33bbfde4f29cf7533b Fixed a crash when assigning a random player class to a spectator in singleplayer games. diff -r 068ab3534f45 -r 3cfa4aa5d621 src/g_level.cpp --- a/src/g_level.cpp Fri Jul 23 00:38:47 2021 -0400 +++ b/src/g_level.cpp Fri Jul 23 01:22:22 2021 -0400 @@ -130,7 +130,8 @@ void G_VerifySkill(); -static FRandom pr_classchoice ("RandomPlayerClassChoice"); +// [AK] Changed pr_classchoice into a non-static variable. +FRandom pr_classchoice ("RandomPlayerClassChoice"); static FRandom g_RandomMapSeed( "MapSeed" ); extern level_info_t TheDefaultLevelInfo; diff -r 068ab3534f45 -r 3cfa4aa5d621 src/p_user.cpp --- a/src/p_user.cpp Fri Jul 23 00:38:47 2021 -0400 +++ b/src/p_user.cpp Fri Jul 23 01:22:22 2021 -0400 @@ -3304,6 +3304,9 @@ +// [AK] We'll need this if we need to assign a random class to a player. +extern FRandom pr_classchoice; + //***************************************************************************** // void PLAYER_JoinGameFromSpectators( int iChar ) @@ -3342,8 +3345,14 @@ // [BB] In single player, allow the player to switch its class when changing from spectator to player. if ( ( NETWORK_GetState( ) == NETSTATE_SINGLE ) || ( NETWORK_GetState( ) == NETSTATE_SINGLE_MULTIPLAYER ) ) + { SinglePlayerClass[consoleplayer] = players[consoleplayer].userinfo.GetPlayerClassNum(); + // [AK] Assign a random class for the player if necessary. + if ( SinglePlayerClass[consoleplayer] < 0 ) + SinglePlayerClass[consoleplayer] = ( pr_classchoice() ) % PlayerClasses.Size(); + } + PLAYER_SpectatorJoinsGame( &players[consoleplayer] ); players[consoleplayer].camera = players[consoleplayer].mo; Printf( "%s joined the game.\n", players[consoleplayer].userinfo.GetName() );