You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There's a Release method defined for SteamNetworkingMessage_t which will cause a crash if called.
The C# method passes the m_pfnRelease pointer as the parameter to the release function:
public void Release() {
NativeMethods.SteamAPI_SteamNetworkingMessage_t_Release(m_pfnRelease);
}
But the implementation of this function (at least, the one visible in the open-source version of the Steam library) seems to be expecting a pointer to the network message itself:
And the code in steamnetworkingtypes.h defines m_pfnRelease as a function pointer:
/// Function to used to decrement the internal reference count and, if
/// it's zero, release the message. You should not set this function pointer,
/// or need to access this directly! Use the Release() function instead!
void (*m_pfnRelease)( SteamNetworkingMessage_t *pMsg );
And the C++ version of Release is as follows, passing this into a call to m_pfnRelease:
inline void SteamNetworkingMessage_t::Release() { (*m_pfnRelease)( this ); }
The safe way to release a message appears to be to call SteamAPI_SteamNetworkingMessage_t_Release and pass the original IntPtr obtained from ReceiveMessagesOnPollGroup (and friends), or maybe to marshal the message's m_pfnRelease into a delegate and call it like the C++ version.
It seems like having Release as a method on the C# struct will never work, because the struct doesn't contain a pointer to itself that we can pass to SteamAPI_SteamNetworkingMessage_t_Release, and having unmarshalled the struct in the first place means an instance won't have the same address as the one Steam allocated.
The text was updated successfully, but these errors were encountered:
There's a
Release
method defined forSteamNetworkingMessage_t
which will cause a crash if called.The C# method passes the
m_pfnRelease
pointer as the parameter to the release function:But the implementation of this function (at least, the one visible in the open-source version of the Steam library) seems to be expecting a pointer to the network message itself:
And the code in
steamnetworkingtypes.h
definesm_pfnRelease
as a function pointer:And the C++ version of Release is as follows, passing
this
into a call tom_pfnRelease
:The safe way to release a message appears to be to call
SteamAPI_SteamNetworkingMessage_t_Release
and pass the original IntPtr obtained fromReceiveMessagesOnPollGroup
(and friends), or maybe to marshal the message'sm_pfnRelease
into a delegate and call it like the C++ version.It seems like having
Release
as a method on the C# struct will never work, because the struct doesn't contain a pointer to itself that we can pass toSteamAPI_SteamNetworkingMessage_t_Release
, and having unmarshalled the struct in the first place means an instance won't have the same address as the one Steam allocated.The text was updated successfully, but these errors were encountered: