mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2025-02-26 13:31:17 +03:00
Some collection modified safety in Dispatch (seeing a few exceptions on Rust staging)
This commit is contained in:
parent
5aeeaa0cd7
commit
e6c0167c48
@ -65,30 +65,54 @@ namespace Steamworks
|
|||||||
SteamAPI_ManualDispatch_Init();
|
SteamAPI_ManualDispatch_Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Make sure we don't call Frame in a callback - because that'll cause some issues for everyone.
|
||||||
|
/// </summary>
|
||||||
|
static bool runningFrame = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Calls RunFrame and processes events from this Steam Pipe
|
/// Calls RunFrame and processes events from this Steam Pipe
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static void Frame( HSteamPipe pipe )
|
internal static void Frame( HSteamPipe pipe )
|
||||||
{
|
{
|
||||||
SteamAPI_ManualDispatch_RunFrame( pipe );
|
if ( runningFrame )
|
||||||
SteamNetworkingUtils.OutputDebugMessages();
|
return;
|
||||||
|
|
||||||
CallbackMsg_t msg = default;
|
try
|
||||||
|
|
||||||
while ( SteamAPI_ManualDispatch_GetNextCallback( pipe, ref msg ) )
|
|
||||||
{
|
{
|
||||||
try
|
runningFrame = true;
|
||||||
|
|
||||||
|
SteamAPI_ManualDispatch_RunFrame( pipe );
|
||||||
|
SteamNetworkingUtils.OutputDebugMessages();
|
||||||
|
|
||||||
|
CallbackMsg_t msg = default;
|
||||||
|
|
||||||
|
while ( SteamAPI_ManualDispatch_GetNextCallback( pipe, ref msg ) )
|
||||||
{
|
{
|
||||||
ProcessCallback( msg, pipe == ServerPipe );
|
try
|
||||||
}
|
{
|
||||||
finally
|
ProcessCallback( msg, pipe == ServerPipe );
|
||||||
{
|
}
|
||||||
SteamAPI_ManualDispatch_FreeLastCallback( pipe );
|
finally
|
||||||
|
{
|
||||||
|
SteamAPI_ManualDispatch_FreeLastCallback( pipe );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
runningFrame = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// To be safe we don't call the continuation functions while iterating
|
||||||
|
/// the Callback list. This is maybe overly safe because the only way this
|
||||||
|
/// could be an issue is if the callback list is modified in the continuation
|
||||||
|
/// which would only happen if starting or shutting down in the callback.
|
||||||
|
/// </summary>
|
||||||
|
static List<Action<IntPtr>> actionsToCall = new List<Action<IntPtr>>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A callback is a general global message
|
/// A callback is a general global message
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -108,13 +132,22 @@ namespace Steamworks
|
|||||||
|
|
||||||
if ( Callbacks.TryGetValue( msg.Type, out var list ) )
|
if ( Callbacks.TryGetValue( msg.Type, out var list ) )
|
||||||
{
|
{
|
||||||
|
actionsToCall.Clear();
|
||||||
|
|
||||||
foreach ( var item in list )
|
foreach ( var item in list )
|
||||||
{
|
{
|
||||||
if ( item.server != isServer )
|
if ( item.server != isServer )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
item.action( msg.Data );
|
actionsToCall.Add( item.action );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach ( var action in actionsToCall )
|
||||||
|
{
|
||||||
|
action( msg.Data );
|
||||||
|
}
|
||||||
|
|
||||||
|
actionsToCall.Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user