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.

Error when running Example Network Discovery

See original GitHub issue

Hi,

Im getting this error on Server when Client is Searching for a Server, this on Both Apple M1 and Windows. port on NetworkManager: 7770 and local IP Port on ExampleNetworkDiscovery: 47777

Any ideas?

Invalid allocation label passed to UnsafeUtility::Free UnityEngine.StackTraceUtility:ExtractStackTrace () Unity.Netcode.FastBufferWriter:Dispose () (at Library/PackageCache/com.unity.netcode.gameobjects@1.2.0/Runtime/Serialization/FastBufferWriter.cs:125) NetworkDiscovery`2/<ReceiveBroadcastAsync>d__27<DiscoveryBroadcastData, DiscoveryResponseData>:MoveNext () (at Library/PackageCache/com.community.netcode.extensions@e9f53f86a0/Runtime/NetworkDiscovery/NetworkDiscovery.cs:224) UnityEngine.UnitySynchronizationContext:ExecuteTasks ()

Issue Analytics

  • State:open
  • Created 9 months ago
  • Reactions:3
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
jpvanoostencommented, Jul 14, 2023

The issue occurs because the FastBufferWriter uses Allocator.Temp for the memory allocation which very likely results in the memory handle becoming invalid at the end of the current frame (the backing memory for the FastBufferWriter is disposed before the FastBufferWriter using that memory is disposed). Since this is an async method, there is no guarantee the function will complete within 1 frame. If the SendAsync function doesn’t return immediately, then the error will occur.

To fix this, change Allocator.Temp to Allocator.Persistent when creating a FastBufferReader or FastBufferWriter inside of an async function. For example, this is what ReceiveBroadcastAsync should look like:

    async Task ReceiveBroadcastAsync()
    {
        UdpReceiveResult udpReceiveResult = await m_Client.ReceiveAsync();

        var segment = new ArraySegment<byte>(udpReceiveResult.Buffer, 0, udpReceiveResult.Buffer.Length);
        using var reader = new FastBufferReader(segment, Allocator.Persistent);

        try
        {
            if (ReadAndCheckHeader(reader, MessageType.BroadCast) == false)
            {
                return;
            }

            reader.ReadNetworkSerializable(out TBroadCast receivedBroadcast);

            if (ProcessBroadcast(udpReceiveResult.RemoteEndPoint, receivedBroadcast, out TResponse response))
            {
                using var writer = new FastBufferWriter(1024, Allocator.Persistent, 1024 * 64);
                WriteHeader(writer, MessageType.Response);

                writer.WriteNetworkSerializable(response);
                var data = writer.ToArray();

                await m_Client.SendAsync(data, data.Length, udpReceiveResult.RemoteEndPoint);
            }
        }
        catch (Exception e)
        {
            Debug.LogException(e);
        }
    }

The ReceiveResponseAsync method should also be updated accordingly.

2reactions
Kinggrasscommented, Feb 27, 2023

Unfortunatly the same 😦

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't turn on Network Discovery - Windows Client
Cause. This issue occurs for one of the following reasons: The dependency services for Network Discovery aren't running. The Windows firewall ...
Read more >
Network Discovery runs in a loop and resulted as error/stale
PROBLEM: Network discovery runs in a loop and later the status becomes STALE. IDENTIFICATION: Example: Sample discovery logs from <Traverse_Home>\topology\ ...
Read more >
6 Ways To Fix "Network Discovery Is Turned Off" In ...
How to fix “Network discovery is turned off” error · Restart the computer · Choose the right sharing mode · Start dependency services...
Read more >
Network Computers are not Showing Up in Windows 10/11
Go to Control Panel -> Network and Sharing Center -> Change advanced sharing settings (you can run the command: control.exe /name Microsoft.
Read more >
Unable to run network discovery on additional poller
Network discovery cannot be run on the Web Console when selecting the additional poller as the engine. The following error messages may be...
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