From 925b690c989dea13d0dfc06d2a7b1edc8de6b34f Mon Sep 17 00:00:00 2001 From: Thaddeus Crews Date: Sun, 9 Jun 2024 15:21:41 -0500 Subject: [PATCH] Core: Integrate `Ref::instantiate` where possible --- core/io/tcp_server.cpp | 2 +- editor/editor_help_search.cpp | 4 ++-- editor/editor_node.cpp | 2 +- editor/editor_settings.cpp | 2 +- editor/export/codesign.cpp | 8 ++++---- editor/import/3d/editor_import_collada.cpp | 2 +- editor/import/3d/resource_importer_scene.cpp | 2 +- .../animation_blend_tree_editor_plugin.cpp | 2 +- editor/plugins/canvas_item_editor_plugin.cpp | 2 +- editor/plugins/gizmos/marker_3d_gizmo_plugin.cpp | 2 +- .../plugins/light_occluder_2d_editor_plugin.cpp | 4 ++-- .../navigation_obstacle_3d_editor_plugin.cpp | 4 ++-- .../plugins/navigation_polygon_editor_plugin.cpp | 4 ++-- editor/plugins/node_3d_editor_plugin.cpp | 16 ++++++++-------- editor/plugins/path_3d_editor_plugin.cpp | 2 +- editor/plugins/polygon_3d_editor_plugin.cpp | 4 ++-- editor/plugins/skeleton_3d_editor_plugin.cpp | 4 ++-- modules/enet/enet_connection.cpp | 2 +- modules/gltf/gltf_document.cpp | 4 ++-- modules/gridmap/grid_map.cpp | 8 ++++---- modules/mono/csharp_script.cpp | 2 +- modules/multiplayer/scene_multiplayer.cpp | 6 +++--- .../openxr_composition_layer_extension.cpp | 2 +- modules/theora/video_stream_theora.cpp | 2 +- platform/ios/export/export_plugin.cpp | 2 +- scene/2d/touch_screen_button.cpp | 2 +- scene/3d/label_3d.cpp | 2 +- scene/3d/navigation_agent_3d.cpp | 4 ++-- scene/3d/navigation_link_3d.cpp | 4 ++-- scene/3d/navigation_obstacle_3d.cpp | 8 ++++---- scene/3d/navigation_region_3d.cpp | 8 ++++---- scene/3d/path_3d.cpp | 4 ++-- scene/3d/physics/ray_cast_3d.cpp | 2 +- scene/3d/physics/shape_cast_3d.cpp | 2 +- scene/3d/sprite_3d.cpp | 2 +- scene/gui/graph_edit.cpp | 2 +- scene/main/scene_tree.cpp | 2 +- scene/main/viewport.cpp | 8 ++++---- scene/resources/3d/shape_3d.cpp | 2 +- scene/resources/mesh.cpp | 2 +- scene/resources/navigation_mesh.cpp | 4 ++-- scene/resources/packed_scene.cpp | 4 ++-- scene/resources/portable_compressed_texture.cpp | 4 ++-- tests/scene/test_viewport.h | 2 +- 44 files changed, 81 insertions(+), 81 deletions(-) diff --git a/core/io/tcp_server.cpp b/core/io/tcp_server.cpp index f2b3d5e56a7..d69d1f1b290 100644 --- a/core/io/tcp_server.cpp +++ b/core/io/tcp_server.cpp @@ -112,7 +112,7 @@ Ref TCPServer::take_connection() { return conn; } - conn = Ref(memnew(StreamPeerTCP)); + conn.instantiate(); conn->accept_socket(ns, ip, port); return conn; } diff --git a/editor/editor_help_search.cpp b/editor/editor_help_search.cpp index d11bf7720cf..b0c06475f81 100644 --- a/editor/editor_help_search.cpp +++ b/editor/editor_help_search.cpp @@ -151,7 +151,7 @@ void EditorHelpSearch::_update_results() { search_flags |= SEARCH_SHOW_HIERARCHY; } - search = Ref(memnew(Runner(results_tree, results_tree, &tree_cache, term, search_flags))); + search.instantiate(results_tree, results_tree, &tree_cache, term, search_flags); // Clear old search flags to force rebuild on short term. old_search_flags = 0; @@ -162,7 +162,7 @@ void EditorHelpSearch::_update_results() { hierarchy_button->set_disabled(true); // Always show hierarchy for short searches. - search = Ref(memnew(Runner(results_tree, results_tree, &tree_cache, term, search_flags | SEARCH_SHOW_HIERARCHY))); + search.instantiate(results_tree, results_tree, &tree_cache, term, search_flags | SEARCH_SHOW_HIERARCHY); old_search_flags = search_flags; set_process(true); diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 36b43b7e9b7..f8e23ecc9d8 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -2153,7 +2153,7 @@ void EditorNode::_dialog_action(String p_file) { } if (ml.is_null()) { - ml = Ref(memnew(MeshLibrary)); + ml.instantiate(); } MeshLibraryEditor::update_library_file(editor_data.get_edited_scene_root(), ml, merge_with_existing_library, apply_mesh_instance_transforms); diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index eeb8ceb1ed6..9d29e8e0351 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -1229,7 +1229,7 @@ fail: extra_config->set_value("init_projects", "list", list); } - singleton = Ref(memnew(EditorSettings)); + singleton.instantiate(); singleton->set_path(config_file_path, true); singleton->save_changed_setting = true; singleton->_load_defaults(extra_config); diff --git a/editor/export/codesign.cpp b/editor/export/codesign.cpp index 72d496b04d1..cc53068d481 100644 --- a/editor/export/codesign.cpp +++ b/editor/export/codesign.cpp @@ -1381,14 +1381,14 @@ Error CodeSign::_codesign_file(bool p_use_hardened_runtime, bool p_force, const r_error_msg = TTR("Invalid entitlements file."); ERR_FAIL_V_MSG(FAILED, "CodeSign: Invalid entitlements file."); } - cet = Ref(memnew(CodeSignEntitlementsText(entitlements))); - ceb = Ref(memnew(CodeSignEntitlementsBinary(entitlements))); + cet.instantiate(entitlements); + ceb.instantiate(entitlements); } print_verbose("CodeSign: Generating requirements..."); Ref rq; String team_id = ""; - rq = Ref(memnew(CodeSignRequirements())); + rq.instantiate(); // Sign executables. for (int i = 0; i < files_to_sign.size(); i++) { @@ -1487,7 +1487,7 @@ Error CodeSign::_codesign_file(bool p_use_hardened_runtime, bool p_force, const print_verbose("CodeSign: Generating signature..."); Ref cs; - cs = Ref(memnew(CodeSignSignature())); + cs.instantiate(); print_verbose("CodeSign: Writing signature superblob..."); // Write signature data to the executable. diff --git a/editor/import/3d/editor_import_collada.cpp b/editor/import/3d/editor_import_collada.cpp index 04a3f231545..c04278fc55c 100644 --- a/editor/import/3d/editor_import_collada.cpp +++ b/editor/import/3d/editor_import_collada.cpp @@ -1263,7 +1263,7 @@ Error ColladaImport::_create_resources(Collada::Node *p_node, bool p_use_compres //bleh, must ignore invalid ERR_FAIL_COND_V(!collada.state.mesh_data_map.has(meshid), ERR_INVALID_DATA); - mesh = Ref(memnew(ImporterMesh)); + mesh.instantiate(); const Collada::MeshData &meshdata = collada.state.mesh_data_map[meshid]; String name = meshdata.name; if (name.is_empty()) { diff --git a/editor/import/3d/resource_importer_scene.cpp b/editor/import/3d/resource_importer_scene.cpp index edf7aa66f00..50082e45bf6 100644 --- a/editor/import/3d/resource_importer_scene.cpp +++ b/editor/import/3d/resource_importer_scene.cpp @@ -3092,7 +3092,7 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p if (!scr.is_valid()) { EditorNode::add_io_error(TTR("Couldn't load post-import script:") + " " + post_import_script_path); } else { - post_import_script = Ref(memnew(EditorScenePostImport)); + post_import_script.instantiate(); post_import_script->set_script(scr); if (!post_import_script->get_script_instance()) { EditorNode::add_io_error(TTR("Invalid/broken script for post-import (check console):") + " " + post_import_script_path); diff --git a/editor/plugins/animation_blend_tree_editor_plugin.cpp b/editor/plugins/animation_blend_tree_editor_plugin.cpp index 34c0040cb7f..eef890d0138 100644 --- a/editor/plugins/animation_blend_tree_editor_plugin.cpp +++ b/editor/plugins/animation_blend_tree_editor_plugin.cpp @@ -1265,7 +1265,7 @@ AnimationNodeBlendTreeEditor::AnimationNodeBlendTreeEditor() { open_file->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE); open_file->connect("file_selected", callable_mp(this, &AnimationNodeBlendTreeEditor::_file_opened)); - animation_node_inspector_plugin = Ref(memnew(EditorInspectorPluginAnimationNodeAnimation)); + animation_node_inspector_plugin.instantiate(); EditorInspector::add_inspector_plugin(animation_node_inspector_plugin); } diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index e3cf3dbbf21..62793fbcb59 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -5620,7 +5620,7 @@ CanvasItemEditor::CanvasItemEditor() { snap_dialog->connect(SceneStringName(confirmed), callable_mp(this, &CanvasItemEditor::_snap_changed)); add_child(snap_dialog); - select_sb = Ref(memnew(StyleBoxTexture)); + select_sb.instantiate(); selection_menu = memnew(PopupMenu); add_child(selection_menu); diff --git a/editor/plugins/gizmos/marker_3d_gizmo_plugin.cpp b/editor/plugins/gizmos/marker_3d_gizmo_plugin.cpp index 39ae020d53a..5a6527f876a 100644 --- a/editor/plugins/gizmos/marker_3d_gizmo_plugin.cpp +++ b/editor/plugins/gizmos/marker_3d_gizmo_plugin.cpp @@ -36,7 +36,7 @@ #include "scene/3d/marker_3d.h" Marker3DGizmoPlugin::Marker3DGizmoPlugin() { - pos3d_mesh = Ref(memnew(ArrayMesh)); + pos3d_mesh.instantiate(); Vector cursor_points; Vector cursor_colors; diff --git a/editor/plugins/light_occluder_2d_editor_plugin.cpp b/editor/plugins/light_occluder_2d_editor_plugin.cpp index 429add45400..e3b59f9bfbc 100644 --- a/editor/plugins/light_occluder_2d_editor_plugin.cpp +++ b/editor/plugins/light_occluder_2d_editor_plugin.cpp @@ -35,8 +35,8 @@ Ref LightOccluder2DEditor::_ensure_occluder() const { Ref occluder = node->get_occluder_polygon(); - if (!occluder.is_valid()) { - occluder = Ref(memnew(OccluderPolygon2D)); + if (occluder.is_null()) { + occluder.instantiate(); node->set_occluder_polygon(occluder); } return occluder; diff --git a/editor/plugins/navigation_obstacle_3d_editor_plugin.cpp b/editor/plugins/navigation_obstacle_3d_editor_plugin.cpp index 2eaab0fcbde..8b938d6f605 100644 --- a/editor/plugins/navigation_obstacle_3d_editor_plugin.cpp +++ b/editor/plugins/navigation_obstacle_3d_editor_plugin.cpp @@ -542,7 +542,7 @@ NavigationObstacle3DEditor::NavigationObstacle3DEditor() { point_lines_meshinstance->set_mesh(point_lines_mesh); point_lines_meshinstance->set_transform(Transform3D(Basis(), Vector3(0, 0, 0.00001))); - line_material = Ref(memnew(StandardMaterial3D)); + line_material.instantiate(); line_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED); line_material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA); line_material->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); @@ -550,7 +550,7 @@ NavigationObstacle3DEditor::NavigationObstacle3DEditor() { line_material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true); line_material->set_albedo(Color(1, 1, 1)); - handle_material = Ref(memnew(StandardMaterial3D)); + handle_material.instantiate(); handle_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED); handle_material->set_flag(StandardMaterial3D::FLAG_USE_POINT_SIZE, true); handle_material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA); diff --git a/editor/plugins/navigation_polygon_editor_plugin.cpp b/editor/plugins/navigation_polygon_editor_plugin.cpp index 3c710404088..c11a7cf20e2 100644 --- a/editor/plugins/navigation_polygon_editor_plugin.cpp +++ b/editor/plugins/navigation_polygon_editor_plugin.cpp @@ -38,8 +38,8 @@ Ref NavigationPolygonEditor::_ensure_navpoly() const { Ref navpoly = node->get_navigation_polygon(); - if (!navpoly.is_valid()) { - navpoly = Ref(memnew(NavigationPolygon)); + if (navpoly.is_null()) { + navpoly.instantiate(); node->set_navigation_polygon(navpoly); } return navpoly; diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index 5afe01025d3..810d1674ca1 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -7050,12 +7050,12 @@ void fragment() { col.a = EDITOR_GET("editors/3d/manipulator_gizmo_opacity"); - move_gizmo[i] = Ref(memnew(ArrayMesh)); - move_plane_gizmo[i] = Ref(memnew(ArrayMesh)); - rotate_gizmo[i] = Ref(memnew(ArrayMesh)); - scale_gizmo[i] = Ref(memnew(ArrayMesh)); - scale_plane_gizmo[i] = Ref(memnew(ArrayMesh)); - axis_gizmo[i] = Ref(memnew(ArrayMesh)); + move_gizmo[i].instantiate(); + move_plane_gizmo[i].instantiate(); + rotate_gizmo[i].instantiate(); + scale_gizmo[i].instantiate(); + scale_plane_gizmo[i].instantiate(); + axis_gizmo[i].instantiate(); Ref mat = memnew(StandardMaterial3D); mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED); @@ -7286,7 +7286,7 @@ void fragment() { border_mat->set_shader(border_shader); border_mat->set_shader_parameter("albedo", Color(0.75, 0.75, 0.75, col.a / 3.0)); - rotate_gizmo[3] = Ref(memnew(ArrayMesh)); + rotate_gizmo[3].instantiate(); rotate_gizmo[3]->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, arrays); rotate_gizmo[3]->surface_set_material(0, border_mat); } @@ -8639,7 +8639,7 @@ Node3DEditor::Node3DEditor() { gizmo.visible = true; gizmo.scale = 1.0; - viewport_environment = Ref(memnew(Environment)); + viewport_environment.instantiate(); VBoxContainer *vbc = this; custom_camera = nullptr; diff --git a/editor/plugins/path_3d_editor_plugin.cpp b/editor/plugins/path_3d_editor_plugin.cpp index 91cff9f8e2e..3a4b3a0ea23 100644 --- a/editor/plugins/path_3d_editor_plugin.cpp +++ b/editor/plugins/path_3d_editor_plugin.cpp @@ -922,7 +922,7 @@ Ref Path3DGizmoPlugin::create_gizmo(Node3D *p_spatial) { Path3D *path = Object::cast_to(p_spatial); if (path) { - ref = Ref(memnew(Path3DGizmo(path, disk_size))); + ref.instantiate(path, disk_size); } return ref; diff --git a/editor/plugins/polygon_3d_editor_plugin.cpp b/editor/plugins/polygon_3d_editor_plugin.cpp index 9bb2d815496..017504f0d61 100644 --- a/editor/plugins/polygon_3d_editor_plugin.cpp +++ b/editor/plugins/polygon_3d_editor_plugin.cpp @@ -554,7 +554,7 @@ Polygon3DEditor::Polygon3DEditor() { imgeom->set_mesh(imesh); imgeom->set_transform(Transform3D(Basis(), Vector3(0, 0, 0.00001))); - line_material = Ref(memnew(StandardMaterial3D)); + line_material.instantiate(); line_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED); line_material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA); line_material->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); @@ -562,7 +562,7 @@ Polygon3DEditor::Polygon3DEditor() { line_material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true); line_material->set_albedo(Color(1, 1, 1)); - handle_material = Ref(memnew(StandardMaterial3D)); + handle_material.instantiate(); handle_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED); handle_material->set_flag(StandardMaterial3D::FLAG_USE_POINT_SIZE, true); handle_material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA); diff --git a/editor/plugins/skeleton_3d_editor_plugin.cpp b/editor/plugins/skeleton_3d_editor_plugin.cpp index 19fbd2dd3b6..369a1fc8643 100644 --- a/editor/plugins/skeleton_3d_editor_plugin.cpp +++ b/editor/plugins/skeleton_3d_editor_plugin.cpp @@ -1186,8 +1186,8 @@ Skeleton3DEditor::Skeleton3DEditor(EditorInspectorPluginSkeleton *e_plugin, Skel singleton = this; // Handle. - handle_material = Ref(memnew(ShaderMaterial)); - handle_shader = Ref(memnew(Shader)); + handle_material.instantiate(); + handle_shader.instantiate(); handle_shader->set_code(R"( // Skeleton 3D gizmo handle shader. diff --git a/modules/enet/enet_connection.cpp b/modules/enet/enet_connection.cpp index 2ccfd5d3263..9c9302a51cb 100644 --- a/modules/enet/enet_connection.cpp +++ b/modules/enet/enet_connection.cpp @@ -113,7 +113,7 @@ Ref ENetConnection::connect_to_host(const String &p_address, int if (peer == nullptr) { return nullptr; } - out = Ref(memnew(ENetPacketPeer(peer))); + out.instantiate(peer); peers.push_back(out); return out; } diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index aa482615da0..2b815b7de94 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -117,7 +117,7 @@ static Ref _mesh_to_importer_mesh(Ref p_mesh) { mat_name = mat->get_name(); } else { // Assign default material when no material is assigned. - mat = Ref(memnew(StandardMaterial3D)); + mat.instantiate(); } importer_mesh->add_surface(p_mesh->surface_get_primitive_type(surface_i), array, p_mesh->surface_get_blend_shape_arrays(surface_i), p_mesh->surface_get_lods(surface_i), mat, @@ -5913,7 +5913,7 @@ void GLTFDocument::_convert_csg_shape_to_gltf(CSGShape3D *p_current, GLTFNodeInd mat_name = mat->get_name(); } else { // Assign default material when no material is assigned. - mat = Ref(memnew(StandardMaterial3D)); + mat.instantiate(); } mesh->add_surface(csg_mesh->surface_get_primitive_type(surface_i), diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp index 71171be3f14..0588ba034a5 100644 --- a/modules/gridmap/grid_map.cpp +++ b/modules/gridmap/grid_map.cpp @@ -801,8 +801,8 @@ void GridMap::_octant_enter_world(const OctantKey &p_key) { if (!g.navigation_debug_edge_connections_instance.is_valid()) { g.navigation_debug_edge_connections_instance = RenderingServer::get_singleton()->instance_create(); } - if (!g.navigation_debug_edge_connections_mesh.is_valid()) { - g.navigation_debug_edge_connections_mesh = Ref(memnew(ArrayMesh)); + if (g.navigation_debug_edge_connections_mesh.is_null()) { + g.navigation_debug_edge_connections_mesh.instantiate(); } _update_octant_navigation_debug_edge_connections_mesh(p_key); @@ -1386,8 +1386,8 @@ void GridMap::_update_octant_navigation_debug_edge_connections_mesh(const Octant g.navigation_debug_edge_connections_instance = RenderingServer::get_singleton()->instance_create(); } - if (!g.navigation_debug_edge_connections_mesh.is_valid()) { - g.navigation_debug_edge_connections_mesh = Ref(memnew(ArrayMesh)); + if (g.navigation_debug_edge_connections_mesh.is_null()) { + g.navigation_debug_edge_connections_mesh.instantiate(); } g.navigation_debug_edge_connections_mesh->clear_surfaces(); diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index 6ae9ce56c67..380b401683c 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -2826,7 +2826,7 @@ Ref ResourceFormatLoaderCSharpScript::load(const String &p_path, const GDMonoCache::managed_callbacks.ScriptManagerBridge_GetOrCreateScriptBridgeForPath(&p_path, &scr); ERR_FAIL_COND_V_MSG(scr.is_null(), Ref(), "Could not create C# script '" + real_path + "'."); } else { - scr = Ref(memnew(CSharpScript)); + scr.instantiate(); } #if defined(DEBUG_ENABLED) || defined(TOOLS_ENABLED) diff --git a/modules/multiplayer/scene_multiplayer.cpp b/modules/multiplayer/scene_multiplayer.cpp index e245101eebd..dde14034e65 100644 --- a/modules/multiplayer/scene_multiplayer.cpp +++ b/modules/multiplayer/scene_multiplayer.cpp @@ -684,9 +684,9 @@ void SceneMultiplayer::_bind_methods() { SceneMultiplayer::SceneMultiplayer() { relay_buffer.instantiate(); - cache = Ref(memnew(SceneCacheInterface(this))); - replicator = Ref(memnew(SceneReplicationInterface(this, cache.ptr()))); - rpc = Ref(memnew(SceneRPCInterface(this, cache.ptr(), replicator.ptr()))); + cache.instantiate(this); + replicator.instantiate(this, cache.ptr()); + rpc.instantiate(this, cache.ptr(), replicator.ptr()); set_multiplayer_peer(Ref(memnew(OfflineMultiplayerPeer))); } diff --git a/modules/openxr/extensions/openxr_composition_layer_extension.cpp b/modules/openxr/extensions/openxr_composition_layer_extension.cpp index 2d29b8a82c4..1e3490d1ed9 100644 --- a/modules/openxr/extensions/openxr_composition_layer_extension.cpp +++ b/modules/openxr/extensions/openxr_composition_layer_extension.cpp @@ -281,7 +281,7 @@ void OpenXRViewportCompositionLayerProvider::create_android_surface() { composition_layer_extension->create_android_surface_swapchain(&info, &android_surface.swapchain, &surface); if (surface) { - android_surface.surface = Ref(memnew(JavaObject(JavaClassWrapper::get_singleton()->wrap("android.view.Surface"), surface))); + android_surface.surface.instantiate(JavaClassWrapper::get_singleton()->wrap("android.view.Surface"), surface); } } #endif diff --git a/modules/theora/video_stream_theora.cpp b/modules/theora/video_stream_theora.cpp index 8b2c58acd53..372885b0b47 100644 --- a/modules/theora/video_stream_theora.cpp +++ b/modules/theora/video_stream_theora.cpp @@ -629,7 +629,7 @@ void VideoStreamPlaybackTheora::_streaming_thread(void *ud) { #endif VideoStreamPlaybackTheora::VideoStreamPlaybackTheora() { - texture = Ref(memnew(ImageTexture)); + texture.instantiate(); #ifdef THEORA_USE_THREAD_STREAMING int rb_power = nearest_shift(RB_SIZE_KB * 1024); diff --git a/platform/ios/export/export_plugin.cpp b/platform/ios/export/export_plugin.cpp index d6cd2e0f3c3..3c5a930bab0 100644 --- a/platform/ios/export/export_plugin.cpp +++ b/platform/ios/export/export_plugin.cpp @@ -1082,7 +1082,7 @@ Error EditorExportPlatformIOS::_export_loading_screen_file(const Ref(memnew(Image(boot_splash_png))); + splash.instantiate(boot_splash_png); } // Using same image for both @2x and @3x diff --git a/scene/2d/touch_screen_button.cpp b/scene/2d/touch_screen_button.cpp index b968f39ccbb..220608a250d 100644 --- a/scene/2d/touch_screen_button.cpp +++ b/scene/2d/touch_screen_button.cpp @@ -430,6 +430,6 @@ void TouchScreenButton::_bind_methods() { } TouchScreenButton::TouchScreenButton() { - unit_rect = Ref(memnew(RectangleShape2D)); + unit_rect.instantiate(); unit_rect->set_size(Vector2(1, 1)); } diff --git a/scene/3d/label_3d.cpp b/scene/3d/label_3d.cpp index 6b3510a72a1..01f15137bec 100644 --- a/scene/3d/label_3d.cpp +++ b/scene/3d/label_3d.cpp @@ -318,7 +318,7 @@ Ref Label3D::generate_triangle_mesh() const { facesw[j] = vtx; } - triangle_mesh = Ref(memnew(TriangleMesh)); + triangle_mesh.instantiate(); triangle_mesh->create(faces); return triangle_mesh; diff --git a/scene/3d/navigation_agent_3d.cpp b/scene/3d/navigation_agent_3d.cpp index 9242c2a2ea3..faf138896a5 100644 --- a/scene/3d/navigation_agent_3d.cpp +++ b/scene/3d/navigation_agent_3d.cpp @@ -1081,8 +1081,8 @@ void NavigationAgent3D::_update_debug_path() { debug_path_instance = RenderingServer::get_singleton()->instance_create(); } - if (!debug_path_mesh.is_valid()) { - debug_path_mesh = Ref(memnew(ArrayMesh)); + if (debug_path_mesh.is_null()) { + debug_path_mesh.instantiate(); } debug_path_mesh->clear_surfaces(); diff --git a/scene/3d/navigation_link_3d.cpp b/scene/3d/navigation_link_3d.cpp index 0cce21b9d0f..9e29384fc9b 100644 --- a/scene/3d/navigation_link_3d.cpp +++ b/scene/3d/navigation_link_3d.cpp @@ -56,8 +56,8 @@ void NavigationLink3D::_update_debug_mesh() { debug_instance = RenderingServer::get_singleton()->instance_create(); } - if (!debug_mesh.is_valid()) { - debug_mesh = Ref(memnew(ArrayMesh)); + if (debug_mesh.is_null()) { + debug_mesh.instantiate(); } RID nav_map = get_world_3d()->get_navigation_map(); diff --git a/scene/3d/navigation_obstacle_3d.cpp b/scene/3d/navigation_obstacle_3d.cpp index 2eb04a0054e..72a7253a100 100644 --- a/scene/3d/navigation_obstacle_3d.cpp +++ b/scene/3d/navigation_obstacle_3d.cpp @@ -389,8 +389,8 @@ void NavigationObstacle3D::_update_fake_agent_radius_debug() { if (!fake_agent_radius_debug_instance.is_valid()) { fake_agent_radius_debug_instance = RenderingServer::get_singleton()->instance_create(); } - if (!fake_agent_radius_debug_mesh.is_valid()) { - fake_agent_radius_debug_mesh = Ref(memnew(ArrayMesh)); + if (fake_agent_radius_debug_mesh.is_null()) { + fake_agent_radius_debug_mesh.instantiate(); } fake_agent_radius_debug_mesh->clear_surfaces(); @@ -487,8 +487,8 @@ void NavigationObstacle3D::_update_static_obstacle_debug() { if (!static_obstacle_debug_instance.is_valid()) { static_obstacle_debug_instance = RenderingServer::get_singleton()->instance_create(); } - if (!static_obstacle_debug_mesh.is_valid()) { - static_obstacle_debug_mesh = Ref(memnew(ArrayMesh)); + if (static_obstacle_debug_mesh.is_null()) { + static_obstacle_debug_mesh.instantiate(); } static_obstacle_debug_mesh->clear_surfaces(); diff --git a/scene/3d/navigation_region_3d.cpp b/scene/3d/navigation_region_3d.cpp index c0c254e7ed5..2d67e4334e6 100644 --- a/scene/3d/navigation_region_3d.cpp +++ b/scene/3d/navigation_region_3d.cpp @@ -492,8 +492,8 @@ void NavigationRegion3D::_update_debug_mesh() { debug_instance = RenderingServer::get_singleton()->instance_create(); } - if (!debug_mesh.is_valid()) { - debug_mesh = Ref(memnew(ArrayMesh)); + if (debug_mesh.is_null()) { + debug_mesh.instantiate(); } debug_mesh->clear_surfaces(); @@ -669,8 +669,8 @@ void NavigationRegion3D::_update_debug_edge_connections_mesh() { debug_edge_connections_instance = RenderingServer::get_singleton()->instance_create(); } - if (!debug_edge_connections_mesh.is_valid()) { - debug_edge_connections_mesh = Ref(memnew(ArrayMesh)); + if (debug_edge_connections_mesh.is_null()) { + debug_edge_connections_mesh.instantiate(); } debug_edge_connections_mesh->clear_surfaces(); diff --git a/scene/3d/path_3d.cpp b/scene/3d/path_3d.cpp index 64259a24b00..00c83101b92 100644 --- a/scene/3d/path_3d.cpp +++ b/scene/3d/path_3d.cpp @@ -88,8 +88,8 @@ void Path3D::_update_debug_mesh() { return; } - if (!debug_mesh.is_valid()) { - debug_mesh = Ref(memnew(ArrayMesh)); + if (debug_mesh.is_null()) { + debug_mesh.instantiate(); } if (!(curve.is_valid())) { diff --git a/scene/3d/physics/ray_cast_3d.cpp b/scene/3d/physics/ray_cast_3d.cpp index a9272388c10..b9159f072b2 100644 --- a/scene/3d/physics/ray_cast_3d.cpp +++ b/scene/3d/physics/ray_cast_3d.cpp @@ -464,7 +464,7 @@ void RayCast3D::_create_debug_shape() { } if (debug_mesh.is_null()) { - debug_mesh = Ref(memnew(ArrayMesh)); + debug_mesh.instantiate(); } } diff --git a/scene/3d/physics/shape_cast_3d.cpp b/scene/3d/physics/shape_cast_3d.cpp index 8ad651fdf56..19c74bc9254 100644 --- a/scene/3d/physics/shape_cast_3d.cpp +++ b/scene/3d/physics/shape_cast_3d.cpp @@ -546,7 +546,7 @@ void ShapeCast3D::_create_debug_shape() { } if (debug_mesh.is_null()) { - debug_mesh = Ref(memnew(ArrayMesh)); + debug_mesh.instantiate(); } } diff --git a/scene/3d/sprite_3d.cpp b/scene/3d/sprite_3d.cpp index 42460eec4cf..6e3ada83add 100644 --- a/scene/3d/sprite_3d.cpp +++ b/scene/3d/sprite_3d.cpp @@ -470,7 +470,7 @@ Ref SpriteBase3D::generate_triangle_mesh() const { facesw[j] = vtx; } - triangle_mesh = Ref(memnew(TriangleMesh)); + triangle_mesh.instantiate(); triangle_mesh->create(faces); return triangle_mesh; diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index b1c47d858d1..7e07f4a2023 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -3001,5 +3001,5 @@ GraphEdit::GraphEdit() { set_clip_contents(true); - arranger = Ref(memnew(GraphEditArranger(this))); + arranger.instantiate(this); } diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index 60cecfcfe70..16b41c8f9b7 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -899,7 +899,7 @@ Ref SceneTree::get_debug_contact_mesh() { return debug_contact_mesh; } - debug_contact_mesh = Ref(memnew(ArrayMesh)); + debug_contact_mesh.instantiate(); Ref mat = Ref(memnew(StandardMaterial3D)); mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED); diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 5a90eb8f3e3..1ee99099ec8 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -1213,7 +1213,7 @@ void Viewport::set_world_2d(const Ref &p_world_2d) { } } else { WARN_PRINT("Invalid world_2d"); - world_2d = Ref(memnew(World2D)); + world_2d.instantiate(); } world_2d->register_viewport(this); @@ -4386,7 +4386,7 @@ void Viewport::set_world_3d(const Ref &p_world_3d) { own_world_3d = world_3d->duplicate(); world_3d->connect_changed(callable_mp(this, &Viewport::_own_world_3d_changed)); } else { - own_world_3d = Ref(memnew(World3D)); + own_world_3d.instantiate(); } } @@ -4437,7 +4437,7 @@ void Viewport::set_use_own_world_3d(bool p_use_own_world_3d) { own_world_3d = world_3d->duplicate(); world_3d->connect_changed(callable_mp(this, &Viewport::_own_world_3d_changed)); } else { - own_world_3d = Ref(memnew(World3D)); + own_world_3d.instantiate(); } } else { own_world_3d = Ref(); @@ -4963,7 +4963,7 @@ void Viewport::_validate_property(PropertyInfo &p_property) const { } Viewport::Viewport() { - world_2d = Ref(memnew(World2D)); + world_2d.instantiate(); world_2d->register_viewport(this); viewport = RenderingServer::get_singleton()->viewport_create(); diff --git a/scene/resources/3d/shape_3d.cpp b/scene/resources/3d/shape_3d.cpp index 5a79392ba52..259d82b7a01 100644 --- a/scene/resources/3d/shape_3d.cpp +++ b/scene/resources/3d/shape_3d.cpp @@ -73,7 +73,7 @@ Ref Shape3D::get_debug_mesh() { Vector lines = get_debug_mesh_lines(); - debug_mesh_cache = Ref(memnew(ArrayMesh)); + debug_mesh_cache.instantiate(); if (!lines.is_empty()) { //make mesh diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp index 848ae2713d0..b0353b4f2c7 100644 --- a/scene/resources/mesh.cpp +++ b/scene/resources/mesh.cpp @@ -385,7 +385,7 @@ Ref Mesh::generate_triangle_mesh() const { } } - triangle_mesh = Ref(memnew(TriangleMesh)); + triangle_mesh.instantiate(); triangle_mesh->create(faces); return triangle_mesh; diff --git a/scene/resources/navigation_mesh.cpp b/scene/resources/navigation_mesh.cpp index 67ed65df0da..034d4d69966 100644 --- a/scene/resources/navigation_mesh.cpp +++ b/scene/resources/navigation_mesh.cpp @@ -392,8 +392,8 @@ Ref NavigationMesh::get_debug_mesh() { return debug_mesh; } - if (!debug_mesh.is_valid()) { - debug_mesh = Ref(memnew(ArrayMesh)); + if (debug_mesh.is_null()) { + debug_mesh.instantiate(); } else { debug_mesh->clear_surfaces(); } diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index bb3aad0f28d..809a77a4872 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -2195,7 +2195,7 @@ void PackedScene::replace_state(Ref p_by) { } void PackedScene::recreate_state() { - state = Ref(memnew(SceneState)); + state.instantiate(); state->set_path(get_path()); #ifdef TOOLS_ENABLED state->set_last_modified_time(get_last_modified_time()); @@ -2286,5 +2286,5 @@ void PackedScene::_bind_methods() { } PackedScene::PackedScene() { - state = Ref(memnew(SceneState)); + state.instantiate(); } diff --git a/scene/resources/portable_compressed_texture.cpp b/scene/resources/portable_compressed_texture.cpp index 06b5ec6d5a2..55bbed7c470 100644 --- a/scene/resources/portable_compressed_texture.cpp +++ b/scene/resources/portable_compressed_texture.cpp @@ -89,7 +89,7 @@ void PortableCompressedTexture2D::_set_data(const Vector &p_data) { data_size -= mipsize; } - image = Ref(memnew(Image(size.width, size.height, mipmaps, format, image_data))); + image.instantiate(size.width, size.height, mipmaps, format, image_data); } break; case COMPRESSION_MODE_BASIS_UNIVERSAL: { @@ -100,7 +100,7 @@ void PortableCompressedTexture2D::_set_data(const Vector &p_data) { case COMPRESSION_MODE_S3TC: case COMPRESSION_MODE_ETC2: case COMPRESSION_MODE_BPTC: { - image = Ref(memnew(Image(size.width, size.height, mipmaps, format, p_data.slice(20)))); + image.instantiate(size.width, size.height, mipmaps, format, p_data.slice(20)); } break; } ERR_FAIL_COND(image.is_null()); diff --git a/tests/scene/test_viewport.h b/tests/scene/test_viewport.h index dde37944ece..06a38f234b0 100644 --- a/tests/scene/test_viewport.h +++ b/tests/scene/test_viewport.h @@ -1577,7 +1577,7 @@ TEST_CASE("[SceneTree][Viewport] Physics Picking 2D") { PickingCollider pc; pc.a = memnew(TestArea2D); pc.c = memnew(CollisionShape2D); - pc.r = Ref(memnew(RectangleShape2D)); + pc.r.instantiate(); pc.r->set_size(Size2(150, 150)); pc.c->set_shape(pc.r); pc.a->add_child(pc.c);