소스 검색

[AssetLib] Fix crash in Web editor.

Add EditorAssetLibrary::is_available which always returns false in the
Web editor and use it in EditorNode for detection.

(cherry picked from commit 0e504e4191d4d535ff296befb3c281c44ae95d88)
Fabio Alessandrelli 3 년 전
부모
커밋
ad5fdcc0f3
4개의 변경된 파일19개의 추가작업 그리고 12개의 파일을 삭제
  1. 5 7
      editor/editor_node.cpp
  2. 11 0
      editor/plugins/asset_library_editor_plugin.cpp
  3. 2 0
      editor/plugins/asset_library_editor_plugin.h
  4. 1 5
      editor/project_manager.cpp

+ 5 - 7
editor/editor_node.cpp

@@ -410,7 +410,7 @@ void EditorNode::_unhandled_input(const Ref<InputEvent> &p_event) {
 			_editor_select(EDITOR_SCRIPT);
 			_editor_select(EDITOR_SCRIPT);
 		} else if (ED_IS_SHORTCUT("editor/editor_help", p_event)) {
 		} else if (ED_IS_SHORTCUT("editor/editor_help", p_event)) {
 			emit_signal("request_help_search", "");
 			emit_signal("request_help_search", "");
-		} else if (ED_IS_SHORTCUT("editor/editor_assetlib", p_event) && StreamPeerSSL::is_available()) {
+		} else if (ED_IS_SHORTCUT("editor/editor_assetlib", p_event) && AssetLibraryEditorPlugin::is_available()) {
 			_editor_select(EDITOR_ASSETLIB);
 			_editor_select(EDITOR_ASSETLIB);
 		} else if (ED_IS_SHORTCUT("editor/editor_next", p_event)) {
 		} else if (ED_IS_SHORTCUT("editor/editor_next", p_event)) {
 			_editor_select_next();
 			_editor_select_next();
@@ -5628,12 +5628,12 @@ void EditorNode::_feature_profile_changed() {
 
 
 		main_editor_buttons[EDITOR_3D]->set_visible(!profile->is_feature_disabled(EditorFeatureProfile::FEATURE_3D));
 		main_editor_buttons[EDITOR_3D]->set_visible(!profile->is_feature_disabled(EditorFeatureProfile::FEATURE_3D));
 		main_editor_buttons[EDITOR_SCRIPT]->set_visible(!profile->is_feature_disabled(EditorFeatureProfile::FEATURE_SCRIPT));
 		main_editor_buttons[EDITOR_SCRIPT]->set_visible(!profile->is_feature_disabled(EditorFeatureProfile::FEATURE_SCRIPT));
-		if (StreamPeerSSL::is_available()) {
+		if (AssetLibraryEditorPlugin::is_available()) {
 			main_editor_buttons[EDITOR_ASSETLIB]->set_visible(!profile->is_feature_disabled(EditorFeatureProfile::FEATURE_ASSET_LIB));
 			main_editor_buttons[EDITOR_ASSETLIB]->set_visible(!profile->is_feature_disabled(EditorFeatureProfile::FEATURE_ASSET_LIB));
 		}
 		}
 		if ((profile->is_feature_disabled(EditorFeatureProfile::FEATURE_3D) && singleton->main_editor_buttons[EDITOR_3D]->is_pressed()) ||
 		if ((profile->is_feature_disabled(EditorFeatureProfile::FEATURE_3D) && singleton->main_editor_buttons[EDITOR_3D]->is_pressed()) ||
 				(profile->is_feature_disabled(EditorFeatureProfile::FEATURE_SCRIPT) && singleton->main_editor_buttons[EDITOR_SCRIPT]->is_pressed()) ||
 				(profile->is_feature_disabled(EditorFeatureProfile::FEATURE_SCRIPT) && singleton->main_editor_buttons[EDITOR_SCRIPT]->is_pressed()) ||
-				(StreamPeerSSL::is_available() && profile->is_feature_disabled(EditorFeatureProfile::FEATURE_ASSET_LIB) && singleton->main_editor_buttons[EDITOR_ASSETLIB]->is_pressed())) {
+				(AssetLibraryEditorPlugin::is_available() && profile->is_feature_disabled(EditorFeatureProfile::FEATURE_ASSET_LIB) && singleton->main_editor_buttons[EDITOR_ASSETLIB]->is_pressed())) {
 			_editor_select(EDITOR_2D);
 			_editor_select(EDITOR_2D);
 		}
 		}
 	} else {
 	} else {
@@ -5645,7 +5645,7 @@ void EditorNode::_feature_profile_changed() {
 		filesystem_dock->set_visible(true);
 		filesystem_dock->set_visible(true);
 		main_editor_buttons[EDITOR_3D]->set_visible(true);
 		main_editor_buttons[EDITOR_3D]->set_visible(true);
 		main_editor_buttons[EDITOR_SCRIPT]->set_visible(true);
 		main_editor_buttons[EDITOR_SCRIPT]->set_visible(true);
-		if (StreamPeerSSL::is_available()) {
+		if (AssetLibraryEditorPlugin::is_available()) {
 			main_editor_buttons[EDITOR_ASSETLIB]->set_visible(true);
 			main_editor_buttons[EDITOR_ASSETLIB]->set_visible(true);
 		}
 		}
 	}
 	}
@@ -6960,13 +6960,11 @@ EditorNode::EditorNode() {
 
 
 	// Asset Library can't work on Web editor for now as most assets are sourced
 	// Asset Library can't work on Web editor for now as most assets are sourced
 	// directly from GitHub which does not set CORS.
 	// directly from GitHub which does not set CORS.
-#ifndef JAVASCRIPT_ENABLED
-	if (StreamPeerSSL::is_available()) {
+	if (AssetLibraryEditorPlugin::is_available()) {
 		add_editor_plugin(memnew(AssetLibraryEditorPlugin(this)));
 		add_editor_plugin(memnew(AssetLibraryEditorPlugin(this)));
 	} else {
 	} else {
 		WARN_PRINT("Asset Library not available, as it requires SSL to work.");
 		WARN_PRINT("Asset Library not available, as it requires SSL to work.");
 	}
 	}
-#endif
 
 
 	//add interface before adding plugins
 	//add interface before adding plugins
 
 

+ 11 - 0
editor/plugins/asset_library_editor_plugin.cpp

@@ -31,6 +31,7 @@
 #include "asset_library_editor_plugin.h"
 #include "asset_library_editor_plugin.h"
 
 
 #include "core/io/json.h"
 #include "core/io/json.h"
+#include "core/io/stream_peer_ssl.h"
 #include "core/version.h"
 #include "core/version.h"
 #include "editor/editor_node.h"
 #include "editor/editor_node.h"
 #include "editor/editor_scale.h"
 #include "editor/editor_scale.h"
@@ -1582,6 +1583,16 @@ EditorAssetLibrary::EditorAssetLibrary(bool p_templates_only) {
 
 
 ///////
 ///////
 
 
+bool AssetLibraryEditorPlugin::is_available() {
+#ifdef JAVASCRIPT_ENABLED
+	// Asset Library can't work on Web editor for now as most assets are sourced
+	// directly from GitHub which does not set CORS.
+	return false;
+#else
+	return StreamPeerSSL::is_available();
+#endif
+}
+
 void AssetLibraryEditorPlugin::make_visible(bool p_visible) {
 void AssetLibraryEditorPlugin::make_visible(bool p_visible) {
 	if (p_visible) {
 	if (p_visible) {
 		addon_library->show();
 		addon_library->show();

+ 2 - 0
editor/plugins/asset_library_editor_plugin.h

@@ -316,6 +316,8 @@ class AssetLibraryEditorPlugin : public EditorPlugin {
 	EditorNode *editor;
 	EditorNode *editor;
 
 
 public:
 public:
+	static bool is_available();
+
 	virtual String get_name() const { return "AssetLib"; }
 	virtual String get_name() const { return "AssetLib"; }
 	bool has_main_screen() const { return true; }
 	bool has_main_screen() const { return true; }
 	virtual void edit(Object *p_object) {}
 	virtual void edit(Object *p_object) {}

+ 1 - 5
editor/project_manager.cpp

@@ -2598,10 +2598,7 @@ ProjectManager::ProjectManager() {
 	about_btn->connect("pressed", this, "_show_about");
 	about_btn->connect("pressed", this, "_show_about");
 	tree_vb->add_child(about_btn);
 	tree_vb->add_child(about_btn);
 
 
-	// Asset Library can't work on Web editor for now as most assets are sourced
-	// directly from GitHub which does not set CORS.
-#ifndef JAVASCRIPT_ENABLED
-	if (StreamPeerSSL::is_available()) {
+	if (AssetLibraryEditorPlugin::is_available()) {
 		asset_library = memnew(EditorAssetLibrary(true));
 		asset_library = memnew(EditorAssetLibrary(true));
 		asset_library->set_name(TTR("Asset Library Projects"));
 		asset_library->set_name(TTR("Asset Library Projects"));
 		tabs->add_child(asset_library);
 		tabs->add_child(asset_library);
@@ -2609,7 +2606,6 @@ ProjectManager::ProjectManager() {
 	} else {
 	} else {
 		WARN_PRINT("Asset Library not available, as it requires SSL to work.");
 		WARN_PRINT("Asset Library not available, as it requires SSL to work.");
 	}
 	}
-#endif
 
 
 	HBoxContainer *settings_hb = memnew(HBoxContainer);
 	HBoxContainer *settings_hb = memnew(HBoxContainer);
 	settings_hb->set_alignment(BoxContainer::ALIGN_END);
 	settings_hb->set_alignment(BoxContainer::ALIGN_END);