-
-
Notifications
You must be signed in to change notification settings - Fork 377
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
SteamNetworkingMessage_t crashes on Release() / SteamNetworkingMessage_t usage #388
Comments
After looking at Facepunch library while trying to understand how they handled this scenario, it seems that they are actually passing a pointer to the SteamNetworkingMessage_t itself to the release function, and not the address of the release function to the release function (what?). Replacing NewMessage.Release(); with NativeMethods.SteamAPI_SteamNetworkingMessage_t_Release(PointerBuffer[i]); Helped me to stop crashes and now everything works as intended, which seems to me that either I don't fully understand how this library wants me to manage my memory/message buffer, or there is something wrong with the implementation. |
I think what we may want to be doing here is:
That's what they do over here: One thing we could possibly do relatively easy is have a constructor that takes an IntPtr, and handles this stuff like so:
We possibly want to make SteamNetworkingMessage_t IDisposable too? I haven't written "client" code using these myself yet, so let me know what you would like and we can make that happen. 👍 The ValveSockets-CSharp library does some clever performance stuff with pooling, and I'd like that to continue to be possible with Steamworks.NET as well. |
Thanks for the hint with that pooling mechanism, I already implemented something simular to Facepunch's approach with pooled pointer buffer on preallocated umashalled memory, but I will think what else there could be done. Talking about code conventions and stuff, I believe naming convention of the method should reflect that setter of the "data" needs to be mandatory, and is bound to the release mechanism of the message so that there would be no need to read documentation, so naming like it something along "SetMessagePtr" would make sense, considering that other methods are operating exactly on top of pointers. |
Would it be possible to expose On a tangent, from a usability/client-code perspective, a signature that delivers the messages instead of the |
@rlabrecque So, as you've correctly identified, the crash is the direct consequence of the fact that the wrong pointer is being passed to the native function. The fix might be as simple as just doing something like this in public void Release()
{
fixed (SteamNetworkingMessage_t* thisPtr = &this)
{
NativeMethods.SteamAPI_SteamNetworkingMessage_t_Release((IntPtr)thisPtr);
}
} However, it is not 100% bulletproof as the native side may be expecting the exact same pointer that it passed to you via, e. g.,
public class SteamNetworkingMessage_t
{
+ public static void ReleaseMessage(IntPtr pointerToMessage);
}
Going on a bit of a tangent here: the library seems to provide a managed wrapper over the Steam API, but it appears to be inconsistent it its design. In places, it exposes very low-level |
This only helps those using Can we settle on a way forward? I'm spending all of my time on this currently and am blocked. I'm happy to help but just need a direction. Are we adding the |
I am fully aware that there is an issue about this problem here, and I am fully aware that it regards the development of the library rather than the usage, which is what I need. After reading it multiple times I still can't understand exactly how am I supposed to clear messages, since
Release()
method still crashes Unity on version 14.0.0. My code looks like this:The text was updated successfully, but these errors were encountered: