diff options
Diffstat (limited to 'core/io')
-rw-r--r-- | core/io/config_file.cpp | 2 | ||||
-rw-r--r-- | core/io/image_loader.cpp | 4 | ||||
-rw-r--r-- | core/io/ip.cpp | 2 | ||||
-rw-r--r-- | core/io/multiplayer_api.cpp | 17 | ||||
-rw-r--r-- | core/io/packet_peer.cpp | 33 | ||||
-rw-r--r-- | core/io/packet_peer.h | 6 | ||||
-rw-r--r-- | core/io/packet_peer_udp.cpp | 2 | ||||
-rw-r--r-- | core/io/pck_packer.cpp | 4 | ||||
-rw-r--r-- | core/io/resource_format_binary.cpp | 4 | ||||
-rw-r--r-- | core/io/resource_importer.cpp | 4 | ||||
-rw-r--r-- | core/io/resource_loader.cpp | 4 | ||||
-rw-r--r-- | core/io/xml_parser.cpp | 8 | ||||
-rw-r--r-- | core/io/zip_io.cpp | 1 |
13 files changed, 67 insertions, 24 deletions
diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp index 5c25cad770..99da512247 100644 --- a/core/io/config_file.cpp +++ b/core/io/config_file.cpp @@ -275,7 +275,7 @@ Error ConfigFile::_internal_load(const String &p_path, FileAccess *f) { memdelete(f); return OK; } else if (err != OK) { - ERR_PRINTS("ConfgFile::load - " + p_path + ":" + itos(lines) + " error: " + error_text + "."); + ERR_PRINT("ConfgFile::load - " + p_path + ":" + itos(lines) + " error: " + error_text + "."); memdelete(f); return err; } diff --git a/core/io/image_loader.cpp b/core/io/image_loader.cpp index 05929ee8ed..720f25f91b 100644 --- a/core/io/image_loader.cpp +++ b/core/io/image_loader.cpp @@ -53,7 +53,7 @@ Error ImageLoader::load_image(String p_file, Ref<Image> p_image, FileAccess *p_c Error err; f = FileAccess::open(p_file, FileAccess::READ, &err); if (!f) { - ERR_PRINTS("Error opening file '" + p_file + "'."); + ERR_PRINT("Error opening file '" + p_file + "'."); return err; } } @@ -66,7 +66,7 @@ Error ImageLoader::load_image(String p_file, Ref<Image> p_image, FileAccess *p_c continue; Error err = loader[i]->load_image(p_image, f, p_force_linear, p_scale); if (err != OK) { - ERR_PRINTS("Error loading image: " + p_file); + ERR_PRINT("Error loading image: " + p_file); } if (err != ERR_FILE_UNRECOGNIZED) { diff --git a/core/io/ip.cpp b/core/io/ip.cpp index ea791fb327..23f6ca25d0 100644 --- a/core/io/ip.cpp +++ b/core/io/ip.cpp @@ -184,7 +184,7 @@ IP_Address IP::get_resolve_item_address(ResolverID p_id) const { resolver->mutex->lock(); if (resolver->queue[p_id].status != IP::RESOLVER_STATUS_DONE) { - ERR_PRINTS("Resolve of '" + resolver->queue[p_id].hostname + "'' didn't complete yet."); + ERR_PRINT("Resolve of '" + resolver->queue[p_id].hostname + "'' didn't complete yet."); resolver->mutex->unlock(); return IP_Address(); } diff --git a/core/io/multiplayer_api.cpp b/core/io/multiplayer_api.cpp index 2708cb8c01..fbed460a4e 100644 --- a/core/io/multiplayer_api.cpp +++ b/core/io/multiplayer_api.cpp @@ -111,6 +111,7 @@ void MultiplayerAPI::poll() { Error err = network_peer->get_packet(&packet, len); if (err != OK) { ERR_PRINT("Error getting packet!"); + break; // Something is wrong! } rpc_sender_id = sender; @@ -252,7 +253,7 @@ Node *MultiplayerAPI::_process_get_node(int p_from, const uint8_t *p_packet, int node = root_node->get_node(np); if (!node) - ERR_PRINTS("Failed to get path from RPC: " + String(np) + "."); + ERR_PRINT("Failed to get path from RPC: " + String(np) + "."); } else { // Use cached path. int id = target; @@ -268,7 +269,7 @@ Node *MultiplayerAPI::_process_get_node(int p_from, const uint8_t *p_packet, int node = root_node->get_node(ni->path); if (!node) - ERR_PRINTS("Failed to get cached path from RPC: " + String(ni->path) + "."); + ERR_PRINT("Failed to get cached path from RPC: " + String(ni->path) + "."); } return node; } @@ -323,7 +324,7 @@ void MultiplayerAPI::_process_rpc(Node *p_node, const StringName &p_name, int p_ if (ce.error != Variant::CallError::CALL_OK) { String error = Variant::get_call_error_text(p_node, p_name, (const Variant **)argp.ptr(), argc, ce); error = "RPC - " + error; - ERR_PRINTS(error); + ERR_PRINT(error); } } @@ -361,7 +362,7 @@ void MultiplayerAPI::_process_rset(Node *p_node, const StringName &p_name, int p p_node->set(p_name, value, &valid); if (!valid) { String error = "Error setting remote property '" + String(p_name) + "', not found in object of type " + p_node->get_class() + "."; - ERR_PRINTS(error); + ERR_PRINT(error); } } @@ -682,7 +683,7 @@ void MultiplayerAPI::rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const if (ce.error != Variant::CallError::CALL_OK) { String error = Variant::get_call_error_text(p_node, p_method, p_arg, p_argcount, ce); error = "rpc() aborted in local call: - " + error + "."; - ERR_PRINTS(error); + ERR_PRINT(error); return; } } @@ -697,7 +698,7 @@ void MultiplayerAPI::rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const if (ce.error != Variant::CallError::CALL_OK) { String error = Variant::get_call_error_text(p_node, p_method, p_arg, p_argcount, ce); error = "rpc() aborted in script local call: - " + error + "."; - ERR_PRINTS(error); + ERR_PRINT(error); return; } } @@ -734,7 +735,7 @@ void MultiplayerAPI::rsetp(Node *p_node, int p_peer_id, bool p_unreliable, const if (!valid) { String error = "rset() aborted in local set, property not found: - " + String(p_property) + "."; - ERR_PRINTS(error); + ERR_PRINT(error); return; } } else if (p_node->get_script_instance()) { @@ -752,7 +753,7 @@ void MultiplayerAPI::rsetp(Node *p_node, int p_peer_id, bool p_unreliable, const if (!valid) { String error = "rset() aborted in local script set, property not found: - " + String(p_property) + "."; - ERR_PRINTS(error); + ERR_PRINT(error); return; } } diff --git a/core/io/packet_peer.cpp b/core/io/packet_peer.cpp index ae0520df6e..9e53d773ba 100644 --- a/core/io/packet_peer.cpp +++ b/core/io/packet_peer.cpp @@ -37,7 +37,8 @@ PacketPeer::PacketPeer() : last_get_error(OK), - allow_object_decoding(false) { + allow_object_decoding(false), + encode_buffer_max_size(8 * 1024 * 1024) { } void PacketPeer::set_allow_object_decoding(bool p_enable) { @@ -50,6 +51,19 @@ bool PacketPeer::is_object_decoding_allowed() const { return allow_object_decoding; } +void PacketPeer::set_encode_buffer_max_size(int p_max_size) { + + ERR_FAIL_COND_MSG(p_max_size < 1024, "Max encode buffer must be at least 1024 bytes"); + ERR_FAIL_COND_MSG(p_max_size > 256 * 1024 * 1024, "Max encode buffer cannot exceed 256 MiB"); + encode_buffer_max_size = next_power_of_2(p_max_size); + encode_buffer.resize(0); +} + +int PacketPeer::get_encode_buffer_max_size() const { + + return encode_buffer_max_size; +} + Error PacketPeer::get_packet_buffer(PoolVector<uint8_t> &r_buffer) { const uint8_t *buffer; @@ -100,12 +114,18 @@ Error PacketPeer::put_var(const Variant &p_packet, bool p_full_objects) { if (len == 0) return OK; - uint8_t *buf = (uint8_t *)alloca(len); - ERR_FAIL_COND_V_MSG(!buf, ERR_OUT_OF_MEMORY, "Out of memory."); - err = encode_variant(p_packet, buf, len, p_full_objects || allow_object_decoding); + ERR_FAIL_COND_V_MSG(len > encode_buffer_max_size, ERR_OUT_OF_MEMORY, "Failed to encode variant, encode size is bigger then encode_buffer_max_size. Consider raising it via 'set_encode_buffer_max_size'."); + + if (unlikely(encode_buffer.size() < len)) { + encode_buffer.resize(0); // Avoid realloc + encode_buffer.resize(next_power_of_2(len)); + } + + PoolVector<uint8_t>::Write w = encode_buffer.write(); + err = encode_variant(p_packet, w.ptr(), len, p_full_objects || allow_object_decoding); ERR_FAIL_COND_V_MSG(err != OK, err, "Error when trying to encode Variant."); - return put_packet(buf, len); + return put_packet(w.ptr(), len); } Variant PacketPeer::_bnd_get_var(bool p_allow_objects) { @@ -142,7 +162,10 @@ void PacketPeer::_bind_methods() { ClassDB::bind_method(D_METHOD("set_allow_object_decoding", "enable"), &PacketPeer::set_allow_object_decoding); ClassDB::bind_method(D_METHOD("is_object_decoding_allowed"), &PacketPeer::is_object_decoding_allowed); + ClassDB::bind_method(D_METHOD("get_encode_buffer_max_size"), &PacketPeer::get_encode_buffer_max_size); + ClassDB::bind_method(D_METHOD("set_encode_buffer_max_size", "max_size"), &PacketPeer::set_encode_buffer_max_size); + ADD_PROPERTY(PropertyInfo(Variant::INT, "encode_buffer_max_size"), "set_encode_buffer_max_size", "get_encode_buffer_max_size"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_object_decoding"), "set_allow_object_decoding", "is_object_decoding_allowed"); }; diff --git a/core/io/packet_peer.h b/core/io/packet_peer.h index f1870e8ef1..2b13f2e952 100644 --- a/core/io/packet_peer.h +++ b/core/io/packet_peer.h @@ -51,6 +51,9 @@ class PacketPeer : public Reference { bool allow_object_decoding; + int encode_buffer_max_size; + PoolVector<uint8_t> encode_buffer; + public: virtual int get_available_packet_count() const = 0; virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) = 0; ///< buffer is GONE after next get_packet @@ -69,6 +72,9 @@ public: void set_allow_object_decoding(bool p_enable); bool is_object_decoding_allowed() const; + void set_encode_buffer_max_size(int p_max_size); + int get_encode_buffer_max_size() const; + PacketPeer(); ~PacketPeer() {} }; diff --git a/core/io/packet_peer_udp.cpp b/core/io/packet_peer_udp.cpp index 5c98c4fcab..a8cfd741bb 100644 --- a/core/io/packet_peer_udp.cpp +++ b/core/io/packet_peer_udp.cpp @@ -222,7 +222,7 @@ Error PacketPeerUDP::_poll() { if (rb.space_left() < read + 24) { #ifdef TOOLS_ENABLED - WARN_PRINTS("Buffer full, dropping packets!"); + WARN_PRINT("Buffer full, dropping packets!"); #endif continue; } diff --git a/core/io/pck_packer.cpp b/core/io/pck_packer.cpp index 8bc73103e9..fb83f0ac90 100644 --- a/core/io/pck_packer.cpp +++ b/core/io/pck_packer.cpp @@ -63,6 +63,10 @@ void PCKPacker::_bind_methods() { Error PCKPacker::pck_start(const String &p_file, int p_alignment) { + if (file != NULL) { + memdelete(file); + } + file = FileAccess::open(p_file, FileAccess::WRITE); ERR_FAIL_COND_V_MSG(!file, ERR_CANT_CREATE, "Can't open file to write: " + String(p_file) + "."); diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index 272d5c1116..97dca98185 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -1113,7 +1113,7 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons memdelete(da); //use the old approach - WARN_PRINTS("This file is old, so it can't refactor dependencies, opening and resaving '" + p_path + "'."); + WARN_PRINT("This file is old, so it can't refactor dependencies, opening and resaving '" + p_path + "'."); Error err; f = FileAccess::open(p_path, FileAccess::READ, &err); @@ -1635,7 +1635,7 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant if (!p_main && (!bundle_resources) && res->get_path().length() && res->get_path().find("::") == -1) { if (res->get_path() == path) { - ERR_PRINTS("Circular reference to resource being saved found: '" + local_path + "' will be null next time it's loaded."); + ERR_PRINT("Circular reference to resource being saved found: '" + local_path + "' will be null next time it's loaded."); return; } int idx = external_resources.size(); diff --git a/core/io/resource_importer.cpp b/core/io/resource_importer.cpp index c2d90ed204..f147170ff7 100644 --- a/core/io/resource_importer.cpp +++ b/core/io/resource_importer.cpp @@ -74,7 +74,7 @@ Error ResourceFormatImporter::_get_path_and_type(const String &p_path, PathAndTy memdelete(f); return OK; } else if (err != OK) { - ERR_PRINTS("ResourceFormatImporter::load - " + p_path + ".import:" + itos(lines) + " error: " + error_text); + ERR_PRINT("ResourceFormatImporter::load - " + p_path + ".import:" + itos(lines) + " error: " + error_text); memdelete(f); return err; } @@ -279,7 +279,7 @@ void ResourceFormatImporter::get_internal_resource_path_list(const String &p_pat memdelete(f); return; } else if (err != OK) { - ERR_PRINTS("ResourceFormatImporter::get_internal_resource_path_list - " + p_path + ".import:" + itos(lines) + " error: " + error_text); + ERR_PRINT("ResourceFormatImporter::get_internal_resource_path_list - " + p_path + ".import:" + itos(lines) + " error: " + error_text); memdelete(f); return; } diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index 7471ab4241..0e1ada9475 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -815,7 +815,7 @@ String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_rem if (err == ERR_FILE_EOF) { break; } else if (err != OK) { - ERR_PRINTS("Parse error: " + p_path + ".remap:" + itos(lines) + " error: " + error_text + "."); + ERR_PRINT("Parse error: " + p_path + ".remap:" + itos(lines) + " error: " + error_text + "."); break; } @@ -1013,7 +1013,7 @@ void ResourceLoader::finalize() { #ifndef NO_THREADS const LoadingMapKey *K = NULL; while ((K = loading_map.next(K))) { - ERR_PRINTS("Exited while resource is being loaded: " + K->path); + ERR_PRINT("Exited while resource is being loaded: " + K->path); } loading_map.clear(); memdelete(loading_map_mutex); diff --git a/core/io/xml_parser.cpp b/core/io/xml_parser.cpp index 53e7da91a7..bd450dd84f 100644 --- a/core/io/xml_parser.cpp +++ b/core/io/xml_parser.cpp @@ -471,6 +471,10 @@ Error XMLParser::open_buffer(const Vector<uint8_t> &p_buffer) { ERR_FAIL_COND_V(p_buffer.size() == 0, ERR_INVALID_DATA); + if (data) { + memdelete_arr(data); + } + length = p_buffer.size(); data = memnew_arr(char, length + 1); copymem(data, p_buffer.ptr(), length); @@ -489,6 +493,10 @@ Error XMLParser::open(const String &p_path) { length = file->get_len(); ERR_FAIL_COND_V(length < 1, ERR_FILE_CORRUPT); + if (data) { + memdelete_arr(data); + } + data = memnew_arr(char, length + 1); file->get_buffer((uint8_t *)data, length); data[length] = 0; diff --git a/core/io/zip_io.cpp b/core/io/zip_io.cpp index 582b7c906b..40e902d874 100644 --- a/core/io/zip_io.cpp +++ b/core/io/zip_io.cpp @@ -97,6 +97,7 @@ int zipio_close(voidpf opaque, voidpf stream) { FileAccess *&f = *(FileAccess **)opaque; if (f) { f->close(); + memdelete(f); f = NULL; } return 0; |