Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebRtcPeerConnection is failing half the time on C# #116

Closed
finepointcgi opened this issue Sep 17, 2023 · 5 comments · Fixed by godotengine/godot#84947
Closed

WebRtcPeerConnection is failing half the time on C# #116

finepointcgi opened this issue Sep 17, 2023 · 5 comments · Fixed by godotengine/godot#84947
Labels
dotnet An issue that only affect dotnet builds Upstream An issue that is due to Godot Engine and not (just) the plugin itself.

Comments

@finepointcgi
Copy link

Godot version

4.1

Plugin version

1.0.2

System information

Windows

Issue description

When creating my WebRtcPeerConnection this error occurs. It sometimes stops the connection its very spotty on if it actually stops the connection from happening. This does not occure on the GD script side of it.

the code im using is
in steps to reproduce

The error

E 0:00:09:0657 Godot.NativeInterop.NativeFuncs.generated.cs:115 @ void Godot.NativeInterop.NativeFuncs.godotsharp_internal_tie_native_managed_to_unmanaged(IntPtr , IntPtr , Godot.NativeInterop.godot_string_name& , Godot.NativeInterop.godot_bool ): Condition "_instance_bindings != nullptr" is true.
<C++ Source> core/object/object.cpp:1750 @ set_instance_binding()
Godot.NativeInterop.NativeFuncs.generated.cs:115 @ void Godot.NativeInterop.NativeFuncs.godotsharp_internal_tie_native_managed_to_unmanaged(IntPtr , IntPtr , Godot.NativeInterop.godot_string_name& , Godot.NativeInterop.godot_bool )
InteropUtils.cs:60 @ void Godot.NativeInterop.InteropUtils.TieManagedToUnmanaged(Godot.GodotObject , IntPtr , Godot.StringName , Boolean , System.Type , System.Type )
GodotObject.base.cs:40 @ void Godot.GodotObject._ConstructAndInitialize(IntPtr , Godot.StringName , System.Type , Boolean )
WebRtcPeerConnection.cs:105 @ Godot.WebRtcPeerConnection..ctor()
Client.cs:91 @ void Client.createPeer(Int32 )
Client.cs:67 @ void Client._Process(Double )
Node.cs:2087 @ Boolean Godot.Node.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name& , Godot.NativeInterop.NativeVariantPtrArgs , Godot.NativeInterop.godot_variant& )
Client_ScriptMethods.generated.cs:115 @ Boolean Client.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name& , Godot.NativeInterop.NativeVariantPtrArgs , Godot.NativeInterop.godot_variant& )
CSharpInstanceBridge.cs:24 @ Godot.NativeInterop.godot_bool Godot.Bridge.CSharpInstanceBridge.Call(IntPtr , Godot.NativeInterop.godot_string_name* , Godot.NativeInterop.godot_variant** , Int32 , Godot.NativeInterop.godot_variant_call_error* , Godot.NativeInterop.godot_variant* )

Steps to reproduce

I created the signaling server and the connection and it blows up
private void createPeer(int id){
if(id != peer.GetUniqueId()){
WebRtcPeerConnection connection = new WebRtcPeerConnection();

		Godot.Collections.Dictionary config = new Godot.Collections.Dictionary {
			["iceServers"] = new Godot.Collections.Array {
				new Godot.Collections.Dictionary {
				["urls"] = new Godot.Collections.Array {
						"stun:stun.l.google.com:19302"
					}
				}
			}
		};
		
		connection.Initialize(config);

		connection.SessionDescriptionCreated += (type, sdp) => offerCreated(type, sdp, id);
		connection.IceCandidateCreated += (media, index, name) => iceCandidateCreated(media, index, name, id);
		rtcPeer.AddPeer(connection, id);

		if(id < peer.GetUniqueId()){
			connection.CreateOffer();
		}
	}
}

Minimal reproduction project

The project is located on my github if you wish to test it
https://github.com/finepointcgi/WebRTC-With-Godot-Tutorial-cSharp/tree/developer-bug-report

@finepointcgi
Copy link
Author

It looks like im getting

