question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Segfault on `SteamNetworkingMessage_t.Release()`

See original GitHub issue

Hi there,

I’m running the latest (giturl) install of Steamworks.NET and am sending and receiving messages just fine it seems.

However when I call the recommended Release method on a SteamNetworkingMessage_t, I get a segfault.

My code is here:

        try
        {
          SteamNetworkingMessage_t netMessage = Marshal.PtrToStructure<SteamNetworkingMessage_t>(receiveBuffers[0]);
          byte[] message = new byte[netMessage.m_cbSize];
          Marshal.Copy(netMessage.m_pData, message, 0, message.Length);


          payload = new ArraySegment<byte>(message);
          clientId = netMessage.m_identityPeer.GetSteamID64();

          Debug.Log($"PollEvent(); // message received at {receiveTime} from {clientId}");

          netMessage.Release(); // <----- Commenting this line prevents segfault
        }
        finally
        {
          Marshal.DestroyStructure<SteamNetworkingMessage_t>(receiveBuffers[0]);
        }

Any ideas? Happy to share more code if needed.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
AG4Wcommented, Jun 4, 2021

Hi there,

I’m running the latest (giturl) install of Steamworks.NET and am sending and receiving messages just fine it seems.

However when I call the recommended Release method on a SteamNetworkingMessage_t, I get a segfault.

My code is here:

        try
        {
          SteamNetworkingMessage_t netMessage = Marshal.PtrToStructure<SteamNetworkingMessage_t>(receiveBuffers[0]);
          byte[] message = new byte[netMessage.m_cbSize];
          Marshal.Copy(netMessage.m_pData, message, 0, message.Length);


          payload = new ArraySegment<byte>(message);
          clientId = netMessage.m_identityPeer.GetSteamID64();

          Debug.Log($"PollEvent(); // message received at {receiveTime} from {clientId}");

          netMessage.Release(); // <----- Commenting this line prevents segfault
        }
        finally
        {
          Marshal.DestroyStructure<SteamNetworkingMessage_t>(receiveBuffers[0]);
        }

Any ideas? Happy to share more code if needed.

You can wrangle NativeMethods in this way to expose the underlying method (internal to public) and call it through the API.

[DllImport(NativeLibraryName, EntryPoint = "SteamAPI_SteamNetworkingMessage_t_Release", CallingConvention = CallingConvention.Cdecl)]
public static extern void SteamAPI_SteamNetworkingMessage_t_Release(IntPtr self);

I use some extension methods to do it.

public static class MessageExtensions
{
    public static T To<T>(this IntPtr pointer) => Marshal.PtrToStructure<T>(pointer);
    public static void Read(this IntPtr pointer, NetworkBuffer buffer) => Marshal.Copy(Marshal.PtrToStructure<SteamNetworkingMessage_t>(pointer).m_pData, buffer.Payload, 0, buffer.Payload.Length);
    public static void Release(this IntPtr pointer) => NativeMethods.SteamAPI_SteamNetworkingMessage_t_Release(pointer);
}
0reactions
fghlcommented, Jun 6, 2021

@AG4W This worked as advertised, thanks for the help!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Segmentation fault occurs only under release configuration
For some odd reason, my application likes to break on me when I switch to release and run it outside of my debugger....
Read more >
Identify what's causing segmentation faults (segfaults)
A segmentation fault (aka segfault) is a common condition that causes ... calling memset() as shown below would cause a program to segfault:...
Read more >
rpc.mountd is segfaulting immediately on launch
Horrible-ish workaround: rm /etc/mtab; cat /proc/mounts > /etc/mtab. Caveat emptor: This may randomly break things that expect /etc/mtab to ...
Read more >
Segmentation fault
Segmentation faults are a common class of error in programs written in languages like C that provide low-level memory access and few to...
Read more >
lxrandr fails to launch and throws Segmentation fault
Troubleshooting. As an act of desperation I tried debugging with gdb however I did not manage to get anything useful from that:
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found