Skip to content

Commit 582540b

Browse files
authored
Merge pull request #1057 from Spartan322/merge/037956d
Merge commit godotengine/godot@037956d
2 parents 8650775 + a14b50a commit 582540b

116 files changed

Lines changed: 4149 additions & 2463 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

core/core_bind.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,10 @@ void Logger::log_message(const String &p_text, bool p_error) {
235235
////// OS //////
236236

237237
void OS::LoggerBind::logv(const char *p_format, va_list p_list, bool p_err) {
238-
if (!should_log(p_err) || is_logging) {
238+
if (!should_log(p_err)) {
239239
return;
240240
}
241241

242-
is_logging = true;
243-
244242
constexpr int static_buf_size = 1024;
245243
char static_buf[static_buf_size] = { '\0' };
246244
char *buf = static_buf;
@@ -262,12 +260,10 @@ void OS::LoggerBind::logv(const char *p_format, va_list p_list, bool p_err) {
262260
if (len >= static_buf_size) {
263261
Memory::free_static(buf);
264262
}
265-
266-
is_logging = false;
267263
}
268264

269265
void OS::LoggerBind::log_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, bool p_editor_notify, ErrorType p_type, const Vector<Ref<ScriptBacktrace>> &p_script_backtraces) {
270-
if (!should_log(true) || is_logging) {
266+
if (!should_log(true)) {
271267
return;
272268
}
273269

@@ -277,13 +273,9 @@ void OS::LoggerBind::log_error(const char *p_function, const char *p_file, int p
277273
backtraces[i] = p_script_backtraces[i];
278274
}
279275

280-
is_logging = true;
281-
282276
for (Ref<CoreBind::Logger> &logger : loggers) {
283277
logger->log_error(p_function, p_file, p_line, p_code, p_rationale, p_editor_notify, CoreBind::Logger::ErrorType(p_type), backtraces);
284278
}
285-
286-
is_logging = false;
287279
}
288280

289281
PackedByteArray OS::get_entropy(int p_bytes) {

core/core_bind.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,6 @@ class OS : public Object {
149149
mutable HashMap<String, bool> feature_cache;
150150

151151
class LoggerBind : public ::Logger {
152-
inline static thread_local bool is_logging = false;
153-
154152
public:
155153
LocalVector<Ref<CoreBind::Logger>> loggers;
156154

core/error/error_macros.cpp

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@
4545
#endif
4646

4747
static ErrorHandlerList *error_handler_list = nullptr;
48+
static thread_local bool is_printing_error = false;
49+
50+
static void _err_print_fallback(const char *p_function, const char *p_file, int p_line, const char *p_error_details, ErrorHandlerType p_type, bool p_reentrance) {
51+
if (p_reentrance) {
52+
fprintf(stderr, "While attempting to print an error, another error was printed:\n");
53+
}
54+
55+
fprintf(stderr, "%s: %s\n", _error_handler_type_string(p_type), p_error_details);
56+
57+
if (p_function && p_file) {
58+
fprintf(stderr, " at: %s (%s:%i)\n", p_function, p_file, p_line);
59+
}
60+
}
4861

4962
void add_error_handler(ErrorHandlerList *p_handler) {
5063
// If p_handler is already in error_handler_list
@@ -93,12 +106,21 @@ void _err_print_error(const char *p_function, const char *p_file, int p_line, co
93106

94107
// Main error printing function.
95108
void _err_print_error(const char *p_function, const char *p_file, int p_line, const char *p_error, const char *p_message, bool p_editor_notify, ErrorHandlerType p_type) {
109+
if (is_printing_error) {
110+
// Fallback if we're already printing an error, to prevent infinite recursion.
111+
const char *err_details = (p_message && *p_message) ? p_message : p_error;
112+
_err_print_fallback(p_function, p_file, p_line, err_details, p_type, true);
113+
return;
114+
}
115+
116+
is_printing_error = true;
117+
96118
if (OS::get_singleton()) {
97119
OS::get_singleton()->print_error(p_function, p_file, p_line, p_error, p_message, p_editor_notify, (Logger::ErrorType)p_type, ScriptServer::capture_script_backtraces(false));
98120
} else {
99121
// Fallback if errors happen before OS init or after it's destroyed.
100122
const char *err_details = (p_message && *p_message) ? p_message : p_error;
101-
fprintf(stderr, "%s: %s\n at: %s (%s:%i)\n", _error_handler_type_string(p_type), err_details, p_function, p_file, p_line);
123+
_err_print_fallback(p_function, p_file, p_line, err_details, p_type, false);
102124
}
103125

104126
_global_lock();
@@ -110,6 +132,8 @@ void _err_print_error(const char *p_function, const char *p_file, int p_line, co
110132
}
111133

112134
_global_unlock();
135+
136+
is_printing_error = false;
113137
}
114138

115139
// For printing errors when we may crash at any point, so we must flush ASAP a lot of lines
@@ -118,11 +142,19 @@ void _err_print_error(const char *p_function, const char *p_file, int p_line, co
118142
void _err_print_error_asap(const String &p_error, ErrorHandlerType p_type) {
119143
const char *err_details = p_error.utf8().get_data();
120144

145+
if (is_printing_error) {
146+
// Fallback if we're already printing an error, to prevent infinite recursion.
147+
_err_print_fallback(nullptr, nullptr, 0, err_details, p_type, true);
148+
return;
149+
}
150+
151+
is_printing_error = true;
152+
121153
if (OS::get_singleton()) {
122154
OS::get_singleton()->printerr("%s: %s\n", _error_handler_type_string(p_type), err_details);
123155
} else {
124156
// Fallback if errors happen before OS init or after it's destroyed.
125-
fprintf(stderr, "%s: %s\n", _error_handler_type_string(p_type), err_details);
157+
_err_print_fallback(nullptr, nullptr, 0, err_details, p_type, false);
126158
}
127159

128160
_global_lock();
@@ -134,6 +166,8 @@ void _err_print_error_asap(const String &p_error, ErrorHandlerType p_type) {
134166
}
135167

136168
_global_unlock();
169+
170+
is_printing_error = false;
137171
}
138172

139173
// Errors with message. (All combinations of p_error and p_message as String or char*.)

core/io/json.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,18 @@ void JSON::_stringify(String &r_result, const Variant &p_var, const String &p_in
7575
r_result += itos(p_var);
7676
return;
7777
case Variant::FLOAT: {
78-
double num = p_var;
78+
const double num = p_var;
7979

8080
// Only for exactly 0. If we have approximately 0 let the user decide how much
8181
// precision they want.
82-
if (num == double(0)) {
82+
if (num == double(0.0)) {
8383
r_result += "0.0";
8484
return;
8585
}
8686

87-
double magnitude = std::log10(Math::abs(num));
88-
int total_digits = p_full_precision ? 17 : 14;
89-
int precision = MAX(1, total_digits - (int)Math::floor(magnitude));
87+
const double magnitude = std::log10(Math::abs(num));
88+
const int total_digits = p_full_precision ? 17 : 14;
89+
const int precision = MAX(1, total_digits - (int)Math::floor(magnitude));
9090

9191
r_result += String::num(num, precision);
9292
return;
@@ -122,7 +122,7 @@ void JSON::_stringify(String &r_result, const Variant &p_var, const String &p_in
122122
r_result += end_statement;
123123
}
124124
_add_indent(r_result, p_indent, p_cur_indent + 1);
125-
_stringify(r_result, var, p_indent, p_cur_indent + 1, p_sort_keys, p_markers);
125+
_stringify(r_result, var, p_indent, p_cur_indent + 1, p_sort_keys, p_markers, p_full_precision);
126126
}
127127
r_result += end_statement;
128128
_add_indent(r_result, p_indent, p_cur_indent);
@@ -156,9 +156,9 @@ void JSON::_stringify(String &r_result, const Variant &p_var, const String &p_in
156156
r_result += end_statement;
157157
}
158158
_add_indent(r_result, p_indent, p_cur_indent + 1);
159-
_stringify(r_result, String(key), p_indent, p_cur_indent + 1, p_sort_keys, p_markers);
159+
_stringify(r_result, String(key), p_indent, p_cur_indent + 1, p_sort_keys, p_markers, p_full_precision);
160160
r_result += colon;
161-
_stringify(r_result, d[key], p_indent, p_cur_indent + 1, p_sort_keys, p_markers);
161+
_stringify(r_result, d[key], p_indent, p_cur_indent + 1, p_sort_keys, p_markers, p_full_precision);
162162
}
163163

164164
r_result += end_statement;

core/io/json.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class JSON : public Resource {
7474
static const char *tk_name[];
7575

7676
static void _add_indent(String &r_result, const String &p_indent, int p_size);
77-
static void _stringify(String &r_result, const Variant &p_var, const String &p_indent, int p_cur_indent, bool p_sort_keys, HashSet<const void *> &p_markers, bool p_full_precision = false);
77+
static void _stringify(String &r_result, const Variant &p_var, const String &p_indent, int p_cur_indent, bool p_sort_keys, HashSet<const void *> &p_markers, bool p_full_precision);
7878
static Error _get_token(const char32_t *p_str, int &index, int p_len, Token &r_token, int &line, String &r_err_str);
7979
static Error _parse_value(Variant &value, Token &token, const char32_t *p_str, int &index, int p_len, int &line, int p_depth, String &r_err_str);
8080
static Error _parse_array(Array &array, const char32_t *p_str, int &index, int p_len, int &line, int p_depth, String &r_err_str);

core/string/print_string.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
#include "core/os/os.h"
3737

3838
static PrintHandlerList *print_handler_list = nullptr;
39+
static thread_local bool is_printing = false;
40+
41+
static void __print_fallback(const String &p_string, bool p_err) {
42+
fprintf(p_err ? stderr : stdout, "While attempting to print a message, another message was printed:\n%s\n", p_string.utf8().get_data());
43+
}
3944

4045
void add_print_handler(PrintHandlerList *p_handler) {
4146
_global_lock();
@@ -73,6 +78,13 @@ void __print_line(const String &p_string) {
7378
return;
7479
}
7580

81+
if (is_printing) {
82+
__print_fallback(p_string, false);
83+
return;
84+
}
85+
86+
is_printing = true;
87+
7688
OS::get_singleton()->print("%s\n", p_string.utf8().get_data());
7789

7890
_global_lock();
@@ -83,6 +95,8 @@ void __print_line(const String &p_string) {
8395
}
8496

8597
_global_unlock();
98+
99+
is_printing = false;
86100
}
87101

88102
void __print_line_rich(const String &p_string) {
@@ -265,6 +279,13 @@ void __print_line_rich(const String &p_string) {
265279
}
266280
output += "\u001b[0m"; // Reset.
267281

282+
if (is_printing) {
283+
__print_fallback(output, false);
284+
return;
285+
}
286+
287+
is_printing = true;
288+
268289
OS::get_singleton()->print_rich("%s\n", output.utf8().get_data());
269290

270291
_global_lock();
@@ -275,13 +296,22 @@ void __print_line_rich(const String &p_string) {
275296
}
276297

277298
_global_unlock();
299+
300+
is_printing = false;
278301
}
279302

280303
void print_error(const String &p_string) {
281304
if (!CoreGlobals::print_error_enabled) {
282305
return;
283306
}
284307

308+
if (is_printing) {
309+
__print_fallback(p_string, true);
310+
return;
311+
}
312+
313+
is_printing = true;
314+
285315
OS::get_singleton()->printerr("%s\n", p_string.utf8().get_data());
286316

287317
_global_lock();
@@ -292,6 +322,8 @@ void print_error(const String &p_string) {
292322
}
293323

294324
_global_unlock();
325+
326+
is_printing = false;
295327
}
296328

297329
bool is_print_verbose_enabled() {

doc/classes/EditorExportPlatformExtension.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
</description>
150150
</method>
151151
<method name="_get_option_icon" qualifiers="virtual const">
152-
<return type="ImageTexture" />
152+
<return type="Texture2D" />
153153
<param index="0" name="device" type="int" />
154154
<description>
155155
Returns the item icon for the specified [param device] in the one-click deploy menu. The icon should be 16×16 pixels, adjusted for the current editor scale (see [method EditorInterface.get_editor_scale]).

doc/classes/SpinBox.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@
133133
<theme_item name="up_pressed" data_type="icon" type="Texture2D">
134134
Up button icon when the button is being pressed.
135135
</theme_item>
136-
<theme_item name="updown" data_type="icon" type="Texture2D">
137-
Single texture representing both the up and down buttons icons. It is displayed in the middle of the buttons and does not change upon interaction. It is recommended to use individual [theme_item up] and [theme_item down] graphics for better usability. This can also be used as additional decoration between the two buttons.
136+
<theme_item name="updown" data_type="icon" type="Texture2D" deprecated="Use [theme_item up] and [theme_item down] instead.">
137+
Single texture representing both the up and down buttons icons. It is displayed in the middle of the buttons and does not change upon interaction. If a valid icon is assigned, it will replace [theme_item up] and [theme_item down].
138138
</theme_item>
139139
<theme_item name="down_background" data_type="style" type="StyleBox">
140140
Background style of the down button.

editor/debugger/editor_debugger_node.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,9 @@ void EditorDebuggerNode::stop(bool p_force) {
313313

314314
// Also close all debugging sessions.
315315
_for_all(tabs, [&](ScriptEditorDebugger *dbg) {
316-
dbg->_stop_and_notify();
316+
if (dbg->is_session_active()) {
317+
dbg->_stop_and_notify();
318+
}
317319
});
318320
_break_state_changed();
319321
breakpoints.clear();

editor/editor_node.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3319,8 +3319,14 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
33193319
p_confirmed = false;
33203320
}
33213321

3322+
if (p_confirmed && stop_project_confirmation && project_run_bar->is_playing()) {
3323+
project_run_bar->stop_playing();
3324+
stop_project_confirmation = false;
3325+
p_confirmed = false;
3326+
}
3327+
33223328
if (!p_confirmed) {
3323-
if (project_run_bar->is_playing()) {
3329+
if (!stop_project_confirmation && project_run_bar->is_playing()) {
33243330
if (p_option == PROJECT_RELOAD_CURRENT_PROJECT) {
33253331
confirmation->set_text(TTR("Stop running project before reloading the current project?"));
33263332
confirmation->set_ok_button_text(TTR("Stop & Reload"));
@@ -3331,6 +3337,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
33313337
confirmation->reset_size();
33323338
confirmation->popup_centered();
33333339
confirmation_button->hide();
3340+
stop_project_confirmation = true;
33343341
break;
33353342
}
33363343

@@ -6218,6 +6225,10 @@ void EditorNode::_cancel_close_scene_tab() {
62186225
tabs_to_close.clear();
62196226
}
62206227

6228+
void EditorNode::_cancel_confirmation() {
6229+
stop_project_confirmation = false;
6230+
}
6231+
62216232
void EditorNode::_prepare_save_confirmation_popup() {
62226233
if (save_confirmation->get_window() != get_last_exclusive_window()) {
62236234
save_confirmation->reparent(get_last_exclusive_window());
@@ -8434,6 +8445,7 @@ EditorNode::EditorNode() {
84348445
confirmation->set_min_size(Vector2(450.0 * EDSCALE, 0));
84358446
confirmation->connect(SceneStringName(confirmed), callable_mp(this, &EditorNode::_menu_confirm_current));
84368447
confirmation->connect("custom_action", callable_mp(this, &EditorNode::_discard_changes));
8448+
confirmation->connect("canceled", callable_mp(this, &EditorNode::_cancel_confirmation));
84378449

84388450
save_confirmation = memnew(ConfirmationDialog);
84398451
save_confirmation->add_button(TTRC("Don't Save"), DisplayServer::get_singleton()->get_swap_cancel_ok(), "discard");

0 commit comments

Comments
 (0)