Started Client on ws://204.48.28.159:8916
{"ID":213189880,"Type":0}
my id is: 213189880
{"ID":213189880,"Type":1}
{"ID":213189880,"Type":1}
{"Lobby":{"HostID":213189880,"Players":[{"Id":213189880,"Index":1,"Name":null,"Score":0}],"LobbyValue":"eb2be362-8f07-4}LobbyData
{"Lobby":{"HostID":213189880,"Players":[{"Id":213189880,"Index":1,"Name":null,"Score":0}],"LobbyValue":"eb2be362-8f07-4}LobbyData
Started Client on ws://204.48.28.159:8916
{"ID":49206036,"Type":0}
my id is: 49206036
{"ID":49206036,"Type":1}
2023-09-19 16:28:07.770 DEBUG [18892] [rtc::impl::Init::doInit@110] Global initialization
2023-09-19 16:28:07.774 DEBUG [17596] [rtc::impl::Certificate::Generate@213] Generating certificate (OpenSSL)
ERROR: Condition "_instance_bindings != null{p"tIrD"" :i2s1 3t1r8u9e8.8
0, " T yapte:" :s1e}t
_instance_bindin2023-09-19 16:28:07.778 DEBUG [11000] [rtc::impl::Init::doInit@110] Global initialization
g (core/object/object.cpp:1750)
2023-09-19 16:28:07.782 DEBUG [19600] [rtc::impl::Certificate::Generate@213] Generating certificate (OpenSSL)
ERROR: Condition "_instance_bindings != nullptr" is true.
   at: set_instance_binding (core/object/object.cpp:1750)
2023-09-19 16:28:07.789 DEBUG [19976] [rtc::impl::Certificate::Generate@213] Generating certificate (OpenSSL)
2023-09-19 16:28:07.789 INFO  [18892] [rtc::impl::PeerConnection::changeState@1148] Changed state to closed
2023-09-19 16:28:07.791 DEBUG [18892] [rtc::impl::IceTransport::IceTransport@49] Initializing ICE transport (libjuice)
2023-09-19 16:28:07.791 INFO  [18892] [rtc::impl::IceTransport::IceTransport@104] Using STUN server "stun.l.google.com:"2023-09-19 16:28:07.792 DEBUG [18892] [rtc::impl::PeerConnection::processLocalDescription@938] Adding application to lo"2023-09-19 16:28:07.792 INFO  [18892] [rtc::impl::PeerConnection::changeSignalingState@1179] Changed signaling state tor2023-09-19 16:28:07.793 INFO  [18892] [rtc::impl::PeerConnection::changeGatheringState@1166] Changed gathering state tos2023-09-19 16:28:07.793 INFO  [18892] [rtc::impl::IceTransport::LogCallback@354] juice: Changing state to gathering
2023-09-19 16:28:07.795 INFO  [18892] [rtc::impl::IceTransport::LogCallback@354] juice: Changing state to connecting
2023-09-19 16:28:07.796 INFO  [18892] [rtc::impl::PeerConnection::changeState@1148] Changed state to connecting
2023-09-19 16:28:07.796 INFO  [11000] [rtc::impl::PeerConnection::changeState@1148] Changed state to closed
2023-09-19 16:28:07.796 DEBUG [18008] [rtc::impl::Certificate::Generate@213] Generating certificate (OpenSSL)
{"ID":49206036,"Type":1}
{"Lobby":{"HostID":213189880,"Players":[{"Id":213189880,"Index":1,"Name":null,"Score":0},{"Id":49206036,"Index":2,"Name}LobbyData
2023-09-19 16:28:07.814 INFO  [14084] [rtc::impl::IceTransport::LogCallback@354] juice: Using STUN server stun.l.google2{"ID":49206036,"Type":1}
{"Lobby":{"HostID":213189880,"Players":[{"Id":213189880,"Index":1,"Name":null,"Score":0},{"Id":49206036,"Index":2,"Name}LobbyData
{"Lobby":{"HostID":213189880,"Players":[{"Id":213189880,"Index":1,"Name":null,"Score":0},{"Id":49206036,"Index":2,"Name}LobbyData
2023-09-19 16:28:07.877 INFO  [7584] [rtc::impl::IceTransport::LogCallback@354] juice: STUN server binding successful
2023-09-19 16:28:07.877 INFO  [7584] [rtc::impl::IceTransport::LogCallback@354] juice: Got STUN mapped address 47.25.16r2023-09-19 16:28:07.877 INFO  [7584] [rtc::impl::IceTransport::LogCallback@354] juice: Candidate gathering done
2023-09-19 16:28:07.878 INFO  [7584] [rtc::impl::PeerConnection::changeGatheringState@1166] Changed gathering state to e{"ID":49206036,"OrgID":213189880,"Data":"v=0\r\no=rtc 2303672837 0 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\na=group:BUNDLE 0}2023-09-19 16:28:08.265 DEBUG [11000] [rtc::impl::IceTransport::IceTransport@49] Initializing ICE transport (libjuice)
2023-09-19 16:28:08.265 INFO  [11000] [rtc::impl::IceTransport::IceTransport@104] Using STUN server "stun.l.google.com:"2023-09-19 16:28:08.266 INFO  [11000] [rtc::impl::PeerConnection::changeSignalingState@1179] Changed signaling state tor2023-09-19 16:28:08.266 DEBUG [11000] [rtc::impl::PeerConnection::processLocalDescription@833] Adding application to lo"2023-09-19 16:28:08.267 INFO  [11000] [rtc::impl::PeerConnection::changeSignalingState@1179] Changed signaling state toe2023-09-19 16:28:08.267 INFO  [11000] [rtc::impl::PeerConnection::changeGatheringState@1166] Changed gathering state tos2023-09-19 16:28:08.267 INFO  [11000] [rtc::impl::IceTransport::LogCallback@354] juice: Changing state to gathering
2023-09-19 16:28:08.270 INFO  [11000] [rtc::impl::IceTransport::LogCallback@354] juice: Changing state to connecting
2023-09-19 16:28:08.270 INFO  [11000] [rtc::impl::PeerConnection::changeState@1148] Changed state to connecting
2023-09-19 16:28:08.271 INFO  [9104] [rtc::impl::IceTransport::LogCallback@354] juice: Using STUN server stun.l.google.2{"ID":49206036,"OrgID":213189880,"Media":"0","index":0,"SdpName":"candidate:1 1 UDP 2122317823 192.168.56.1 62716 typ h}2023-09-19 16:28:08.284 INFO  [6876] [rtc::impl::IceTransport::LogCallback@354] juice: Changing state to connected
2023-09-19 16:28:08.285 DEBUG [6876] [rtc::impl::DtlsTransport::DtlsTransport@376] Initializing DTLS transport (OpenSSL)2023-09-19 16:28:08.286 DEBUG [6876] [rtc::impl::DtlsTransport::start@469] Starting DTLS recv thread
2023-09-19 16:28:08.286 INFO  [3204] [rtc::impl::IceTransport::LogCallback@354] juice: IP Differentiated Services are ns{"ID":49206036,"OrgID":213189880,"Media":"0","index":0,"SdpName":"candidate:2 1 UDP 2122317567 192.168.1.33 62716 typ h}{"ID":49206036,"OrgID":213189880,"Media":"0","index":0,"SdpName":"candidate:3 1 UDP 1686109695 47.25.168.83 62716 typ s}2023-09-19 16:28:08.339 INFO  [6876] [rtc::impl::IceTransport::LogCallback@354] juice: STUN server binding successful
2023-09-19 16:28:08.339 INFO  [6876] [rtc::impl::IceTransport::LogCallback@354] juice: Got STUN mapped address 47.25.16r2023-09-19 16:28:08.340 INFO  [6876] [rtc::impl::IceTransport::LogCallback@354] juice: Candidate gathering done
2023-09-19 16:28:08.340 INFO  [6876] [rtc::impl::PeerConnection::changeGatheringState@1166] Changed gathering state to e{"ID":213189880,"OrgID":49206036,"Data":"v=0\r\no=rtc 1364480411 0 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\na=group:BUNDLE 0}2023-09-19 16:28:08.713 INFO  [18892] [rtc::impl::PeerConnection::changeSignalingState@1179] Changed signaling state toe2023-09-19 16:28:08.713 INFO  [7584] [rtc::impl::IceTransport::LogCallback@354] juice: Changing state to connected
2023-09-19 16:28:08.714 DEBUG [7584] [rtc::impl::DtlsTransport::DtlsTransport@376] Initializing DTLS transport (OpenSSL){"ID":213189880,"O2023-09-19 16:28:08.715 DEBUG [7584] [rtc::impl::DtlsTransport::start@469] Starting DTLS recv thread
rgID"2023-09-19 16:28:08.716 INFO  [6876] [rtc::impl::IceTransport::LogCallback@354] juice: Changing state to completed
2023-09-19 16:28:08.716 INFO  [7584] [rtc::impl::IceTransport::LogCallback@354] juice: Changing state to completed
:49206036,"Media":"0","index":0,"SdpName":"candidate:1 1 UDP 2122317823 192.168.56.1 62718 typ host","Lobby":"eb2be362-}{"ID":213189880,"OrgID":49206036,"Media":"0","index":0,"SdpName":"candidate:2 1 UDP 2122317567 192.168.1.33 62718 typ h}{"ID":213189880,"OrgID":49206036,"Media":"0","index":0,"SdpName":"candidate:5 1 UDP 1686109183 47.25.168.83 62718 typ s}2023-09-19 16:28:09.287 INFO  [15052] [rtc::impl::IceTransport::LogCallback@354] juice: IP Differentiated Services are s2023-09-19 16:28:09.289 INFO  [15052] [rtc::impl::DtlsTransport::runRecvLoop@578] DTLS handshake finished
2023-09-19 16:28:09.289 INFO  [3204] [rtc::impl::DtlsTransport::runRecvLoop@578] DTLS handshake finished
2023-09-19 16:28:09.289 DEBUG [15052] [rtc::impl::SctpTransport::SctpTransport@174] Initializing SCTP transport
2023-09-19 16:28:09.290 DEBUG [3204] [rtc::impl::SctpTransport::SctpTransport@174] Initializing SCTP transport
2023-09-19 16:28:09.290 DEBUG [15052] [rtc::impl::SctpTransport::connect@355] SCTP connecting (local port=5000, remote )2023-09-19 16:28:09.291 DEBUG [3204] [rtc::impl::SctpTransport::connect@355] SCTP connecting (local port=5000, remote p)2023-09-19 16:28:09.291 DEBUG [17596] [rtc::impl::SctpTransport::processNotification@839] SCTP negotiated streams: inco42023-09-19 16:28:09.291 DEBUG [3104] [rtc::impl::SctpTransport::processNotification@839] SCTP negotiated streams: incom42023-09-19 16:28:09.292 INFO  [17596] [rtc::impl::SctpTransport::processNotification@844] SCTP connected
2023-09-19 16:28:09.292 INFO  [3104] [rtc::impl::SctpTransport::processNotification@844] SCTP connected
2023-09-19 16:28:09.293 INFO  [17596] [rtc::impl::PeerConnection::changeState@1148] Changed state to connected
2023-09-19 16:28:09.293 INFO  [3104] [rtc::impl::PeerConnection::changeState@1148] Changed state to connected
Peer Connected! 49206036
Peer Connected! 213189880

its very inconsistant some times it makes it though and throws an error but actually makes it though other times it just spins out and doesnt work.

@finepointcgi
Copy link
Author

finepointcgi commented Sep 19, 2023

Even if I just initalize it it fails

public override void _Ready()
	{
		WebRtcPeerConnection connection = new WebRtcPeerConnection();
	}
E 0:00:00:0785   Godot.NativeInterop.NativeFuncs.generated.cs:115 @ void Godot.NativeInterop.NativeFuncs.godotsharp_internal_tie_native_managed_to_unmanaged(IntPtr , IntPtr , Godot.NativeInterop.godot_string_name& , Godot.NativeInterop.godot_bool ): Condition "_instance_bindings != nullptr" is true.
  <C++ Source>   core/object/object.cpp:1750 @ set_instance_binding()
  <Stack Trace>  Godot.NativeInterop.NativeFuncs.generated.cs:115 @ void Godot.NativeInterop.NativeFuncs.godotsharp_internal_tie_native_managed_to_unmanaged(IntPtr , IntPtr , Godot.NativeInterop.godot_string_name& , Godot.NativeInterop.godot_bool )
                 InteropUtils.cs:60 @ void Godot.NativeInterop.InteropUtils.TieManagedToUnmanaged(Godot.GodotObject , IntPtr , Godot.StringName , Boolean , System.Type , System.Type )
                 GodotObject.base.cs:40 @ void Godot.GodotObject._ConstructAndInitialize(IntPtr , Godot.StringName , System.Type , Boolean )
                 WebRtcPeerConnection.cs:105 @ Godot.WebRtcPeerConnection..ctor()
                 Control.cs:9 @ void Control._Ready()
                 Node.cs:2093 @ Boolean Godot.Node.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name& , Godot.NativeInterop.NativeVariantPtrArgs , Godot.NativeInterop.godot_variant& )
                 CanvasItem.cs:1374 @ Boolean Godot.CanvasItem.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name& , Godot.NativeInterop.NativeVariantPtrArgs , Godot.NativeInterop.godot_variant& )
                 Control.cs:2827 @ Boolean Godot.Control.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name& , Godot.NativeInterop.NativeVariantPtrArgs , Godot.NativeInterop.godot_variant& )
                 Control_ScriptMethods.generated.cs:31 @ Boolean Control.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name& , Godot.NativeInterop.NativeVariantPtrArgs , Godot.NativeInterop.godot_variant& )
                 CSharpInstanceBridge.cs:24 @ Godot.NativeInterop.godot_bool Godot.Bridge.CSharpInstanceBridge.Call(IntPtr , Godot.NativeInterop.godot_string_name* , Godot.NativeInterop.godot_variant** , Int32 , Godot.NativeInterop.godot_variant_call_error* , Godot.NativeInterop.godot_variant* )

@SakulFlee
Copy link

Getting the same error (Condition "_instance_bindings != nullptr" is true.) on new WebRtcPeerConnection() 100% of the times.
Doesn't matter which Godot version or DotNet version I use.
Installing from AssetLib, GitHub ZIP or compiling from source doensn't change the outcome either.

The library seems to be correctly installed though as I can call it just fine from GDScript. Only on C# it fails.

@Faless
Copy link
Collaborator

Faless commented Nov 16, 2023

This might be fixed by godotengine/godot#84947 , can anyone confirm?

@SakulFlee
Copy link

This might be fixed by godotengine/godot#84947 , can anyone confirm?

Can confirm this works :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dotnet An issue that only affect dotnet builds Upstream An issue that is due to Godot Engine and not (just) the plugin itself.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants