Facepunch / Facepunch.Steamworks

Another fucking c# Steamworks implementation
MIT License
2.92k stars 350 forks source link

NetAddress NullReferenceException #532

Open snaulX opened 3 years ago

snaulX commented 3 years ago

I have a project on Unity using Facepunch.Steamworks. In Start method of server and client script I create NetAddress address use one of two cases (when I want to set the address differently, I comment on one part and uncomment the other):

IPHostEntry he = Dns.GetHostEntry(ip);
            foreach (IPAddress addr in he.AddressList)
            {
                if (addr.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                {
                    address = NetAddress.From(addr, port);
                    break;
                }
            }

or

address = NetAddress.LocalHost(port);

But when I trying to make server (server = SteamNetworkingSockets.CreateNormalSocket(address, this);) or client (client = SteamNetworkingSockets.ConnectNormal(address, this);) I get NullReferenceException. And when I trying to Debug.Log(address); Unity was crashing.
What can causes this issue and how to fix it?

DoogeJ commented 3 years ago

Same issue found here (I do not use Unity):

[S_API] SteamAPI_Init(): Loaded local 'steamclient.so' OK. CAppInfoCacheReadFromDiskThread took 0 milliseconds to initialize CApplicationManagerPopulateThread took 0 milliseconds to initialize (will have waited on CAppInfoCacheReadFromDiskThread) RecordSteamInterfaceCreation (PID 3538489): SteamGameServer013 / RecordSteamInterfaceCreation (PID 3538489): SteamUtils009 / Error: Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object. at Steamworks.SteamNetworkingSockets.CreateNormalSocket(NetAddress address, ISocketManager intrface)

Using Facepunch.Steamworks.Posix.dll with .NET 5.0.301 on Ubuntu 20.04.

The same code works well on Windows using Facepunch.Steamworks.Win64.dll.

Actual code: SocketManager manager = SteamNetworkingSockets.CreateNormalSocket(host, myServer);

host can be NetAddress.AnyIp(32680) but also NetAddress.From("my-server-ip", 32680);, it does not matter.

The same thing happens if I directly specify the IP address.

I tried splitting it up even more like this:

SocketManager manager = new SocketManager(); manager = SteamNetworkingSockets.CreateNormalSocket(host, myServer);

The error then happens in the line manager = SteamNetworkingSockets.CreateNormalSocket(host, myServer);.

@snaulX Did you make any progress?

Edit: I have noticed this also fails: SteamNetworkingUtils.DebugLevel = NetDebugOutput.Everything; with a NRE.

Edit2: I figured out that SteamServer.Init fails, but doesn't return any error. This is what is causing all the other issues. Edit3: Of course this is because of #543 🤦‍♂️

snaulX commented 3 years ago

I'm working on Windows so I have other reason for this issue. Also all other steam functions working good so it's not about #543