Merge pull request #37067 from zaksnet/multiple-editor-instances

Automatic remote debugger port assignment.
This commit is contained in:
Rémi Verschelde 2021-05-01 12:57:35 +02:00 committed by GitHub
commit 48cc756f88
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 11 deletions

View file

@ -29,8 +29,8 @@
/*************************************************************************/
#include "script_editor_debugger.h"
#include "core/io/marshalls.h"
#include "core/os/os.h"
#include "core/project_settings.h"
#include "core/ustring.h"
#include "core/version.h"
@ -1610,13 +1610,25 @@ void ScriptEditorDebugger::start() {
perf_max.write[i] = 0;
}
int remote_port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port");
if (server->listen(remote_port) != OK) {
EditorNode::get_log()->add_message(String("Error listening on port ") + itos(remote_port), EditorLog::MSG_TYPE_ERROR);
return;
const int max_tries = 6;
remote_port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port");
int current_try = 0;
// Find first available port.
Error err = server->listen(remote_port);
while (err != OK && current_try < max_tries) {
EditorNode::get_log()->add_message(String("Remote debugger failed listening on port: ") + itos(remote_port) + String(" Retrying on new port: " + itos(remote_port + 1)), EditorLog::MSG_TYPE_WARNING);
current_try++;
remote_port++;
OS::get_singleton()->delay_usec(1000);
err = server->listen(remote_port);
}
// No suitable port found.
if (err != OK) {
EditorNode::get_log()->add_message(String("Error listening on port ") + itos(remote_port), EditorLog::MSG_TYPE_ERROR);
EditorNode::get_log()->add_message(String("Remote debugger error listening for connections. No free port"), EditorLog::MSG_TYPE_ERROR);
}
EditorNode::get_singleton()->get_scene_tree_dock()->show_tab_buttons();
auto_switch_remote_scene_tree = (bool)EditorSettings::get_singleton()->get("debugger/auto_switch_to_remote_scene_tree");
if (auto_switch_remote_scene_tree) {
EditorNode::get_singleton()->get_scene_tree_dock()->show_remote_tree();
@ -1651,6 +1663,7 @@ void ScriptEditorDebugger::stop() {
reason->set_tooltip("");
}
remote_port = 0;
pending_in_queue = 0;
message.clear();
@ -2194,6 +2207,11 @@ bool ScriptEditorDebugger::get_debug_with_external_editor() const {
return enable_external_editor;
}
String ScriptEditorDebugger::get_connection_string() const {
String remote_host = EditorSettings::get_singleton()->get("network/debug/remote_host");
return remote_port ? remote_host + ":" + itos(remote_port) : "";
}
void ScriptEditorDebugger::set_debug_with_external_editor(bool p_enabled) {
enable_external_editor = p_enabled;
@ -2796,6 +2814,7 @@ ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor) {
enable_external_editor = false;
last_error_count = 0;
last_warning_count = 0;
remote_port = 0;
EditorNode::get_singleton()->get_pause_button()->connect("pressed", this, "_paused");
}