Skip to content

Commit

Permalink
Fixed a crash when repeatedly setting the same CallResult within it's…
Browse files Browse the repository at this point in the history
… CallResult handler
  • Loading branch information
rlabrecque committed Apr 5, 2017
1 parent 9e5e77e commit f510c7f
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions Plugins/Steamworks.NET/CallbackDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ private void OnRunCallback(
#endif
IntPtr pvParam) {
m_hAPICall = SteamAPICall_t.Invalid; // Caller unregisters for us

try {
m_Func((T)Marshal.PtrToStructure(pvParam, typeof(T)), false);
}
Expand All @@ -308,21 +309,17 @@ private void OnRunCallResult(
#if !STDCALL
IntPtr thisptr,
#endif
IntPtr pvParam, bool bFailed, ulong hSteamAPICall) {
SteamAPICall_t hAPICall = (SteamAPICall_t)hSteamAPICall;
if (hAPICall == m_hAPICall) {
IntPtr pvParam, bool bFailed, ulong hSteamAPICall_) {
SteamAPICall_t hSteamAPICall = (SteamAPICall_t)hSteamAPICall_;
if (hSteamAPICall == m_hAPICall) {
m_hAPICall = SteamAPICall_t.Invalid; // Caller unregisters for us

try {
m_Func((T)Marshal.PtrToStructure(pvParam, typeof(T)), bFailed);
}
catch (Exception e) {
CallbackDispatcher.ExceptionHandler(e);
}

// The official SDK sets m_hAPICall to invalid before calling the callresult function,
// this doesn't let us access .Handle from within the function though.
if (hAPICall == m_hAPICall) { // Ensure that m_hAPICall has not been changed in m_Func
m_hAPICall = SteamAPICall_t.Invalid; // Caller unregisters for us
}
}
}

Expand Down

0 comments on commit f510c7f

Please sign in to comment.