From d7fcf557e990d76e1f77b703a4b4603c73ff96f6 Mon Sep 17 00:00:00 2001 From: Ben Lubar Date: Mon, 20 Jul 2026 08:13:47 -0500 Subject: [PATCH] Update uses of memnew to handle godot-cpp returning Ref<> instead of raw pointers. --- src/WebRTCLibDataChannel.cpp | 6 +++++- src/WebRTCLibDataChannel.hpp | 4 ++++ src/WebRTCLibPeerConnection.cpp | 5 +++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/WebRTCLibDataChannel.cpp b/src/WebRTCLibDataChannel.cpp index 5f21e73..e6035d6 100644 --- a/src/WebRTCLibDataChannel.cpp +++ b/src/WebRTCLibDataChannel.cpp @@ -48,7 +48,11 @@ using namespace godot; using namespace godot_webrtc; // DataChannel +#ifdef GDNATIVE_WEBRTC WebRTCLibDataChannel *WebRTCLibDataChannel::new_data_channel(std::shared_ptr p_channel, bool p_negotiated) { +#else +Ref WebRTCLibDataChannel::new_data_channel(std::shared_ptr p_channel, bool p_negotiated) { +#endif // Invalid channel result in NULL return ERR_FAIL_COND_V(!p_channel, nullptr); @@ -62,7 +66,7 @@ WebRTCLibDataChannel *WebRTCLibDataChannel::new_data_channel(std::shared_ptrset_script(script); WebRTCLibDataChannel *out = native->cast_to(native); #else - WebRTCLibDataChannel *out = memnew(WebRTCLibDataChannel); + Ref out = memnew(WebRTCLibDataChannel); #endif // Bind the library data channel to our object. out->bind_channel(p_channel, p_negotiated); diff --git a/src/WebRTCLibDataChannel.hpp b/src/WebRTCLibDataChannel.hpp index 0f55315..e567bbe 100644 --- a/src/WebRTCLibDataChannel.hpp +++ b/src/WebRTCLibDataChannel.hpp @@ -78,7 +78,11 @@ class WebRTCLibDataChannel : public godot::WebRTCDataChannelExtension { } public: +#ifdef GDNATIVE_WEBRTC static WebRTCLibDataChannel *new_data_channel(std::shared_ptr p_channel, bool p_negotiated); +#else + static godot::Ref new_data_channel(std::shared_ptr p_channel, bool p_negotiated); +#endif /* PacketPeer */ virtual godot::Error _get_packet(const uint8_t **r_buffer, int32_t *r_len) override; diff --git a/src/WebRTCLibPeerConnection.cpp b/src/WebRTCLibPeerConnection.cpp index 1f22fd5..9f60547 100644 --- a/src/WebRTCLibPeerConnection.cpp +++ b/src/WebRTCLibPeerConnection.cpp @@ -234,8 +234,13 @@ Ref WebRTCLibPeerConnection::_create_data_channel(const Strin std::shared_ptr ch = peer_connection->createDataChannel(p_channel.utf8().get_data(), config); ERR_FAIL_COND_V(ch == nullptr, nullptr); +#ifdef GDNATIVE_WEBRTC WebRTCLibDataChannel *wrapper = WebRTCLibDataChannel::new_data_channel(ch, ch->id().has_value()); ERR_FAIL_COND_V(wrapper == nullptr, nullptr); +#else + Ref wrapper = WebRTCLibDataChannel::new_data_channel(ch, ch->id().has_value()); + ERR_FAIL_COND_V(wrapper.is_null(), nullptr); +#endif return wrapper; } catch (const std::exception &e) { ERR_PRINT(e.what());