From 2a13c6529842f8df3a35606749dd6612a9508901 Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 19 Aug 2022 02:52:31 +0200 Subject: [PATCH] Ported: Visual/Physics/Navigation Servers validate RIDs with documentation update - tinmanjuggernaut https://github.com/godotengine/godot/commit/2be073830414fe657a00410ce3c1740b1e5964d6 --- modules/navigation/pandemonium_navigation_server.cpp | 7 ++++++- servers/physics/physics_server_sw.cpp | 9 +++++++-- servers/physics_2d/physics_2d_server_sw.cpp | 9 +++++++-- servers/visual/visual_server_raster.cpp | 11 +++++++++-- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/modules/navigation/pandemonium_navigation_server.cpp b/modules/navigation/pandemonium_navigation_server.cpp index 7a73f798d..8ee7d9090 100644 --- a/modules/navigation/pandemonium_navigation_server.cpp +++ b/modules/navigation/pandemonium_navigation_server.cpp @@ -566,6 +566,11 @@ COMMAND_4(agent_set_callback, RID, p_agent, Object *, p_receiver, StringName, p_ } COMMAND_1(free, RID, p_object) { + if (!p_object.is_valid()) { + ERR_FAIL_MSG("Invalid RID."); + return; + } + if (map_owner.owns(p_object)) { NavMap *map = map_owner.getornull(p_object); @@ -614,7 +619,7 @@ COMMAND_1(free, RID, p_object) { memdelete(agent); } else { - ERR_FAIL_COND("Invalid ID."); + ERR_FAIL_COND("Invalid RID."); } } diff --git a/servers/physics/physics_server_sw.cpp b/servers/physics/physics_server_sw.cpp index 424e2aa06..1a2486faf 100644 --- a/servers/physics/physics_server_sw.cpp +++ b/servers/physics/physics_server_sw.cpp @@ -33,9 +33,9 @@ #include "broad_phase_basic.h" #include "broad_phase_bvh.h" #include "broad_phase_octree.h" -#include "core/os/os.h" #include "core/config/project_settings.h" #include "core/object/script_language.h" +#include "core/os/os.h" #include "joints/cone_twist_joint_sw.h" #include "joints/generic_6dof_joint_sw.h" #include "joints/hinge_joint_sw.h" @@ -1199,6 +1199,11 @@ bool PhysicsServerSW::generic_6dof_joint_get_flag(RID p_joint, Vector3::Axis p_a } void PhysicsServerSW::free(RID p_rid) { + if (!p_rid.is_valid()) { + ERR_FAIL_MSG("Invalid RID."); + return; + } + _update_shapes(); //just in case if (shape_owner.owns(p_rid)) { @@ -1271,7 +1276,7 @@ void PhysicsServerSW::free(RID p_rid) { memdelete(joint); } else { - ERR_FAIL_MSG("Invalid ID."); + ERR_FAIL_MSG("Invalid RID."); } }; diff --git a/servers/physics_2d/physics_2d_server_sw.cpp b/servers/physics_2d/physics_2d_server_sw.cpp index 44d5c0a9b..872c3a2b2 100644 --- a/servers/physics_2d/physics_2d_server_sw.cpp +++ b/servers/physics_2d/physics_2d_server_sw.cpp @@ -33,9 +33,9 @@ #include "broad_phase_2d_bvh.h" #include "broad_phase_2d_hash_grid.h" #include "collision_solver_2d_sw.h" -#include "core/os/os.h" #include "core/config/project_settings.h" #include "core/object/script_language.h" +#include "core/os/os.h" #define FLUSH_QUERY_CHECK(m_object) \ ERR_FAIL_COND_MSG(m_object->get_space() && flushing_queries, "Can't change this state while flushing queries. Use call_deferred() or set_deferred() to change monitoring state instead."); @@ -1121,6 +1121,11 @@ Physics2DServer::JointType Physics2DServerSW::joint_get_type(RID p_joint) const } void Physics2DServerSW::free(RID p_rid) { + if (!p_rid.is_valid()) { + ERR_FAIL_MSG("Invalid RID."); + return; + } + _update_shapes(); // just in case if (shape_owner.owns(p_rid)) { @@ -1188,7 +1193,7 @@ void Physics2DServerSW::free(RID p_rid) { memdelete(joint); } else { - ERR_FAIL_MSG("Invalid ID."); + ERR_FAIL_MSG("Invalid RID."); } }; diff --git a/servers/visual/visual_server_raster.cpp b/servers/visual/visual_server_raster.cpp index 8a5e52290..ca06fcd73 100644 --- a/servers/visual/visual_server_raster.cpp +++ b/servers/visual/visual_server_raster.cpp @@ -30,10 +30,10 @@ #include "visual_server_raster.h" -#include "core/io/marshalls.h" -#include "core/os/os.h" #include "core/config/project_settings.h" #include "core/containers/sort_array.h" +#include "core/io/marshalls.h" +#include "core/os/os.h" #include "visual_server_canvas.h" #include "visual_server_globals.h" #include "visual_server_scene.h" @@ -65,6 +65,11 @@ void VisualServerRaster::_draw_margins() { /* FREE */ void VisualServerRaster::free(RID p_rid) { + if (!p_rid.is_valid()) { + ERR_FAIL_MSG("Invalid RID."); + return; + } + if (VSG::storage->free(p_rid)) { return; } @@ -80,6 +85,8 @@ void VisualServerRaster::free(RID p_rid) { if (VSG::scene_render->free(p_rid)) { return; } + + ERR_FAIL_MSG("Invalid RID."); } /* EVENT QUEUING */