From e81f25ac7b197698d0556678d25c05044b422341 Mon Sep 17 00:00:00 2001
From: Relintai <relintai@protonmail.com>
Date: Sun, 3 Sep 2023 11:51:09 +0200
Subject: [PATCH] Added init and finish methods to the NavigationMeshGenerator.
 Also small tweaks in initialization.

---
 main/main.cpp                                    | 8 ++++++++
 servers/navigation/navigation_mesh_generator.cpp | 6 ++++++
 servers/navigation/navigation_mesh_generator.h   | 3 +++
 3 files changed, 17 insertions(+)

diff --git a/main/main.cpp b/main/main.cpp
index ef0cad0f3..248664a93 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -226,6 +226,8 @@ void finalize_physics() {
 }
 
 void initialize_navigation_mesh_generator() {
+	ERR_FAIL_COND(navigation_mesh_generator != NULL);
+
 	// Init chosen NavigationMeshGenerator
 	const String &server_name = GLOBAL_GET(NavigationMeshGeneratorManager::setting_property_name);
 	navigation_mesh_generator = NavigationMeshGeneratorManager::get_singleton()->new_server(server_name);
@@ -243,6 +245,8 @@ void initialize_navigation_mesh_generator() {
 	}
 
 	if (navigation_mesh_generator) {
+		navigation_mesh_generator->init();
+
 		// need to register singleton earlier so modules / extensions / addons can use it on SCENE / SERVER init level
 		Engine::get_singleton()->add_singleton(Engine::Singleton("NavigationMeshGenerator", NavigationMeshGenerator::get_singleton()));
 	}
@@ -251,6 +255,10 @@ void initialize_navigation_mesh_generator() {
 }
 
 void finalize_navigation_mesh_generator() {
+	ERR_FAIL_COND(!navigation_mesh_generator);
+
+	navigation_mesh_generator->finish();
+
 	memdelete(navigation_mesh_generator);
 	navigation_mesh_generator = nullptr;
 }
diff --git a/servers/navigation/navigation_mesh_generator.cpp b/servers/navigation/navigation_mesh_generator.cpp
index 3139bd968..8dcef1955 100644
--- a/servers/navigation/navigation_mesh_generator.cpp
+++ b/servers/navigation/navigation_mesh_generator.cpp
@@ -71,6 +71,12 @@ NavigationMeshGenerator *NavigationMeshGenerator::get_singleton() {
 	return singleton;
 }
 
+void NavigationMeshGenerator::init() {
+}
+
+void NavigationMeshGenerator::finish() {
+}
+
 NavigationMeshGenerator::NavigationMeshGenerator() {
 	ERR_FAIL_COND(singleton != nullptr);
 	singleton = this;
diff --git a/servers/navigation/navigation_mesh_generator.h b/servers/navigation/navigation_mesh_generator.h
index cc0cfcbaa..98aa300ac 100644
--- a/servers/navigation/navigation_mesh_generator.h
+++ b/servers/navigation/navigation_mesh_generator.h
@@ -85,6 +85,9 @@ public:
 	virtual bool is_navigation_mesh_baking(Ref<NavigationMesh> p_navigation_mesh) const = 0;
 #endif // _3D_DISABLED
 
+	virtual void init();
+	virtual void finish();
+
 	NavigationMeshGenerator();
 	~NavigationMeshGenerator();
 };