ValveSockets-CSharp
ValveSockets-CSharp copied to clipboard
Incorrect usage of `SteamNetworkingMessage_t::Release()`
https://github.com/nxrighthere/ValveSockets-CSharp/blob/abe9031a25b2f5d6d6e2530fbd908faade6eb896/ValveSockets.cs#L401-L408
Block above is an incorrect usage of SteamAPI_SteamNetworkingMessage_t_Release(self).
You have to pass the unmanaged pointer to the SteamNetworkingMessage_t, not the freeing function pointer m_pfnRelease.
What SteamNetworkingMessage_t::Release() on GameNetworkingSockets does:
inline void SteamNetworkingMessage_t::Release() { (*m_pfnRelease)( this ); }
It calls the m_pfnRelease function pointer to clean up itself with this pointer.
Unfortunately, you can't do the same thing on C# side, because you don't have an unmanaged pointer to self inside of NetworkingMessage.
Steamworks.NET solves this by providing the static method that receives IntPtr parameter.
/// You MUST call this when you're done with the object,
/// to free up memory, etc.
/// This is a Steamworks.NET extension.
public static void Release(IntPtr pointer) {
NativeMethods.SteamAPI_SteamNetworkingMessage_t_Release(pointer);
}