summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/enet/networked_multiplayer_enet.cpp86
-rw-r--r--modules/gdnative/gdnative/gdnative.cpp4
-rw-r--r--modules/gdnative/gdnative/variant.cpp2
-rw-r--r--modules/gdnative/gdnative_api.json7
-rw-r--r--modules/gdnative/include/gdnative/gdnative.h4
-rw-r--r--modules/gdscript/gdscript.cpp9
-rw-r--r--modules/gdscript/gdscript.h1
-rw-r--r--modules/gdscript/gdscript_function.cpp62
-rw-r--r--modules/gdscript/gdscript_function.h8
-rw-r--r--modules/gdscript/gdscript_functions.cpp4
-rw-r--r--modules/mono/csharp_script.cpp6
-rw-r--r--modules/mono/mono_gd/gd_mono_internals.cpp2
-rw-r--r--modules/visual_script/visual_script_editor.cpp4
-rw-r--r--modules/visual_script/visual_script_editor.h2
-rw-r--r--modules/websocket/emws_client.cpp22
-rw-r--r--modules/websocket/emws_peer.cpp15
16 files changed, 127 insertions, 111 deletions
diff --git a/modules/enet/networked_multiplayer_enet.cpp b/modules/enet/networked_multiplayer_enet.cpp
index 21dd758391..ca134824f7 100644
--- a/modules/enet/networked_multiplayer_enet.cpp
+++ b/modules/enet/networked_multiplayer_enet.cpp
@@ -49,7 +49,7 @@ void NetworkedMultiplayerENet::set_target_peer(int p_peer) {
int NetworkedMultiplayerENet::get_packet_peer() const {
- ERR_FAIL_COND_V(!active, 1);
+ ERR_FAIL_COND_V_MSG(!active, 1, "The multiplayer instance isn't currently active.");
ERR_FAIL_COND_V(incoming_packets.size() == 0, 1);
return incoming_packets.front()->get().from;
@@ -57,7 +57,7 @@ int NetworkedMultiplayerENet::get_packet_peer() const {
int NetworkedMultiplayerENet::get_packet_channel() const {
- ERR_FAIL_COND_V(!active, -1);
+ ERR_FAIL_COND_V_MSG(!active, -1, "The multiplayer instance isn't currently active.");
ERR_FAIL_COND_V(incoming_packets.size() == 0, -1);
return incoming_packets.front()->get().channel;
@@ -65,7 +65,7 @@ int NetworkedMultiplayerENet::get_packet_channel() const {
int NetworkedMultiplayerENet::get_last_packet_channel() const {
- ERR_FAIL_COND_V(!active, -1);
+ ERR_FAIL_COND_V_MSG(!active, -1, "The multiplayer instance isn't currently active.");
ERR_FAIL_COND_V(!current_packet.packet, -1);
return current_packet.channel;
@@ -73,11 +73,11 @@ int NetworkedMultiplayerENet::get_last_packet_channel() const {
Error NetworkedMultiplayerENet::create_server(int p_port, int p_max_clients, int p_in_bandwidth, int p_out_bandwidth) {
- ERR_FAIL_COND_V(active, ERR_ALREADY_IN_USE);
- ERR_FAIL_COND_V(p_port < 0 || p_port > 65535, ERR_INVALID_PARAMETER);
- ERR_FAIL_COND_V(p_max_clients < 1 || p_max_clients > 4095, ERR_INVALID_PARAMETER);
- ERR_FAIL_COND_V(p_in_bandwidth < 0, ERR_INVALID_PARAMETER);
- ERR_FAIL_COND_V(p_out_bandwidth < 0, ERR_INVALID_PARAMETER);
+ ERR_FAIL_COND_V_MSG(active, ERR_ALREADY_IN_USE, "The multiplayer instance is already active.");
+ ERR_FAIL_COND_V_MSG(p_port < 0 || p_port > 65535, ERR_INVALID_PARAMETER, "The port number must be set between 0 and 65535 (inclusive).");
+ ERR_FAIL_COND_V_MSG(p_max_clients < 1 || p_max_clients > 4095, ERR_INVALID_PARAMETER, "The number of clients must be set between 1 and 4095 (inclusive).");
+ ERR_FAIL_COND_V_MSG(p_in_bandwidth < 0, ERR_INVALID_PARAMETER, "The incoming bandwidth limit must be greater than or equal to 0 (0 disables the limit).");
+ ERR_FAIL_COND_V_MSG(p_out_bandwidth < 0, ERR_INVALID_PARAMETER, "The outgoing bandwidth limit must be greater than or equal to 0 (0 disables the limit).");
ENetAddress address;
memset(&address, 0, sizeof(address));
@@ -104,7 +104,7 @@ Error NetworkedMultiplayerENet::create_server(int p_port, int p_max_clients, int
p_in_bandwidth /* limit incoming bandwidth if > 0 */,
p_out_bandwidth /* limit outgoing bandwidth if > 0 */);
- ERR_FAIL_COND_V(!host, ERR_CANT_CREATE);
+ ERR_FAIL_COND_V_MSG(!host, ERR_CANT_CREATE, "Couldn't create an ENet multiplayer server.");
_setup_compressor();
active = true;
@@ -116,11 +116,11 @@ Error NetworkedMultiplayerENet::create_server(int p_port, int p_max_clients, int
}
Error NetworkedMultiplayerENet::create_client(const String &p_address, int p_port, int p_in_bandwidth, int p_out_bandwidth, int p_client_port) {
- ERR_FAIL_COND_V(active, ERR_ALREADY_IN_USE);
- ERR_FAIL_COND_V(p_port < 0 || p_port > 65535, ERR_INVALID_PARAMETER);
- ERR_FAIL_COND_V(p_client_port < 0 || p_client_port > 65535, ERR_INVALID_PARAMETER);
- ERR_FAIL_COND_V(p_in_bandwidth < 0, ERR_INVALID_PARAMETER);
- ERR_FAIL_COND_V(p_out_bandwidth < 0, ERR_INVALID_PARAMETER);
+ ERR_FAIL_COND_V_MSG(active, ERR_ALREADY_IN_USE, "The multiplayer instance is already active.");
+ ERR_FAIL_COND_V_MSG(p_port < 0 || p_port > 65535, ERR_INVALID_PARAMETER, "The server port number must be set between 0 and 65535 (inclusive).");
+ ERR_FAIL_COND_V_MSG(p_client_port < 0 || p_client_port > 65535, ERR_INVALID_PARAMETER, "The client port number must be set between 0 and 65535 (inclusive).");
+ ERR_FAIL_COND_V_MSG(p_in_bandwidth < 0, ERR_INVALID_PARAMETER, "The incoming bandwidth limit must be greater than or equal to 0 (0 disables the limit).");
+ ERR_FAIL_COND_V_MSG(p_out_bandwidth < 0, ERR_INVALID_PARAMETER, "The outgoing bandwidth limit must be greater than or equal to 0 (0 disables the limit).");
if (p_client_port != 0) {
ENetAddress c_client;
@@ -135,7 +135,7 @@ Error NetworkedMultiplayerENet::create_client(const String &p_address, int p_por
if (bind_ip.is_wildcard()) {
c_client.host = 0;
} else {
- ERR_FAIL_COND_V(!bind_ip.is_ipv4(), ERR_INVALID_PARAMETER);
+ ERR_FAIL_COND_V_MSG(!bind_ip.is_ipv4(), ERR_INVALID_PARAMETER, "Wildcard IP addresses are only permitted in IPv4, not IPv6.");
c_client.host = *(uint32_t *)bind_ip.get_ipv4();
}
#endif
@@ -155,7 +155,7 @@ Error NetworkedMultiplayerENet::create_client(const String &p_address, int p_por
p_out_bandwidth /* limit outgoing bandwidth if > 0 */);
}
- ERR_FAIL_COND_V(!host, ERR_CANT_CREATE);
+ ERR_FAIL_COND_V_MSG(!host, ERR_CANT_CREATE, "Couldn't create the ENet client host.");
_setup_compressor();
@@ -169,14 +169,14 @@ Error NetworkedMultiplayerENet::create_client(const String &p_address, int p_por
ip = IP::get_singleton()->resolve_hostname(p_address, IP::TYPE_IPV4);
#endif
- ERR_FAIL_COND_V(!ip.is_valid(), ERR_CANT_RESOLVE);
+ ERR_FAIL_COND_V_MSG(!ip.is_valid(), ERR_CANT_RESOLVE, "Couldn't resolve the server IP address or domain name.");
}
ENetAddress address;
#ifdef GODOT_ENET
enet_address_set_ip(&address, ip.get_ipv6(), 16);
#else
- ERR_FAIL_COND_V(!ip.is_ipv4(), ERR_INVALID_PARAMETER);
+ ERR_FAIL_COND_V_MSG(!ip.is_ipv4(), ERR_INVALID_PARAMETER, "Connecting to an IPv6 server isn't supported when using vanilla ENet. Recompile Godot with the bundled ENet library.");
address.host = *(uint32_t *)ip.get_ipv4();
#endif
address.port = p_port;
@@ -188,7 +188,7 @@ Error NetworkedMultiplayerENet::create_client(const String &p_address, int p_por
if (peer == NULL) {
enet_host_destroy(host);
- ERR_FAIL_COND_V(!peer, ERR_CANT_CREATE);
+ ERR_FAIL_COND_V_MSG(!peer, ERR_CANT_CREATE, "Couldn't connect to the ENet multiplayer server.");
}
// Technically safe to ignore the peer or anything else.
@@ -203,7 +203,7 @@ Error NetworkedMultiplayerENet::create_client(const String &p_address, int p_por
void NetworkedMultiplayerENet::poll() {
- ERR_FAIL_COND(!active);
+ ERR_FAIL_COND_MSG(!active, "The multiplayer instance isn't currently active.");
_pop_current_packet();
@@ -435,14 +435,14 @@ void NetworkedMultiplayerENet::poll() {
}
bool NetworkedMultiplayerENet::is_server() const {
- ERR_FAIL_COND_V(!active, false);
+ ERR_FAIL_COND_V_MSG(!active, false, "The multiplayer instance isn't currently active.");
return server;
}
void NetworkedMultiplayerENet::close_connection(uint32_t wait_usec) {
- ERR_FAIL_COND(!active);
+ ERR_FAIL_COND_MSG(!active, "The multiplayer instance isn't currently active.");
_pop_current_packet();
@@ -474,9 +474,9 @@ void NetworkedMultiplayerENet::close_connection(uint32_t wait_usec) {
void NetworkedMultiplayerENet::disconnect_peer(int p_peer, bool now) {
- ERR_FAIL_COND(!active);
- ERR_FAIL_COND(!is_server());
- ERR_FAIL_COND(!peer_map.has(p_peer));
+ ERR_FAIL_COND_MSG(!active, "The multiplayer instance isn't currently active.");
+ ERR_FAIL_COND_MSG(!is_server(), "Can't disconnect a peer when not acting as a server.");
+ ERR_FAIL_COND_MSG(!peer_map.has(p_peer), vformat("Peer ID %d not found in the list of peers.", p_peer));
if (now) {
int *id = (int *)peer_map[p_peer]->data;
@@ -515,7 +515,7 @@ int NetworkedMultiplayerENet::get_available_packet_count() const {
Error NetworkedMultiplayerENet::get_packet(const uint8_t **r_buffer, int &r_buffer_size) {
- ERR_FAIL_COND_V(incoming_packets.size() == 0, ERR_UNAVAILABLE);
+ ERR_FAIL_COND_V_MSG(incoming_packets.size() == 0, ERR_UNAVAILABLE, "No incoming packets available.");
_pop_current_packet();
@@ -530,8 +530,8 @@ Error NetworkedMultiplayerENet::get_packet(const uint8_t **r_buffer, int &r_buff
Error NetworkedMultiplayerENet::put_packet(const uint8_t *p_buffer, int p_buffer_size) {
- ERR_FAIL_COND_V(!active, ERR_UNCONFIGURED);
- ERR_FAIL_COND_V(connection_status != CONNECTION_CONNECTED, ERR_UNCONFIGURED);
+ ERR_FAIL_COND_V_MSG(!active, ERR_UNCONFIGURED, "The multiplayer instance isn't currently active.");
+ ERR_FAIL_COND_V_MSG(connection_status != CONNECTION_CONNECTED, ERR_UNCONFIGURED, "The multiplayer instance isn't currently connected to any server or client.");
int packet_flags = 0;
int channel = SYSCH_RELIABLE;
@@ -562,7 +562,7 @@ Error NetworkedMultiplayerENet::put_packet(const uint8_t *p_buffer, int p_buffer
if (target_peer != 0) {
E = peer_map.find(ABS(target_peer));
- ERR_FAIL_COND_V_MSG(!E, ERR_INVALID_PARAMETER, "Invalid target peer '" + itos(target_peer) + "'.");
+ ERR_FAIL_COND_V_MSG(!E, ERR_INVALID_PARAMETER, vformat("Invalid target peer: %d", target_peer));
}
ENetPacket *packet = enet_packet_create(NULL, p_buffer_size + 8, packet_flags);
@@ -650,7 +650,7 @@ uint32_t NetworkedMultiplayerENet::_gen_unique_id() const {
int NetworkedMultiplayerENet::get_unique_id() const {
- ERR_FAIL_COND_V(!active, 0);
+ ERR_FAIL_COND_V_MSG(!active, 0, "The multiplayer instance isn't currently active.");
return unique_id;
}
@@ -706,7 +706,7 @@ size_t NetworkedMultiplayerENet::enet_compress(void *context, const ENetBuffer *
mode = Compression::MODE_ZSTD;
} break;
default: {
- ERR_FAIL_V(0);
+ ERR_FAIL_V_MSG(0, vformat("Invalid ENet compression mode: %d", enet->compression_mode));
}
}
@@ -781,9 +781,9 @@ void NetworkedMultiplayerENet::enet_compressor_destroy(void *context) {
IP_Address NetworkedMultiplayerENet::get_peer_address(int p_peer_id) const {
- ERR_FAIL_COND_V(!peer_map.has(p_peer_id), IP_Address());
- ERR_FAIL_COND_V(!is_server() && p_peer_id != 1, IP_Address());
- ERR_FAIL_COND_V(peer_map[p_peer_id] == NULL, IP_Address());
+ ERR_FAIL_COND_V_MSG(!peer_map.has(p_peer_id), IP_Address(), vformat("Peer ID %d not found in the list of peers.", p_peer_id));
+ ERR_FAIL_COND_V_MSG(!is_server() && p_peer_id != 1, IP_Address(), "Can't get the address of peers other than the server (ID -1) when acting as a client.");
+ ERR_FAIL_COND_V_MSG(peer_map[p_peer_id] == NULL, IP_Address(), vformat("Peer ID %d found in the list of peers, but is null.", p_peer_id));
IP_Address out;
#ifdef GODOT_ENET
@@ -797,9 +797,9 @@ IP_Address NetworkedMultiplayerENet::get_peer_address(int p_peer_id) const {
int NetworkedMultiplayerENet::get_peer_port(int p_peer_id) const {
- ERR_FAIL_COND_V(!peer_map.has(p_peer_id), 0);
- ERR_FAIL_COND_V(!is_server() && p_peer_id != 1, 0);
- ERR_FAIL_COND_V(peer_map[p_peer_id] == NULL, 0);
+ ERR_FAIL_COND_V_MSG(!peer_map.has(p_peer_id), 0, vformat("Peer ID %d not found in the list of peers.", p_peer_id));
+ ERR_FAIL_COND_V_MSG(!is_server() && p_peer_id != 1, 0, "Can't get the address of peers other than the server (ID -1) when acting as a client.");
+ ERR_FAIL_COND_V_MSG(peer_map[p_peer_id] == NULL, 0, vformat("Peer ID %d found in the list of peers, but is null.", p_peer_id));
#ifdef GODOT_ENET
return peer_map[p_peer_id]->address.port;
#else
@@ -809,8 +809,8 @@ int NetworkedMultiplayerENet::get_peer_port(int p_peer_id) const {
void NetworkedMultiplayerENet::set_transfer_channel(int p_channel) {
- ERR_FAIL_COND(p_channel < -1 || p_channel >= channel_count);
- ERR_FAIL_COND_MSG(p_channel == SYSCH_CONFIG, "Channel " + itos(SYSCH_CONFIG) + " is reserved.");
+ ERR_FAIL_COND_MSG(p_channel < -1 || p_channel >= channel_count, vformat("The transfer channel must be set between 0 and %d, inclusive (got %d).", channel_count - 1, p_channel));
+ ERR_FAIL_COND_MSG(p_channel == SYSCH_CONFIG, vformat("The channel %d is reserved.", SYSCH_CONFIG));
transfer_channel = p_channel;
}
@@ -820,8 +820,8 @@ int NetworkedMultiplayerENet::get_transfer_channel() const {
void NetworkedMultiplayerENet::set_channel_count(int p_channel) {
- ERR_FAIL_COND(active);
- ERR_FAIL_COND(p_channel < SYSCH_MAX);
+ ERR_FAIL_COND_MSG(active, "The channel count can't be set while the multiplayer instance is active.");
+ ERR_FAIL_COND_MSG(p_channel < SYSCH_MAX, vformat("The channel count must be greater than or equal to %d to account for reserved channels (got %d).", SYSCH_MAX, p_channel));
channel_count = p_channel;
}
@@ -838,7 +838,7 @@ bool NetworkedMultiplayerENet::is_always_ordered() const {
}
void NetworkedMultiplayerENet::set_server_relay_enabled(bool p_enabled) {
- ERR_FAIL_COND(active);
+ ERR_FAIL_COND_MSG(active, "Server relaying can't be toggled while the multiplayer instance is active.");
server_relay = p_enabled;
}
@@ -916,7 +916,7 @@ NetworkedMultiplayerENet::~NetworkedMultiplayerENet() {
// Sets IP for ENet to bind when using create_server or create_client
// if no IP is set, then ENet bind to ENET_HOST_ANY
void NetworkedMultiplayerENet::set_bind_ip(const IP_Address &p_ip) {
- ERR_FAIL_COND(!p_ip.is_valid() && !p_ip.is_wildcard());
+ ERR_FAIL_COND_MSG(!p_ip.is_valid() && !p_ip.is_wildcard(), vformat("Invalid bind IP address: %s", String(p_ip)));
bind_ip = p_ip;
}
diff --git a/modules/gdnative/gdnative/gdnative.cpp b/modules/gdnative/gdnative/gdnative.cpp
index bb868d3b52..018a613724 100644
--- a/modules/gdnative/gdnative/gdnative.cpp
+++ b/modules/gdnative/gdnative/gdnative.cpp
@@ -166,10 +166,6 @@ void _gdnative_report_loading_error(const godot_object *p_library, const char *p
_err_print_error("gdnative_init", library->get_current_library_path().utf8().ptr(), 0, message.utf8().ptr());
}
-bool GDAPI godot_is_instance_valid(const godot_object *p_object) {
- return ObjectDB::instance_validate((Object *)p_object);
-}
-
godot_object GDAPI *godot_instance_from_id(godot_int p_instance_id) {
return (godot_object *)ObjectDB::get_instance(ObjectID(p_instance_id));
}
diff --git a/modules/gdnative/gdnative/variant.cpp b/modules/gdnative/gdnative/variant.cpp
index 11b6448e34..33b378d9cc 100644
--- a/modules/gdnative/gdnative/variant.cpp
+++ b/modules/gdnative/gdnative/variant.cpp
@@ -178,7 +178,7 @@ void GDAPI godot_variant_new_object(godot_variant *r_dest, const godot_object *p
ref = REF(reference);
}
if (!ref.is_null()) {
- memnew_placement_custom(dest, Variant, Variant(ref.get_ref_ptr()));
+ memnew_placement_custom(dest, Variant, Variant(ref));
} else {
#if defined(DEBUG_METHODS_ENABLED)
if (reference) {
diff --git a/modules/gdnative/gdnative_api.json b/modules/gdnative/gdnative_api.json
index 44e407218b..6004b07965 100644
--- a/modules/gdnative/gdnative_api.json
+++ b/modules/gdnative/gdnative_api.json
@@ -404,13 +404,6 @@
]
},
{
- "name": "godot_is_instance_valid",
- "return_type": "bool",
- "arguments": [
- ["const godot_object *", "p_object"]
- ]
- },
- {
"name": "godot_quat_new_with_basis",
"return_type": "void",
"arguments": [
diff --git a/modules/gdnative/include/gdnative/gdnative.h b/modules/gdnative/include/gdnative/gdnative.h
index 6fd0bdc87f..6fdca30122 100644
--- a/modules/gdnative/include/gdnative/gdnative.h
+++ b/modules/gdnative/include/gdnative/gdnative.h
@@ -282,9 +282,7 @@ void GDAPI godot_print_error(const char *p_description, const char *p_function,
void GDAPI godot_print_warning(const char *p_description, const char *p_function, const char *p_file, int p_line);
void GDAPI godot_print(const godot_string *p_message);
-// GDNATIVE CORE 1.0.1
-
-bool GDAPI godot_is_instance_valid(const godot_object *p_object);
+// GDNATIVE CORE 1.0.2?
//tags used for safe dynamic casting
void GDAPI *godot_get_class_tag(const godot_string_name *p_class);
diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp
index c71ec6ec76..07c74a2e26 100644
--- a/modules/gdscript/gdscript.cpp
+++ b/modules/gdscript/gdscript.cpp
@@ -93,6 +93,7 @@ GDScriptInstance *GDScript::_create_instance(const Variant **p_args, int p_argco
instance->members.resize(member_indices.size());
instance->script = Ref<GDScript>(this);
instance->owner = p_owner;
+ instance->owner_id = p_owner->get_instance_id();
#ifdef DEBUG_ENABLED
//needed for hot reloading
for (Map<StringName, MemberInfo>::Element *E = member_indices.front(); E; E = E->next()) {
@@ -1792,7 +1793,7 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_so
obj->get_script_instance()->get_property_state(state);
map[obj->get_instance_id()] = state;
- obj->set_script(RefPtr());
+ obj->set_script(Variant());
}
}
@@ -1808,7 +1809,7 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_so
map.insert(obj->get_instance_id(), List<Pair<StringName, Variant> >());
List<Pair<StringName, Variant> > &state = map[obj->get_instance_id()];
obj->get_script_instance()->get_property_state(state);
- obj->set_script(RefPtr());
+ obj->set_script(Variant());
} else {
// no instance found. Let's remove it so we don't loop forever
E->get()->placeholders.erase(E->get()->placeholders.front()->get());
@@ -1839,9 +1840,9 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_so
if (!p_soft_reload) {
//clear it just in case (may be a pending reload state)
- obj->set_script(RefPtr());
+ obj->set_script(Variant());
}
- obj->set_script(scr.get_ref_ptr());
+ obj->set_script(scr);
ScriptInstance *script_instance = obj->get_script_instance();
diff --git a/modules/gdscript/gdscript.h b/modules/gdscript/gdscript.h
index 4af574cd9d..3d24f9b3f5 100644
--- a/modules/gdscript/gdscript.h
+++ b/modules/gdscript/gdscript.h
@@ -241,6 +241,7 @@ class GDScriptInstance : public ScriptInstance {
friend class GDScriptFunctions;
friend class GDScriptCompiler;
+ ObjectID owner_id;
Object *owner;
Ref<GDScript> script;
#ifdef DEBUG_ENABLED
diff --git a/modules/gdscript/gdscript_function.cpp b/modules/gdscript/gdscript_function.cpp
index 7392bbc10a..cbf7d81a61 100644
--- a/modules/gdscript/gdscript_function.cpp
+++ b/modules/gdscript/gdscript_function.cpp
@@ -137,18 +137,19 @@ static String _get_var_type(const Variant *p_var) {
String basestr;
if (p_var->get_type() == Variant::OBJECT) {
- Object *bobj = *p_var;
+ bool was_freed;
+ Object *bobj = p_var->get_validated_object_with_check(was_freed);
if (!bobj) {
- basestr = "null instance";
- } else {
- if (ObjectDB::instance_validate(bobj)) {
- if (bobj->get_script_instance())
- basestr = bobj->get_class() + " (" + bobj->get_script_instance()->get_script()->get_path().get_file() + ")";
- else
- basestr = bobj->get_class();
+ if (was_freed) {
+ basestr = "null instance";
} else {
- basestr = "previously freed instance";
+ basestr = "previously freed";
}
+ } else {
+ if (bobj->get_script_instance())
+ basestr = bobj->get_class() + " (" + bobj->get_script_instance()->get_script()->get_path().get_file() + ")";
+ else
+ basestr = bobj->get_class();
}
} else {
@@ -497,14 +498,26 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
bool extends_ok = false;
if (a->get_type() == Variant::OBJECT && a->operator Object *() != NULL) {
- Object *obj_A = *a;
- Object *obj_B = *b;
#ifdef DEBUG_ENABLED
- if (!ObjectDB::instance_validate(obj_A)) {
- err_text = "Left operand of 'is' was already freed.";
+ bool was_freed;
+ Object *obj_A = a->get_validated_object_with_check(was_freed);
+
+ if (was_freed) {
+ err_text = "Left operand of 'is' is a previously freed instance.";
OPCODE_BREAK;
}
+
+ Object *obj_B = b->get_validated_object_with_check(was_freed);
+
+ if (was_freed) {
+ err_text = "Right operand of 'is' is a previously freed instance.";
+ OPCODE_BREAK;
+ }
+#else
+
+ Object *obj_A = *a;
+ Object *obj_B = *b;
#endif // DEBUG_ENABLED
GDScript *scr_B = Object::cast_to<GDScript>(obj_B);
@@ -1298,20 +1311,20 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
}
#endif
- Object *obj = argobj->operator Object *();
+#ifdef DEBUG_ENABLED
+ bool was_freed;
+ Object *obj = argobj->get_validated_object_with_check(was_freed);
String signal = argname->operator String();
-#ifdef DEBUG_ENABLED
+ if (was_freed) {
+ err_text = "First argument of yield() is a previously freed instance.";
+ OPCODE_BREAK;
+ }
+
if (!obj) {
err_text = "First argument of yield() is null.";
OPCODE_BREAK;
}
- if (ScriptDebugger::get_singleton()) {
- if (!ObjectDB::instance_validate(obj)) {
- err_text = "First argument of yield() is a previously freed instance.";
- OPCODE_BREAK;
- }
- }
if (signal.length() == 0) {
err_text = "Second argument of yield() is an empty string (for signal name).";
@@ -1324,6 +1337,9 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE_BREAK;
}
#else
+ Object *obj = argobj->operator Object *();
+ String signal = argname->operator String();
+
obj->connect(signal, gdfs.ptr(), "_signal_callback", varray(gdfs), Object::CONNECT_ONESHOT);
#endif
}
@@ -1565,14 +1581,14 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
//error
// function, file, line, error, explanation
String err_file;
- if (p_instance && ObjectDB::instance_validate(p_instance->owner) && p_instance->script->is_valid() && p_instance->script->path != "")
+ if (p_instance && ObjectDB::get_instance(p_instance->owner_id) != nullptr && p_instance->script->is_valid() && p_instance->script->path != "")
err_file = p_instance->script->path;
else if (script)
err_file = script->path;
if (err_file == "")
err_file = "<built-in>";
String err_func = name;
- if (p_instance && ObjectDB::instance_validate(p_instance->owner) && p_instance->script->is_valid() && p_instance->script->name != "")
+ if (p_instance && ObjectDB::get_instance(p_instance->owner_id) != nullptr && p_instance->script->is_valid() && p_instance->script->name != "")
err_func = p_instance->script->name + "." + err_func;
int err_line = line;
if (err_text == "") {
diff --git a/modules/gdscript/gdscript_function.h b/modules/gdscript/gdscript_function.h
index ad95ebc543..7b7bcbaac9 100644
--- a/modules/gdscript/gdscript_function.h
+++ b/modules/gdscript/gdscript_function.h
@@ -77,8 +77,8 @@ struct GDScriptDataType {
return false;
}
- Object *obj = p_variant.operator Object *();
- if (!obj || !ObjectDB::instance_validate(obj)) {
+ Object *obj = p_variant.get_validated_object();
+ if (!obj) {
return false;
}
@@ -100,8 +100,8 @@ struct GDScriptDataType {
return false;
}
- Object *obj = p_variant.operator Object *();
- if (!obj || !ObjectDB::instance_validate(obj)) {
+ Object *obj = p_variant.get_validated_object();
+ if (!obj) {
return false;
}
diff --git a/modules/gdscript/gdscript_functions.cpp b/modules/gdscript/gdscript_functions.cpp
index 1a5087eb4d..a46337d7dd 100644
--- a/modules/gdscript/gdscript_functions.cpp
+++ b/modules/gdscript/gdscript_functions.cpp
@@ -1441,8 +1441,8 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_
if (p_args[0]->get_type() != Variant::OBJECT) {
r_ret = false;
} else {
- Object *obj = *p_args[0];
- r_ret = ObjectDB::instance_validate(obj);
+ Object *obj = p_args[0]->get_validated_object();
+ r_ret = obj != nullptr;
}
} break;
diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp
index 43cdd19411..c722076fe2 100644
--- a/modules/mono/csharp_script.cpp
+++ b/modules/mono/csharp_script.cpp
@@ -854,7 +854,7 @@ void CSharpLanguage::reload_assemblies(bool p_soft_reload) {
while (script->instances.front()) {
Object *obj = script->instances.front()->get();
- obj->set_script(RefPtr()); // Remove script and existing script instances (placeholder are not removed before domain reload)
+ obj->set_script(REF()); // Remove script and existing script instances (placeholder are not removed before domain reload)
}
script->_clear();
@@ -877,7 +877,7 @@ void CSharpLanguage::reload_assemblies(bool p_soft_reload) {
// Use a placeholder for now to avoid losing the state when saving a scene
- obj->set_script(scr.get_ref_ptr());
+ obj->set_script(scr);
PlaceHolderScriptInstance *placeholder = scr->placeholder_instance_create(obj);
obj->set_script_instance(placeholder);
@@ -1003,7 +1003,7 @@ void CSharpLanguage::reload_assemblies(bool p_soft_reload) {
CRASH_COND(si != NULL);
#endif
// Re-create script instance
- obj->set_script(script.get_ref_ptr()); // will create the script instance as well
+ obj->set_script(script); // will create the script instance as well
}
}
diff --git a/modules/mono/mono_gd/gd_mono_internals.cpp b/modules/mono/mono_gd/gd_mono_internals.cpp
index 75aa77c7b0..74ffa90cb3 100644
--- a/modules/mono/mono_gd/gd_mono_internals.cpp
+++ b/modules/mono/mono_gd/gd_mono_internals.cpp
@@ -107,7 +107,7 @@ void tie_managed_to_unmanaged(MonoObject *managed, Object *unmanaged) {
ScriptInstance *si = CSharpInstance::create_for_managed_type(unmanaged, script.ptr(), gchandle);
- unmanaged->set_script_and_instance(script.get_ref_ptr(), si);
+ unmanaged->set_script_and_instance(script, si);
}
void unhandled_exception(MonoException *p_exc) {
diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp
index 18851e6ab6..9a1125c375 100644
--- a/modules/visual_script/visual_script_editor.cpp
+++ b/modules/visual_script/visual_script_editor.cpp
@@ -4963,7 +4963,7 @@ Ref<VisualScriptNode> _VisualScriptEditor::create_node_custom(const String &p_na
}
_VisualScriptEditor *_VisualScriptEditor::singleton = NULL;
-Map<String, RefPtr> _VisualScriptEditor::custom_nodes;
+Map<String, REF> _VisualScriptEditor::custom_nodes;
_VisualScriptEditor::_VisualScriptEditor() {
singleton = this;
@@ -4975,7 +4975,7 @@ _VisualScriptEditor::~_VisualScriptEditor() {
void _VisualScriptEditor::add_custom_node(const String &p_name, const String &p_category, const Ref<Script> &p_script) {
String node_name = "custom/" + p_category + "/" + p_name;
- custom_nodes.insert(node_name, p_script.get_ref_ptr());
+ custom_nodes.insert(node_name, p_script);
VisualScriptLanguage::singleton->add_register_func(node_name, &_VisualScriptEditor::create_node_custom);
emit_signal("custom_nodes_updated");
}
diff --git a/modules/visual_script/visual_script_editor.h b/modules/visual_script/visual_script_editor.h
index 40e9e1cc98..9f52d87b6a 100644
--- a/modules/visual_script/visual_script_editor.h
+++ b/modules/visual_script/visual_script_editor.h
@@ -341,7 +341,7 @@ protected:
static void _bind_methods();
static _VisualScriptEditor *singleton;
- static Map<String, RefPtr> custom_nodes;
+ static Map<String, REF> custom_nodes;
static Ref<VisualScriptNode> create_node_custom(const String &p_name);
public:
diff --git a/modules/websocket/emws_client.cpp b/modules/websocket/emws_client.cpp
index 7e68936fc3..e5680ce2e9 100644
--- a/modules/websocket/emws_client.cpp
+++ b/modules/websocket/emws_client.cpp
@@ -91,10 +91,14 @@ Error EMWSClient::connect_to_host(String p_host, String p_path, uint16_t p_port,
int peer_sock = EM_ASM_INT({
var proto_str = UTF8ToString($2);
var socket = null;
- if (proto_str) {
- socket = new WebSocket(UTF8ToString($1), proto_str.split(","));
- } else {
- socket = new WebSocket(UTF8ToString($1));
+ try {
+ if (proto_str) {
+ socket = new WebSocket(UTF8ToString($1), proto_str.split(","));
+ } else {
+ socket = new WebSocket(UTF8ToString($1));
+ }
+ } catch (e) {
+ return -1;
}
var c_ptr = Module.IDHandler.get($0);
socket.binaryType = "arraybuffer";
@@ -174,6 +178,8 @@ Error EMWSClient::connect_to_host(String p_host, String p_path, uint16_t p_port,
return Module.IDHandler.add(socket);
}, _js_id, str.utf8().get_data(), proto_string.utf8().get_data());
/* clang-format on */
+ if (peer_sock == -1)
+ return FAILED;
static_cast<Ref<EMWSPeer> >(_peer)->set_sock(peer_sock, _in_buf_size, _in_pkt_size);
@@ -190,11 +196,11 @@ Ref<WebSocketPeer> EMWSClient::get_peer(int p_peer_id) const {
NetworkedMultiplayerPeer::ConnectionStatus EMWSClient::get_connection_status() const {
- if (_peer->is_connected_to_host())
+ if (_peer->is_connected_to_host()) {
+ if (_is_connecting)
+ return CONNECTION_CONNECTING;
return CONNECTION_CONNECTED;
-
- if (_is_connecting)
- return CONNECTION_CONNECTING;
+ }
return CONNECTION_DISCONNECTED;
};
diff --git a/modules/websocket/emws_peer.cpp b/modules/websocket/emws_peer.cpp
index effed8e4d9..588f38cffd 100644
--- a/modules/websocket/emws_peer.cpp
+++ b/modules/websocket/emws_peer.cpp
@@ -68,12 +68,17 @@ Error EMWSPeer::put_packet(const uint8_t *p_buffer, int p_buffer_size) {
bytes_array[i] = getValue($1+i, 'i8');
}
- if ($3) {
- sock.send(bytes_array.buffer);
- } else {
- var string = new TextDecoder("utf-8").decode(bytes_array);
- sock.send(string);
+ try {
+ if ($3) {
+ sock.send(bytes_array.buffer);
+ } else {
+ var string = new TextDecoder("utf-8").decode(bytes_array);
+ sock.send(string);
+ }
+ } catch (e) {
+ return 1;
}
+ return 0;
}, peer_sock, p_buffer, p_buffer_size, is_bin);
/* clang-format on */