From 35959f9c5a314effc9a442931baccec2408b8ece Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Wed, 21 Oct 2015 16:52:43 -0300 Subject: [PATCH] -fixes to ring buffer (fixes network error) -fixes to invalid disabling of commands on scene tree dock --- core/io/marshalls.cpp | 5 ++++- core/io/packet_peer.cpp | 3 +-- core/ring_buffer.h | 8 ++++---- tools/editor/scene_tree_dock.cpp | 3 ++- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index 1e76e2b4b24..62ccd814899 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -36,7 +36,10 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int * const uint8_t * buf=p_buffer; int len=p_len; - ERR_FAIL_COND_V(len<4,ERR_INVALID_DATA); + if (len<4) { + + ERR_FAIL_COND_V(len<4,ERR_INVALID_DATA); + } uint32_t type=decode_uint32(buf); diff --git a/core/io/packet_peer.cpp b/core/io/packet_peer.cpp index 875cace3684..f6d526b512e 100644 --- a/core/io/packet_peer.cpp +++ b/core/io/packet_peer.cpp @@ -156,7 +156,6 @@ Error PacketPeerStream::_poll_buffer() const { Error err = peer->get_partial_data(&temp_buffer[0], ring_buffer.space_left(), read); if (err) return err; - if (read==0) return OK; @@ -202,7 +201,7 @@ Error PacketPeerStream::get_packet(const uint8_t **r_buffer,int &r_buffer_size) uint8_t lbuf[4]; ring_buffer.copy(lbuf,0,4); remaining-=4; - uint32_t len = decode_uint32(lbuf); + uint32_t len = decode_uint32(lbuf); ERR_FAIL_COND_V(remaining<(int)len,ERR_UNAVAILABLE); ring_buffer.read(lbuf,4); //get rid of first 4 bytes diff --git a/core/ring_buffer.h b/core/ring_buffer.h index de33de0c765..3cf9cf9064e 100644 --- a/core/ring_buffer.h +++ b/core/ring_buffer.h @@ -141,15 +141,15 @@ public: inline int space_left() { int left = read_pos - write_pos; if (left < 0) { - return size() + left; + return size() + left - 1; }; if (left == 0) { - return size(); + return size()-1; }; - return left; + return left -1; }; inline int data_left() { - return size() - space_left(); + return size() - space_left() - 1; }; inline int size() { diff --git a/tools/editor/scene_tree_dock.cpp b/tools/editor/scene_tree_dock.cpp index 510517de6f2..08aa68d792c 100644 --- a/tools/editor/scene_tree_dock.cpp +++ b/tools/editor/scene_tree_dock.cpp @@ -1088,7 +1088,8 @@ void SceneTreeDock::_delete_confirm() { void SceneTreeDock::_update_tool_buttons() { Node *sel = scene_tree->get_selected(); - bool disable = !sel || (sel!=edited_scene && sel->get_owner()!=edited_scene) || (edited_scene->get_scene_instance_state().is_valid() && edited_scene->get_scene_instance_state()->find_node_by_path(edited_scene->get_path_to(sel))>=0); + bool disable = !sel || (sel!=edited_scene && sel->get_owner()!=edited_scene); + disable = disable || (edited_scene->get_scene_inherited_state().is_valid() && edited_scene->get_scene_inherited_state()->find_node_by_path(edited_scene->get_path_to(sel))>=0); bool disable_root = disable || sel->get_parent()==scene_root; bool disable_edit = !sel;