script_editor_debugger.cpp 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701
  1. /*************************************************************************/
  2. /* script_editor_debugger.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "script_editor_debugger.h"
  31. #include "core/debugger/debugger_marshalls.h"
  32. #include "core/debugger/remote_debugger.h"
  33. #include "core/io/marshalls.h"
  34. #include "core/project_settings.h"
  35. #include "core/ustring.h"
  36. #include "editor/debugger/editor_network_profiler.h"
  37. #include "editor/debugger/editor_performance_profiler.h"
  38. #include "editor/debugger/editor_profiler.h"
  39. #include "editor/debugger/editor_visual_profiler.h"
  40. #include "editor/editor_log.h"
  41. #include "editor/editor_node.h"
  42. #include "editor/editor_scale.h"
  43. #include "editor/editor_settings.h"
  44. #include "editor/plugins/canvas_item_editor_plugin.h"
  45. #include "editor/plugins/node_3d_editor_plugin.h"
  46. #include "editor/property_editor.h"
  47. #include "main/performance.h"
  48. #include "scene/3d/camera_3d.h"
  49. #include "scene/debugger/scene_debugger.h"
  50. #include "scene/gui/dialogs.h"
  51. #include "scene/gui/label.h"
  52. #include "scene/gui/line_edit.h"
  53. #include "scene/gui/margin_container.h"
  54. #include "scene/gui/rich_text_label.h"
  55. #include "scene/gui/separator.h"
  56. #include "scene/gui/split_container.h"
  57. #include "scene/gui/tab_container.h"
  58. #include "scene/gui/texture_button.h"
  59. #include "scene/gui/tree.h"
  60. #include "scene/resources/packed_scene.h"
  61. #include "servers/display_server.h"
  62. using CameraOverride = EditorDebuggerNode::CameraOverride;
  63. void ScriptEditorDebugger::_put_msg(String p_message, Array p_data) {
  64. if (is_session_active()) {
  65. Array msg;
  66. msg.push_back(p_message);
  67. msg.push_back(p_data);
  68. peer->put_message(msg);
  69. }
  70. }
  71. void ScriptEditorDebugger::debug_copy() {
  72. String msg = reason->get_text();
  73. if (msg == "") {
  74. return;
  75. }
  76. DisplayServer::get_singleton()->clipboard_set(msg);
  77. }
  78. void ScriptEditorDebugger::debug_skip_breakpoints() {
  79. skip_breakpoints_value = !skip_breakpoints_value;
  80. if (skip_breakpoints_value) {
  81. skip_breakpoints->set_icon(get_theme_icon("DebugSkipBreakpointsOn", "EditorIcons"));
  82. } else {
  83. skip_breakpoints->set_icon(get_theme_icon("DebugSkipBreakpointsOff", "EditorIcons"));
  84. }
  85. Array msg;
  86. msg.push_back(skip_breakpoints_value);
  87. _put_msg("set_skip_breakpoints", msg);
  88. }
  89. void ScriptEditorDebugger::debug_next() {
  90. ERR_FAIL_COND(!breaked);
  91. _put_msg("next", Array());
  92. _clear_execution();
  93. }
  94. void ScriptEditorDebugger::debug_step() {
  95. ERR_FAIL_COND(!breaked);
  96. _put_msg("step", Array());
  97. _clear_execution();
  98. }
  99. void ScriptEditorDebugger::debug_break() {
  100. ERR_FAIL_COND(breaked);
  101. _put_msg("break", Array());
  102. }
  103. void ScriptEditorDebugger::debug_continue() {
  104. ERR_FAIL_COND(!breaked);
  105. // Allow focus stealing only if we actually run this client for security.
  106. if (remote_pid && EditorNode::get_singleton()->has_child_process(remote_pid)) {
  107. DisplayServer::get_singleton()->enable_for_stealing_focus(remote_pid);
  108. }
  109. _clear_execution();
  110. _put_msg("continue", Array());
  111. }
  112. void ScriptEditorDebugger::update_tabs() {
  113. if (error_count == 0 && warning_count == 0) {
  114. errors_tab->set_name(TTR("Errors"));
  115. tabs->set_tab_icon(errors_tab->get_index(), Ref<Texture2D>());
  116. } else {
  117. errors_tab->set_name(TTR("Errors") + " (" + itos(error_count + warning_count) + ")");
  118. if (error_count >= 1 && warning_count >= 1) {
  119. tabs->set_tab_icon(errors_tab->get_index(), get_theme_icon("ErrorWarning", "EditorIcons"));
  120. } else if (error_count >= 1) {
  121. tabs->set_tab_icon(errors_tab->get_index(), get_theme_icon("Error", "EditorIcons"));
  122. } else {
  123. tabs->set_tab_icon(errors_tab->get_index(), get_theme_icon("Warning", "EditorIcons"));
  124. }
  125. }
  126. }
  127. void ScriptEditorDebugger::clear_style() {
  128. tabs->add_theme_style_override("panel", nullptr);
  129. }
  130. void ScriptEditorDebugger::save_node(ObjectID p_id, const String &p_file) {
  131. Array msg;
  132. msg.push_back(p_id);
  133. msg.push_back(p_file);
  134. _put_msg("scene:save_node", msg);
  135. }
  136. void ScriptEditorDebugger::_file_selected(const String &p_file) {
  137. switch (file_dialog_purpose) {
  138. case SAVE_MONITORS_CSV: {
  139. Error err;
  140. FileAccessRef file = FileAccess::open(p_file, FileAccess::WRITE, &err);
  141. if (err != OK) {
  142. ERR_PRINT("Failed to open " + p_file);
  143. return;
  144. }
  145. Vector<String> line;
  146. line.resize(Performance::MONITOR_MAX);
  147. // signatures
  148. for (int i = 0; i < Performance::MONITOR_MAX; i++) {
  149. line.write[i] = Performance::get_singleton()->get_monitor_name(Performance::Monitor(i));
  150. }
  151. file->store_csv_line(line);
  152. // values
  153. Vector<List<float>::Element *> iterators;
  154. iterators.resize(Performance::MONITOR_MAX);
  155. bool continue_iteration = false;
  156. for (int i = 0; i < Performance::MONITOR_MAX; i++) {
  157. iterators.write[i] = performance_profiler->get_monitor_data(Performance::get_singleton()->get_monitor_name(Performance::Monitor(i)))->back();
  158. continue_iteration = continue_iteration || iterators[i];
  159. }
  160. while (continue_iteration) {
  161. continue_iteration = false;
  162. for (int i = 0; i < Performance::MONITOR_MAX; i++) {
  163. if (iterators[i]) {
  164. line.write[i] = String::num_real(iterators[i]->get());
  165. iterators.write[i] = iterators[i]->prev();
  166. } else {
  167. line.write[i] = "";
  168. }
  169. continue_iteration = continue_iteration || iterators[i];
  170. }
  171. file->store_csv_line(line);
  172. }
  173. file->store_string("\n");
  174. Vector<Vector<String>> profiler_data = profiler->get_data_as_csv();
  175. for (int i = 0; i < profiler_data.size(); i++) {
  176. file->store_csv_line(profiler_data[i]);
  177. }
  178. } break;
  179. case SAVE_VRAM_CSV: {
  180. Error err;
  181. FileAccessRef file = FileAccess::open(p_file, FileAccess::WRITE, &err);
  182. if (err != OK) {
  183. ERR_PRINT("Failed to open " + p_file);
  184. return;
  185. }
  186. Vector<String> headers;
  187. headers.resize(vmem_tree->get_columns());
  188. for (int i = 0; i < vmem_tree->get_columns(); ++i) {
  189. headers.write[i] = vmem_tree->get_column_title(i);
  190. }
  191. file->store_csv_line(headers);
  192. if (vmem_tree->get_root()) {
  193. TreeItem *ti = vmem_tree->get_root()->get_children();
  194. while (ti) {
  195. Vector<String> values;
  196. values.resize(vmem_tree->get_columns());
  197. for (int i = 0; i < vmem_tree->get_columns(); ++i) {
  198. values.write[i] = ti->get_text(i);
  199. }
  200. file->store_csv_line(values);
  201. ti = ti->get_next();
  202. }
  203. }
  204. } break;
  205. }
  206. }
  207. void ScriptEditorDebugger::request_remote_tree() {
  208. _put_msg("scene:request_scene_tree", Array());
  209. }
  210. const SceneDebuggerTree *ScriptEditorDebugger::get_remote_tree() {
  211. return scene_tree;
  212. }
  213. void ScriptEditorDebugger::update_remote_object(ObjectID p_obj_id, const String &p_prop, const Variant &p_value) {
  214. Array msg;
  215. msg.push_back(p_obj_id);
  216. msg.push_back(p_prop);
  217. msg.push_back(p_value);
  218. _put_msg("scene:set_object_property", msg);
  219. }
  220. void ScriptEditorDebugger::request_remote_object(ObjectID p_obj_id) {
  221. ERR_FAIL_COND(p_obj_id.is_null());
  222. Array msg;
  223. msg.push_back(p_obj_id);
  224. _put_msg("scene:inspect_object", msg);
  225. }
  226. Object *ScriptEditorDebugger::get_remote_object(ObjectID p_id) {
  227. return inspector->get_object(p_id);
  228. }
  229. void ScriptEditorDebugger::_remote_object_selected(ObjectID p_id) {
  230. emit_signal("remote_object_requested", p_id);
  231. }
  232. void ScriptEditorDebugger::_remote_object_edited(ObjectID p_id, const String &p_prop, const Variant &p_value) {
  233. update_remote_object(p_id, p_prop, p_value);
  234. request_remote_object(p_id);
  235. }
  236. void ScriptEditorDebugger::_remote_object_property_updated(ObjectID p_id, const String &p_property) {
  237. emit_signal("remote_object_property_updated", p_id, p_property);
  238. }
  239. void ScriptEditorDebugger::_video_mem_request() {
  240. _put_msg("core:memory", Array());
  241. }
  242. void ScriptEditorDebugger::_video_mem_export() {
  243. file_dialog->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE);
  244. file_dialog->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
  245. file_dialog->clear_filters();
  246. file_dialog_purpose = SAVE_VRAM_CSV;
  247. file_dialog->popup_centered_ratio();
  248. }
  249. Size2 ScriptEditorDebugger::get_minimum_size() const {
  250. Size2 ms = MarginContainer::get_minimum_size();
  251. ms.y = MAX(ms.y, 250 * EDSCALE);
  252. return ms;
  253. }
  254. void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_data) {
  255. if (p_msg == "debug_enter") {
  256. _put_msg("get_stack_dump", Array());
  257. ERR_FAIL_COND(p_data.size() != 2);
  258. bool can_continue = p_data[0];
  259. String error = p_data[1];
  260. breaked = true;
  261. can_debug = can_continue;
  262. _update_buttons_state();
  263. _set_reason_text(error, MESSAGE_ERROR);
  264. emit_signal("breaked", true, can_continue);
  265. DisplayServer::get_singleton()->window_move_to_foreground();
  266. if (error != "") {
  267. tabs->set_current_tab(0);
  268. }
  269. profiler->set_enabled(false);
  270. inspector->clear_cache(); // Take a chance to force remote objects update.
  271. } else if (p_msg == "debug_exit") {
  272. breaked = false;
  273. can_debug = false;
  274. _clear_execution();
  275. _update_buttons_state();
  276. _set_reason_text(TTR("Execution resumed."), MESSAGE_SUCCESS);
  277. emit_signal("breaked", false, false);
  278. profiler->set_enabled(true);
  279. profiler->disable_seeking();
  280. } else if (p_msg == "set_pid") {
  281. ERR_FAIL_COND(p_data.size() < 1);
  282. remote_pid = p_data[0];
  283. } else if (p_msg == "scene:click_ctrl") {
  284. ERR_FAIL_COND(p_data.size() < 2);
  285. clicked_ctrl->set_text(p_data[0]);
  286. clicked_ctrl_type->set_text(p_data[1]);
  287. } else if (p_msg == "scene:scene_tree") {
  288. scene_tree->nodes.clear();
  289. scene_tree->deserialize(p_data);
  290. emit_signal("remote_tree_updated");
  291. _update_buttons_state();
  292. } else if (p_msg == "scene:inspect_object") {
  293. ObjectID id = inspector->add_object(p_data);
  294. if (id.is_valid()) {
  295. emit_signal("remote_object_updated", id);
  296. }
  297. } else if (p_msg == "memory:usage") {
  298. vmem_tree->clear();
  299. TreeItem *root = vmem_tree->create_item();
  300. DebuggerMarshalls::ResourceUsage usage;
  301. usage.deserialize(p_data);
  302. int total = 0;
  303. for (List<DebuggerMarshalls::ResourceInfo>::Element *E = usage.infos.front(); E; E = E->next()) {
  304. TreeItem *it = vmem_tree->create_item(root);
  305. String type = E->get().type;
  306. int bytes = E->get().vram;
  307. it->set_text(0, E->get().path);
  308. it->set_text(1, type);
  309. it->set_text(2, E->get().format);
  310. it->set_text(3, String::humanize_size(bytes));
  311. total += bytes;
  312. if (has_theme_icon(type, "EditorIcons")) {
  313. it->set_icon(0, get_theme_icon(type, "EditorIcons"));
  314. }
  315. }
  316. vmem_total->set_tooltip(TTR("Bytes:") + " " + itos(total));
  317. vmem_total->set_text(String::humanize_size(total));
  318. } else if (p_msg == "stack_dump") {
  319. DebuggerMarshalls::ScriptStackDump stack;
  320. stack.deserialize(p_data);
  321. stack_dump->clear();
  322. inspector->clear_stack_variables();
  323. TreeItem *r = stack_dump->create_item();
  324. for (int i = 0; i < stack.frames.size(); i++) {
  325. TreeItem *s = stack_dump->create_item(r);
  326. Dictionary d;
  327. d["frame"] = i;
  328. d["file"] = stack.frames[i].file;
  329. d["function"] = stack.frames[i].func;
  330. d["line"] = stack.frames[i].line;
  331. s->set_metadata(0, d);
  332. String line = itos(i) + " - " + String(d["file"]) + ":" + itos(d["line"]) + " - at function: " + d["function"];
  333. s->set_text(0, line);
  334. if (i == 0) {
  335. s->select(0);
  336. }
  337. }
  338. } else if (p_msg == "stack_frame_vars") {
  339. inspector->clear_stack_variables();
  340. } else if (p_msg == "stack_frame_var") {
  341. inspector->add_stack_variable(p_data);
  342. } else if (p_msg == "output") {
  343. ERR_FAIL_COND(p_data.size() != 2);
  344. ERR_FAIL_COND(p_data[0].get_type() != Variant::PACKED_STRING_ARRAY);
  345. Vector<String> output_strings = p_data[0];
  346. ERR_FAIL_COND(p_data[1].get_type() != Variant::PACKED_INT32_ARRAY);
  347. Vector<int> output_types = p_data[1];
  348. ERR_FAIL_COND(output_strings.size() != output_types.size());
  349. for (int i = 0; i < output_strings.size(); i++) {
  350. RemoteDebugger::MessageType type = (RemoteDebugger::MessageType)(int)(output_types[i]);
  351. EditorLog::MessageType msg_type;
  352. switch (type) {
  353. case RemoteDebugger::MESSAGE_TYPE_LOG: {
  354. msg_type = EditorLog::MSG_TYPE_STD;
  355. } break;
  356. case RemoteDebugger::MESSAGE_TYPE_ERROR: {
  357. msg_type = EditorLog::MSG_TYPE_ERROR;
  358. } break;
  359. default: {
  360. WARN_PRINT("Unhandled script debugger message type: " + itos(type));
  361. msg_type = EditorLog::MSG_TYPE_STD;
  362. } break;
  363. }
  364. EditorNode::get_log()->add_message(output_strings[i], msg_type);
  365. }
  366. } else if (p_msg == "performance:profile_frame") {
  367. Vector<float> frame_data;
  368. frame_data.resize(p_data.size());
  369. for (int i = 0; i < p_data.size(); i++) {
  370. frame_data.write[i] = p_data[i];
  371. }
  372. performance_profiler->add_profile_frame(frame_data);
  373. } else if (p_msg == "visual:profile_frame") {
  374. DebuggerMarshalls::VisualProfilerFrame frame;
  375. frame.deserialize(p_data);
  376. EditorVisualProfiler::Metric metric;
  377. metric.areas.resize(frame.areas.size());
  378. metric.frame_number = frame.frame_number;
  379. metric.valid = true;
  380. {
  381. EditorVisualProfiler::Metric::Area *areas_ptr = metric.areas.ptrw();
  382. for (int i = 0; i < frame.areas.size(); i++) {
  383. areas_ptr[i].name = frame.areas[i].name;
  384. areas_ptr[i].cpu_time = frame.areas[i].cpu_msec;
  385. areas_ptr[i].gpu_time = frame.areas[i].gpu_msec;
  386. }
  387. }
  388. visual_profiler->add_frame_metric(metric);
  389. } else if (p_msg == "error") {
  390. DebuggerMarshalls::OutputError oe;
  391. ERR_FAIL_COND_MSG(oe.deserialize(p_data) == false, "Failed to deserialize error message");
  392. // Format time.
  393. Array time_vals;
  394. time_vals.push_back(oe.hr);
  395. time_vals.push_back(oe.min);
  396. time_vals.push_back(oe.sec);
  397. time_vals.push_back(oe.msec);
  398. bool e;
  399. String time = String("%d:%02d:%02d:%04d").sprintf(time_vals, &e);
  400. // Rest of the error data.
  401. bool source_is_project_file = oe.source_file.begins_with("res://");
  402. // Metadata to highlight error line in scripts.
  403. Array source_meta;
  404. source_meta.push_back(oe.source_file);
  405. source_meta.push_back(oe.source_line);
  406. // Create error tree to display above error or warning details.
  407. TreeItem *r = error_tree->get_root();
  408. if (!r) {
  409. r = error_tree->create_item();
  410. }
  411. // Also provide the relevant details as tooltip to quickly check without
  412. // uncollapsing the tree.
  413. String tooltip = oe.warning ? TTR("Warning:") : TTR("Error:");
  414. TreeItem *error = error_tree->create_item(r);
  415. error->set_collapsed(true);
  416. error->set_icon(0, get_theme_icon(oe.warning ? "Warning" : "Error", "EditorIcons"));
  417. error->set_text(0, time);
  418. error->set_text_align(0, TreeItem::ALIGN_LEFT);
  419. String error_title;
  420. // Include method name, when given, in error title.
  421. if (!oe.source_func.empty()) {
  422. error_title += oe.source_func + ": ";
  423. }
  424. // If we have a (custom) error message, use it as title, and add a C++ Error
  425. // item with the original error condition.
  426. error_title += oe.error_descr.empty() ? oe.error : oe.error_descr;
  427. error->set_text(1, error_title);
  428. tooltip += " " + error_title + "\n";
  429. if (!oe.error_descr.empty()) {
  430. // Add item for C++ error condition.
  431. TreeItem *cpp_cond = error_tree->create_item(error);
  432. cpp_cond->set_text(0, "<" + TTR("C++ Error") + ">");
  433. cpp_cond->set_text(1, oe.error);
  434. cpp_cond->set_text_align(0, TreeItem::ALIGN_LEFT);
  435. tooltip += TTR("C++ Error:") + " " + oe.error + "\n";
  436. if (source_is_project_file) {
  437. cpp_cond->set_metadata(0, source_meta);
  438. }
  439. }
  440. Vector<uint8_t> v;
  441. v.resize(100);
  442. // Source of the error.
  443. String source_txt = (source_is_project_file ? oe.source_file.get_file() : oe.source_file) + ":" + itos(oe.source_line);
  444. if (!oe.source_func.empty()) {
  445. source_txt += " @ " + oe.source_func + "()";
  446. }
  447. TreeItem *cpp_source = error_tree->create_item(error);
  448. cpp_source->set_text(0, "<" + (source_is_project_file ? TTR("Source") : TTR("C++ Source")) + ">");
  449. cpp_source->set_text(1, source_txt);
  450. cpp_source->set_text_align(0, TreeItem::ALIGN_LEFT);
  451. tooltip += (source_is_project_file ? TTR("Source:") : TTR("C++ Source:")) + " " + source_txt + "\n";
  452. // Set metadata to highlight error line in scripts.
  453. if (source_is_project_file) {
  454. error->set_metadata(0, source_meta);
  455. cpp_source->set_metadata(0, source_meta);
  456. }
  457. error->set_tooltip(0, tooltip);
  458. error->set_tooltip(1, tooltip);
  459. // Format stack trace.
  460. // stack_items_count is the number of elements to parse, with 3 items per frame
  461. // of the stack trace (script, method, line).
  462. const ScriptLanguage::StackInfo *infos = oe.callstack.ptr();
  463. for (unsigned int i = 0; i < (unsigned int)oe.callstack.size(); i++) {
  464. TreeItem *stack_trace = error_tree->create_item(error);
  465. Array meta;
  466. meta.push_back(infos[i].file);
  467. meta.push_back(infos[i].line);
  468. stack_trace->set_metadata(0, meta);
  469. if (i == 0) {
  470. stack_trace->set_text(0, "<" + TTR("Stack Trace") + ">");
  471. stack_trace->set_text_align(0, TreeItem::ALIGN_LEFT);
  472. error->set_metadata(0, meta);
  473. }
  474. stack_trace->set_text(1, infos[i].file.get_file() + ":" + itos(infos[i].line) + " @ " + infos[i].func + "()");
  475. }
  476. if (oe.warning) {
  477. warning_count++;
  478. } else {
  479. error_count++;
  480. }
  481. } else if (p_msg == "servers:function_signature") {
  482. // Cache a profiler signature.
  483. DebuggerMarshalls::ScriptFunctionSignature sig;
  484. sig.deserialize(p_data);
  485. profiler_signature[sig.id] = sig.name;
  486. } else if (p_msg == "servers:profile_frame" || p_msg == "servers:profile_total") {
  487. EditorProfiler::Metric metric;
  488. DebuggerMarshalls::ServersProfilerFrame frame;
  489. frame.deserialize(p_data);
  490. metric.valid = true;
  491. metric.frame_number = frame.frame_number;
  492. metric.frame_time = frame.frame_time;
  493. metric.idle_time = frame.idle_time;
  494. metric.physics_time = frame.physics_time;
  495. metric.physics_frame_time = frame.physics_frame_time;
  496. if (frame.servers.size()) {
  497. EditorProfiler::Metric::Category frame_time;
  498. frame_time.signature = "category_frame_time";
  499. frame_time.name = "Frame Time";
  500. frame_time.total_time = metric.frame_time;
  501. EditorProfiler::Metric::Category::Item item;
  502. item.calls = 1;
  503. item.line = 0;
  504. item.name = "Physics Time";
  505. item.total = metric.physics_time;
  506. item.self = item.total;
  507. item.signature = "physics_time";
  508. frame_time.items.push_back(item);
  509. item.name = "Idle Time";
  510. item.total = metric.idle_time;
  511. item.self = item.total;
  512. item.signature = "idle_time";
  513. frame_time.items.push_back(item);
  514. item.name = "Physics Frame Time";
  515. item.total = metric.physics_frame_time;
  516. item.self = item.total;
  517. item.signature = "physics_frame_time";
  518. frame_time.items.push_back(item);
  519. metric.categories.push_back(frame_time);
  520. }
  521. for (int i = 0; i < frame.servers.size(); i++) {
  522. const DebuggerMarshalls::ServerInfo &srv = frame.servers[i];
  523. EditorProfiler::Metric::Category c;
  524. const String name = srv.name;
  525. c.name = name.capitalize();
  526. c.items.resize(srv.functions.size());
  527. c.total_time = 0;
  528. c.signature = "categ::" + name;
  529. for (int j = 0; j < srv.functions.size(); j++) {
  530. EditorProfiler::Metric::Category::Item item;
  531. item.calls = 1;
  532. item.line = 0;
  533. item.name = srv.functions[j].name;
  534. item.self = srv.functions[j].time;
  535. item.total = item.self;
  536. item.signature = "categ::" + name + "::" + item.name;
  537. item.name = item.name.capitalize();
  538. c.total_time += item.total;
  539. c.items.write[j] = item;
  540. }
  541. metric.categories.push_back(c);
  542. }
  543. EditorProfiler::Metric::Category funcs;
  544. funcs.total_time = frame.script_time;
  545. funcs.items.resize(frame.script_functions.size());
  546. funcs.name = "Script Functions";
  547. funcs.signature = "script_functions";
  548. for (int i = 0; i < frame.script_functions.size(); i++) {
  549. int signature = frame.script_functions[i].sig_id;
  550. int calls = frame.script_functions[i].call_count;
  551. float total = frame.script_functions[i].total_time;
  552. float self = frame.script_functions[i].self_time;
  553. EditorProfiler::Metric::Category::Item item;
  554. if (profiler_signature.has(signature)) {
  555. item.signature = profiler_signature[signature];
  556. String name = profiler_signature[signature];
  557. Vector<String> strings = name.split("::");
  558. if (strings.size() == 3) {
  559. item.name = strings[2];
  560. item.script = strings[0];
  561. item.line = strings[1].to_int();
  562. } else if (strings.size() == 4) { //Built-in scripts have an :: in their name
  563. item.name = strings[3];
  564. item.script = strings[0] + "::" + strings[1];
  565. item.line = strings[2].to_int();
  566. }
  567. } else {
  568. item.name = "SigErr " + itos(signature);
  569. }
  570. item.calls = calls;
  571. item.self = self;
  572. item.total = total;
  573. funcs.items.write[i] = item;
  574. }
  575. metric.categories.push_back(funcs);
  576. if (p_msg == "servers:profile_frame") {
  577. profiler->add_frame_metric(metric, false);
  578. } else {
  579. profiler->add_frame_metric(metric, true);
  580. }
  581. } else if (p_msg == "network:profile_frame") {
  582. DebuggerMarshalls::NetworkProfilerFrame frame;
  583. frame.deserialize(p_data);
  584. for (int i = 0; i < frame.infos.size(); i++) {
  585. network_profiler->add_node_frame_data(frame.infos[i]);
  586. }
  587. } else if (p_msg == "network:bandwidth") {
  588. ERR_FAIL_COND(p_data.size() < 2);
  589. network_profiler->set_bandwidth(p_data[0], p_data[1]);
  590. } else if (p_msg == "request_quit") {
  591. emit_signal("stop_requested");
  592. _stop_and_notify();
  593. } else if (p_msg == "performance:profile_names") {
  594. Vector<StringName> monitors;
  595. monitors.resize(p_data.size());
  596. for (int i = 0; i < p_data.size(); i++) {
  597. ERR_FAIL_COND(p_data[i].get_type() != Variant::STRING_NAME);
  598. monitors.set(i, p_data[i]);
  599. }
  600. performance_profiler->update_monitors(monitors);
  601. } else {
  602. WARN_PRINT("unknown message " + p_msg);
  603. }
  604. }
  605. void ScriptEditorDebugger::_set_reason_text(const String &p_reason, MessageType p_type) {
  606. switch (p_type) {
  607. case MESSAGE_ERROR:
  608. reason->add_theme_color_override("font_color", get_theme_color("error_color", "Editor"));
  609. break;
  610. case MESSAGE_WARNING:
  611. reason->add_theme_color_override("font_color", get_theme_color("warning_color", "Editor"));
  612. break;
  613. default:
  614. reason->add_theme_color_override("font_color", get_theme_color("success_color", "Editor"));
  615. }
  616. reason->set_text(p_reason);
  617. reason->set_tooltip(p_reason.word_wrap(80));
  618. }
  619. void ScriptEditorDebugger::_notification(int p_what) {
  620. switch (p_what) {
  621. case NOTIFICATION_ENTER_TREE: {
  622. skip_breakpoints->set_icon(get_theme_icon("DebugSkipBreakpointsOff", "EditorIcons"));
  623. copy->set_icon(get_theme_icon("ActionCopy", "EditorIcons"));
  624. step->set_icon(get_theme_icon("DebugStep", "EditorIcons"));
  625. next->set_icon(get_theme_icon("DebugNext", "EditorIcons"));
  626. dobreak->set_icon(get_theme_icon("Pause", "EditorIcons"));
  627. docontinue->set_icon(get_theme_icon("DebugContinue", "EditorIcons"));
  628. le_set->connect("pressed", callable_mp(this, &ScriptEditorDebugger::_live_edit_set));
  629. le_clear->connect("pressed", callable_mp(this, &ScriptEditorDebugger::_live_edit_clear));
  630. error_tree->connect("item_selected", callable_mp(this, &ScriptEditorDebugger::_error_selected));
  631. error_tree->connect("item_activated", callable_mp(this, &ScriptEditorDebugger::_error_activated));
  632. vmem_refresh->set_icon(get_theme_icon("Reload", "EditorIcons"));
  633. vmem_export->set_icon(get_theme_icon("Save", "EditorIcons"));
  634. reason->add_theme_color_override("font_color", get_theme_color("error_color", "Editor"));
  635. } break;
  636. case NOTIFICATION_PROCESS: {
  637. if (is_session_active()) {
  638. peer->poll();
  639. if (camera_override == CameraOverride::OVERRIDE_2D) {
  640. CanvasItemEditor *editor = CanvasItemEditor::get_singleton();
  641. Dictionary state = editor->get_state();
  642. float zoom = state["zoom"];
  643. Point2 offset = state["ofs"];
  644. Transform2D transform;
  645. transform.scale_basis(Size2(zoom, zoom));
  646. transform.elements[2] = -offset * zoom;
  647. Array msg;
  648. msg.push_back(transform);
  649. _put_msg("scene:override_camera_2D:transform", msg);
  650. } else if (camera_override >= CameraOverride::OVERRIDE_3D_1) {
  651. int viewport_idx = camera_override - CameraOverride::OVERRIDE_3D_1;
  652. Node3DEditorViewport *viewport = Node3DEditor::get_singleton()->get_editor_viewport(viewport_idx);
  653. Camera3D *const cam = viewport->get_camera();
  654. Array msg;
  655. msg.push_back(cam->get_camera_transform());
  656. if (cam->get_projection() == Camera3D::PROJECTION_ORTHOGONAL) {
  657. msg.push_back(false);
  658. msg.push_back(cam->get_size());
  659. } else {
  660. msg.push_back(true);
  661. msg.push_back(cam->get_fov());
  662. }
  663. msg.push_back(cam->get_znear());
  664. msg.push_back(cam->get_zfar());
  665. _put_msg("scene:override_camera_3D:transform", msg);
  666. }
  667. }
  668. const uint64_t until = OS::get_singleton()->get_ticks_msec() + 20;
  669. while (peer.is_valid() && peer->has_message()) {
  670. Array arr = peer->get_message();
  671. if (arr.size() != 2 || arr[0].get_type() != Variant::STRING || arr[1].get_type() != Variant::ARRAY) {
  672. _stop_and_notify();
  673. ERR_FAIL_MSG("Invalid message format received from peer");
  674. }
  675. _parse_message(arr[0], arr[1]);
  676. if (OS::get_singleton()->get_ticks_msec() > until) {
  677. break;
  678. }
  679. }
  680. if (!is_session_active()) {
  681. _stop_and_notify();
  682. break;
  683. };
  684. } break;
  685. case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
  686. if (tabs->has_theme_stylebox_override("panel")) {
  687. tabs->add_theme_style_override("panel", editor->get_gui_base()->get_theme_stylebox("DebuggerPanel", "EditorStyles"));
  688. }
  689. copy->set_icon(get_theme_icon("ActionCopy", "EditorIcons"));
  690. step->set_icon(get_theme_icon("DebugStep", "EditorIcons"));
  691. next->set_icon(get_theme_icon("DebugNext", "EditorIcons"));
  692. dobreak->set_icon(get_theme_icon("Pause", "EditorIcons"));
  693. docontinue->set_icon(get_theme_icon("DebugContinue", "EditorIcons"));
  694. vmem_refresh->set_icon(get_theme_icon("Reload", "EditorIcons"));
  695. vmem_export->set_icon(get_theme_icon("Save", "EditorIcons"));
  696. } break;
  697. }
  698. }
  699. void ScriptEditorDebugger::_clear_execution() {
  700. TreeItem *ti = stack_dump->get_selected();
  701. if (!ti) {
  702. return;
  703. }
  704. Dictionary d = ti->get_metadata(0);
  705. stack_script = ResourceLoader::load(d["file"]);
  706. emit_signal("clear_execution", stack_script);
  707. stack_script.unref();
  708. stack_dump->clear();
  709. inspector->clear_stack_variables();
  710. }
  711. void ScriptEditorDebugger::start(Ref<RemoteDebuggerPeer> p_peer) {
  712. error_count = 0;
  713. warning_count = 0;
  714. stop();
  715. peer = p_peer;
  716. ERR_FAIL_COND(p_peer.is_null());
  717. performance_profiler->reset();
  718. set_process(true);
  719. breaked = false;
  720. can_debug = true;
  721. camera_override = CameraOverride::OVERRIDE_NONE;
  722. tabs->set_current_tab(0);
  723. _set_reason_text(TTR("Debug session started."), MESSAGE_SUCCESS);
  724. _update_buttons_state();
  725. }
  726. void ScriptEditorDebugger::_update_buttons_state() {
  727. const bool active = is_session_active();
  728. const bool has_editor_tree = active && editor_remote_tree && editor_remote_tree->get_selected();
  729. vmem_refresh->set_disabled(!active);
  730. step->set_disabled(!active || !breaked || !can_debug);
  731. next->set_disabled(!active || !breaked || !can_debug);
  732. copy->set_disabled(!active || !breaked);
  733. docontinue->set_disabled(!active || !breaked);
  734. dobreak->set_disabled(!active || breaked);
  735. le_clear->set_disabled(!active);
  736. le_set->set_disabled(!has_editor_tree);
  737. }
  738. void ScriptEditorDebugger::_stop_and_notify() {
  739. stop();
  740. emit_signal("stopped");
  741. _set_reason_text(TTR("Debug session closed."), MESSAGE_WARNING);
  742. }
  743. void ScriptEditorDebugger::stop() {
  744. set_process(false);
  745. breaked = false;
  746. can_debug = false;
  747. remote_pid = 0;
  748. _clear_execution();
  749. inspector->clear_cache();
  750. if (peer.is_valid()) {
  751. peer->close();
  752. peer.unref();
  753. reason->set_text("");
  754. reason->set_tooltip("");
  755. }
  756. node_path_cache.clear();
  757. res_path_cache.clear();
  758. profiler_signature.clear();
  759. inspector->edit(nullptr);
  760. _update_buttons_state();
  761. }
  762. void ScriptEditorDebugger::_profiler_activate(bool p_enable, int p_type) {
  763. Array data;
  764. data.push_back(p_enable);
  765. switch (p_type) {
  766. case PROFILER_NETWORK:
  767. _put_msg("profiler:network", data);
  768. break;
  769. case PROFILER_VISUAL:
  770. _put_msg("profiler:visual", data);
  771. break;
  772. case PROFILER_SCRIPTS_SERVERS:
  773. if (p_enable) {
  774. // Clear old script signatures. (should we move all this into the profiler?)
  775. profiler_signature.clear();
  776. // Add max funcs options to request.
  777. Array opts;
  778. int max_funcs = EditorSettings::get_singleton()->get("debugger/profiler_frame_max_functions");
  779. opts.push_back(CLAMP(max_funcs, 16, 512));
  780. data.push_back(opts);
  781. }
  782. _put_msg("profiler:servers", data);
  783. break;
  784. default:
  785. ERR_FAIL_MSG("Invalid profiler type");
  786. }
  787. }
  788. void ScriptEditorDebugger::_profiler_seeked() {
  789. if (breaked) {
  790. return;
  791. }
  792. debug_break();
  793. }
  794. void ScriptEditorDebugger::_stack_dump_frame_selected() {
  795. emit_signal("stack_frame_selected");
  796. int frame = get_stack_script_frame();
  797. if (is_session_active() && frame >= 0) {
  798. Array msg;
  799. msg.push_back(frame);
  800. _put_msg("get_stack_frame_vars", msg);
  801. } else {
  802. inspector->edit(nullptr);
  803. }
  804. }
  805. void ScriptEditorDebugger::_export_csv() {
  806. file_dialog->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE);
  807. file_dialog->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
  808. file_dialog_purpose = SAVE_MONITORS_CSV;
  809. file_dialog->popup_centered_ratio();
  810. }
  811. String ScriptEditorDebugger::get_var_value(const String &p_var) const {
  812. if (!breaked) {
  813. return String();
  814. }
  815. return inspector->get_stack_variable(p_var);
  816. }
  817. int ScriptEditorDebugger::_get_node_path_cache(const NodePath &p_path) {
  818. const int *r = node_path_cache.getptr(p_path);
  819. if (r) {
  820. return *r;
  821. }
  822. last_path_id++;
  823. node_path_cache[p_path] = last_path_id;
  824. Array msg;
  825. msg.push_back(p_path);
  826. msg.push_back(last_path_id);
  827. _put_msg("scene:live_node_path", msg);
  828. return last_path_id;
  829. }
  830. int ScriptEditorDebugger::_get_res_path_cache(const String &p_path) {
  831. Map<String, int>::Element *E = res_path_cache.find(p_path);
  832. if (E) {
  833. return E->get();
  834. }
  835. last_path_id++;
  836. res_path_cache[p_path] = last_path_id;
  837. Array msg;
  838. msg.push_back(p_path);
  839. msg.push_back(last_path_id);
  840. _put_msg("scene:live_res_path", msg);
  841. return last_path_id;
  842. }
  843. void ScriptEditorDebugger::_method_changed(Object *p_base, const StringName &p_name, VARIANT_ARG_DECLARE) {
  844. if (!p_base || !live_debug || !is_session_active() || !editor->get_edited_scene()) {
  845. return;
  846. }
  847. Node *node = Object::cast_to<Node>(p_base);
  848. VARIANT_ARGPTRS
  849. for (int i = 0; i < VARIANT_ARG_MAX; i++) {
  850. //no pointers, sorry
  851. if (argptr[i] && (argptr[i]->get_type() == Variant::OBJECT || argptr[i]->get_type() == Variant::_RID)) {
  852. return;
  853. }
  854. }
  855. if (node) {
  856. NodePath path = editor->get_edited_scene()->get_path_to(node);
  857. int pathid = _get_node_path_cache(path);
  858. Array msg;
  859. msg.push_back(pathid);
  860. msg.push_back(p_name);
  861. for (int i = 0; i < VARIANT_ARG_MAX; i++) {
  862. //no pointers, sorry
  863. msg.push_back(*argptr[i]);
  864. }
  865. _put_msg("scene:live_node_call", msg);
  866. return;
  867. }
  868. Resource *res = Object::cast_to<Resource>(p_base);
  869. if (res && res->get_path() != String()) {
  870. String respath = res->get_path();
  871. int pathid = _get_res_path_cache(respath);
  872. Array msg;
  873. msg.push_back(pathid);
  874. msg.push_back(p_name);
  875. for (int i = 0; i < VARIANT_ARG_MAX; i++) {
  876. //no pointers, sorry
  877. msg.push_back(*argptr[i]);
  878. }
  879. _put_msg("scene:live_res_call", msg);
  880. return;
  881. }
  882. }
  883. void ScriptEditorDebugger::_property_changed(Object *p_base, const StringName &p_property, const Variant &p_value) {
  884. if (!p_base || !live_debug || !editor->get_edited_scene()) {
  885. return;
  886. }
  887. Node *node = Object::cast_to<Node>(p_base);
  888. if (node) {
  889. NodePath path = editor->get_edited_scene()->get_path_to(node);
  890. int pathid = _get_node_path_cache(path);
  891. if (p_value.is_ref()) {
  892. Ref<Resource> res = p_value;
  893. if (res.is_valid() && res->get_path() != String()) {
  894. Array msg;
  895. msg.push_back(pathid);
  896. msg.push_back(p_property);
  897. msg.push_back(res->get_path());
  898. _put_msg("scene:live_node_prop_res", msg);
  899. }
  900. } else {
  901. Array msg;
  902. msg.push_back(pathid);
  903. msg.push_back(p_property);
  904. msg.push_back(p_value);
  905. _put_msg("scene:live_node_prop", msg);
  906. }
  907. return;
  908. }
  909. Resource *res = Object::cast_to<Resource>(p_base);
  910. if (res && res->get_path() != String()) {
  911. String respath = res->get_path();
  912. int pathid = _get_res_path_cache(respath);
  913. if (p_value.is_ref()) {
  914. Ref<Resource> res2 = p_value;
  915. if (res2.is_valid() && res2->get_path() != String()) {
  916. Array msg;
  917. msg.push_back(pathid);
  918. msg.push_back(p_property);
  919. msg.push_back(res2->get_path());
  920. _put_msg("scene:live_res_prop_res", msg);
  921. }
  922. } else {
  923. Array msg;
  924. msg.push_back(pathid);
  925. msg.push_back(p_property);
  926. msg.push_back(p_value);
  927. _put_msg("scene:live_res_prop", msg);
  928. }
  929. return;
  930. }
  931. }
  932. String ScriptEditorDebugger::get_stack_script_file() const {
  933. TreeItem *ti = stack_dump->get_selected();
  934. if (!ti) {
  935. return "";
  936. }
  937. Dictionary d = ti->get_metadata(0);
  938. return d["file"];
  939. }
  940. int ScriptEditorDebugger::get_stack_script_line() const {
  941. TreeItem *ti = stack_dump->get_selected();
  942. if (!ti) {
  943. return -1;
  944. }
  945. Dictionary d = ti->get_metadata(0);
  946. return d["line"];
  947. }
  948. int ScriptEditorDebugger::get_stack_script_frame() const {
  949. TreeItem *ti = stack_dump->get_selected();
  950. if (!ti) {
  951. return -1;
  952. }
  953. Dictionary d = ti->get_metadata(0);
  954. return d["frame"];
  955. }
  956. void ScriptEditorDebugger::set_live_debugging(bool p_enable) {
  957. live_debug = p_enable;
  958. }
  959. void ScriptEditorDebugger::_live_edit_set() {
  960. if (!is_session_active() || !editor_remote_tree) {
  961. return;
  962. }
  963. TreeItem *ti = editor_remote_tree->get_selected();
  964. if (!ti) {
  965. return;
  966. }
  967. String path;
  968. while (ti) {
  969. String lp = ti->get_text(0);
  970. path = "/" + lp + path;
  971. ti = ti->get_parent();
  972. }
  973. NodePath np = path;
  974. editor->get_editor_data().set_edited_scene_live_edit_root(np);
  975. update_live_edit_root();
  976. }
  977. void ScriptEditorDebugger::_live_edit_clear() {
  978. NodePath np = NodePath("/root");
  979. editor->get_editor_data().set_edited_scene_live_edit_root(np);
  980. update_live_edit_root();
  981. }
  982. void ScriptEditorDebugger::update_live_edit_root() {
  983. NodePath np = editor->get_editor_data().get_edited_scene_live_edit_root();
  984. Array msg;
  985. msg.push_back(np);
  986. if (editor->get_edited_scene()) {
  987. msg.push_back(editor->get_edited_scene()->get_filename());
  988. } else {
  989. msg.push_back("");
  990. }
  991. _put_msg("scene:live_set_root", msg);
  992. live_edit_root->set_text(np);
  993. }
  994. void ScriptEditorDebugger::live_debug_create_node(const NodePath &p_parent, const String &p_type, const String &p_name) {
  995. if (live_debug) {
  996. Array msg;
  997. msg.push_back(p_parent);
  998. msg.push_back(p_type);
  999. msg.push_back(p_name);
  1000. _put_msg("scene:live_create_node", msg);
  1001. }
  1002. }
  1003. void ScriptEditorDebugger::live_debug_instance_node(const NodePath &p_parent, const String &p_path, const String &p_name) {
  1004. if (live_debug) {
  1005. Array msg;
  1006. msg.push_back(p_parent);
  1007. msg.push_back(p_path);
  1008. msg.push_back(p_name);
  1009. _put_msg("scene:live_instance_node", msg);
  1010. }
  1011. }
  1012. void ScriptEditorDebugger::live_debug_remove_node(const NodePath &p_at) {
  1013. if (live_debug) {
  1014. Array msg;
  1015. msg.push_back(p_at);
  1016. _put_msg("scene:live_remove_node", msg);
  1017. }
  1018. }
  1019. void ScriptEditorDebugger::live_debug_remove_and_keep_node(const NodePath &p_at, ObjectID p_keep_id) {
  1020. if (live_debug) {
  1021. Array msg;
  1022. msg.push_back(p_at);
  1023. msg.push_back(p_keep_id);
  1024. _put_msg("scene:live_remove_and_keep_node", msg);
  1025. }
  1026. }
  1027. void ScriptEditorDebugger::live_debug_restore_node(ObjectID p_id, const NodePath &p_at, int p_at_pos) {
  1028. if (live_debug) {
  1029. Array msg;
  1030. msg.push_back(p_id);
  1031. msg.push_back(p_at);
  1032. msg.push_back(p_at_pos);
  1033. _put_msg("scene:live_restore_node", msg);
  1034. }
  1035. }
  1036. void ScriptEditorDebugger::live_debug_duplicate_node(const NodePath &p_at, const String &p_new_name) {
  1037. if (live_debug) {
  1038. Array msg;
  1039. msg.push_back(p_at);
  1040. msg.push_back(p_new_name);
  1041. _put_msg("scene:live_duplicate_node", msg);
  1042. }
  1043. }
  1044. void ScriptEditorDebugger::live_debug_reparent_node(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos) {
  1045. if (live_debug) {
  1046. Array msg;
  1047. msg.push_back(p_at);
  1048. msg.push_back(p_new_place);
  1049. msg.push_back(p_new_name);
  1050. msg.push_back(p_at_pos);
  1051. _put_msg("scene:live_reparent_node", msg);
  1052. }
  1053. }
  1054. CameraOverride ScriptEditorDebugger::get_camera_override() const {
  1055. return camera_override;
  1056. }
  1057. void ScriptEditorDebugger::set_camera_override(CameraOverride p_override) {
  1058. if (p_override == CameraOverride::OVERRIDE_2D && camera_override != CameraOverride::OVERRIDE_2D) {
  1059. Array msg;
  1060. msg.push_back(true);
  1061. _put_msg("scene:override_camera_2D:set", msg);
  1062. } else if (p_override != CameraOverride::OVERRIDE_2D && camera_override == CameraOverride::OVERRIDE_2D) {
  1063. Array msg;
  1064. msg.push_back(false);
  1065. _put_msg("scene:override_camera_2D:set", msg);
  1066. } else if (p_override >= CameraOverride::OVERRIDE_3D_1 && camera_override < CameraOverride::OVERRIDE_3D_1) {
  1067. Array msg;
  1068. msg.push_back(true);
  1069. _put_msg("scene:override_camera_3D:set", msg);
  1070. } else if (p_override < CameraOverride::OVERRIDE_3D_1 && camera_override >= CameraOverride::OVERRIDE_3D_1) {
  1071. Array msg;
  1072. msg.push_back(false);
  1073. _put_msg("scene:override_camera_3D:set", msg);
  1074. }
  1075. camera_override = p_override;
  1076. }
  1077. void ScriptEditorDebugger::set_breakpoint(const String &p_path, int p_line, bool p_enabled) {
  1078. Array msg;
  1079. msg.push_back(p_path);
  1080. msg.push_back(p_line);
  1081. msg.push_back(p_enabled);
  1082. _put_msg("breakpoint", msg);
  1083. }
  1084. void ScriptEditorDebugger::reload_scripts() {
  1085. _put_msg("reload_scripts", Array());
  1086. }
  1087. bool ScriptEditorDebugger::is_skip_breakpoints() {
  1088. return skip_breakpoints_value;
  1089. }
  1090. void ScriptEditorDebugger::_error_activated() {
  1091. TreeItem *selected = error_tree->get_selected();
  1092. TreeItem *ci = selected->get_children();
  1093. if (ci) {
  1094. selected->set_collapsed(!selected->is_collapsed());
  1095. }
  1096. }
  1097. void ScriptEditorDebugger::_error_selected() {
  1098. TreeItem *selected = error_tree->get_selected();
  1099. Array meta = selected->get_metadata(0);
  1100. if (meta.size() == 0) {
  1101. return;
  1102. }
  1103. emit_signal("error_selected", String(meta[0]), int(meta[1]));
  1104. }
  1105. void ScriptEditorDebugger::_expand_errors_list() {
  1106. TreeItem *root = error_tree->get_root();
  1107. if (!root) {
  1108. return;
  1109. }
  1110. TreeItem *item = root->get_children();
  1111. while (item) {
  1112. item->set_collapsed(false);
  1113. item = item->get_next();
  1114. }
  1115. }
  1116. void ScriptEditorDebugger::_collapse_errors_list() {
  1117. TreeItem *root = error_tree->get_root();
  1118. if (!root) {
  1119. return;
  1120. }
  1121. TreeItem *item = root->get_children();
  1122. while (item) {
  1123. item->set_collapsed(true);
  1124. item = item->get_next();
  1125. }
  1126. }
  1127. void ScriptEditorDebugger::_clear_errors_list() {
  1128. error_tree->clear();
  1129. error_count = 0;
  1130. warning_count = 0;
  1131. }
  1132. // Right click on specific file(s) or folder(s).
  1133. void ScriptEditorDebugger::_error_tree_item_rmb_selected(const Vector2 &p_pos) {
  1134. item_menu->clear();
  1135. item_menu->set_size(Size2(1, 1));
  1136. if (error_tree->is_anything_selected()) {
  1137. item_menu->add_icon_item(get_theme_icon("ActionCopy", "EditorIcons"), TTR("Copy Error"), 0);
  1138. }
  1139. if (item_menu->get_item_count() > 0) {
  1140. item_menu->set_position(error_tree->get_global_position() + p_pos);
  1141. item_menu->popup();
  1142. }
  1143. }
  1144. void ScriptEditorDebugger::_item_menu_id_pressed(int p_option) {
  1145. TreeItem *ti = error_tree->get_selected();
  1146. while (ti->get_parent() != error_tree->get_root()) {
  1147. ti = ti->get_parent();
  1148. }
  1149. String type;
  1150. if (ti->get_icon(0) == get_theme_icon("Warning", "EditorIcons")) {
  1151. type = "W ";
  1152. } else if (ti->get_icon(0) == get_theme_icon("Error", "EditorIcons")) {
  1153. type = "E ";
  1154. }
  1155. String text = ti->get_text(0) + " ";
  1156. int rpad_len = text.length();
  1157. text = type + text + ti->get_text(1) + "\n";
  1158. TreeItem *ci = ti->get_children();
  1159. while (ci) {
  1160. text += " " + ci->get_text(0).rpad(rpad_len) + ci->get_text(1) + "\n";
  1161. ci = ci->get_next();
  1162. }
  1163. DisplayServer::get_singleton()->clipboard_set(text);
  1164. }
  1165. void ScriptEditorDebugger::_tab_changed(int p_tab) {
  1166. if (tabs->get_tab_title(p_tab) == TTR("Video RAM")) {
  1167. // "Video RAM" tab was clicked, refresh the data it's displaying when entering the tab.
  1168. _video_mem_request();
  1169. }
  1170. }
  1171. void ScriptEditorDebugger::_bind_methods() {
  1172. ClassDB::bind_method(D_METHOD("live_debug_create_node"), &ScriptEditorDebugger::live_debug_create_node);
  1173. ClassDB::bind_method(D_METHOD("live_debug_instance_node"), &ScriptEditorDebugger::live_debug_instance_node);
  1174. ClassDB::bind_method(D_METHOD("live_debug_remove_node"), &ScriptEditorDebugger::live_debug_remove_node);
  1175. ClassDB::bind_method(D_METHOD("live_debug_remove_and_keep_node"), &ScriptEditorDebugger::live_debug_remove_and_keep_node);
  1176. ClassDB::bind_method(D_METHOD("live_debug_restore_node"), &ScriptEditorDebugger::live_debug_restore_node);
  1177. ClassDB::bind_method(D_METHOD("live_debug_duplicate_node"), &ScriptEditorDebugger::live_debug_duplicate_node);
  1178. ClassDB::bind_method(D_METHOD("live_debug_reparent_node"), &ScriptEditorDebugger::live_debug_reparent_node);
  1179. ClassDB::bind_method(D_METHOD("request_remote_object", "id"), &ScriptEditorDebugger::request_remote_object);
  1180. ClassDB::bind_method(D_METHOD("update_remote_object", "id", "property", "value"), &ScriptEditorDebugger::update_remote_object);
  1181. ADD_SIGNAL(MethodInfo("stopped"));
  1182. ADD_SIGNAL(MethodInfo("stop_requested"));
  1183. ADD_SIGNAL(MethodInfo("stack_frame_selected", PropertyInfo(Variant::INT, "frame")));
  1184. ADD_SIGNAL(MethodInfo("error_selected", PropertyInfo(Variant::INT, "error")));
  1185. ADD_SIGNAL(MethodInfo("set_execution", PropertyInfo("script"), PropertyInfo(Variant::INT, "line")));
  1186. ADD_SIGNAL(MethodInfo("clear_execution", PropertyInfo("script")));
  1187. ADD_SIGNAL(MethodInfo("breaked", PropertyInfo(Variant::BOOL, "reallydid"), PropertyInfo(Variant::BOOL, "can_debug")));
  1188. ADD_SIGNAL(MethodInfo("remote_object_requested", PropertyInfo(Variant::INT, "id")));
  1189. ADD_SIGNAL(MethodInfo("remote_object_updated", PropertyInfo(Variant::INT, "id")));
  1190. ADD_SIGNAL(MethodInfo("remote_object_property_updated", PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::STRING, "property")));
  1191. ADD_SIGNAL(MethodInfo("remote_tree_updated"));
  1192. }
  1193. ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor) {
  1194. editor = p_editor;
  1195. tabs = memnew(TabContainer);
  1196. tabs->set_tab_align(TabContainer::ALIGN_LEFT);
  1197. tabs->add_theme_style_override("panel", editor->get_gui_base()->get_theme_stylebox("DebuggerPanel", "EditorStyles"));
  1198. tabs->connect("tab_changed", callable_mp(this, &ScriptEditorDebugger::_tab_changed));
  1199. add_child(tabs);
  1200. { //debugger
  1201. VBoxContainer *vbc = memnew(VBoxContainer);
  1202. vbc->set_name(TTR("Debugger"));
  1203. Control *dbg = vbc;
  1204. HBoxContainer *hbc = memnew(HBoxContainer);
  1205. vbc->add_child(hbc);
  1206. reason = memnew(Label);
  1207. reason->set_text("");
  1208. hbc->add_child(reason);
  1209. reason->set_h_size_flags(SIZE_EXPAND_FILL);
  1210. reason->set_autowrap(true);
  1211. reason->set_max_lines_visible(3);
  1212. reason->set_mouse_filter(Control::MOUSE_FILTER_PASS);
  1213. hbc->add_child(memnew(VSeparator));
  1214. skip_breakpoints = memnew(Button);
  1215. skip_breakpoints->set_flat(true);
  1216. hbc->add_child(skip_breakpoints);
  1217. skip_breakpoints->set_tooltip(TTR("Skip Breakpoints"));
  1218. skip_breakpoints->connect("pressed", callable_mp(this, &ScriptEditorDebugger::debug_skip_breakpoints));
  1219. hbc->add_child(memnew(VSeparator));
  1220. copy = memnew(Button);
  1221. copy->set_flat(true);
  1222. hbc->add_child(copy);
  1223. copy->set_tooltip(TTR("Copy Error"));
  1224. copy->connect("pressed", callable_mp(this, &ScriptEditorDebugger::debug_copy));
  1225. hbc->add_child(memnew(VSeparator));
  1226. step = memnew(Button);
  1227. step->set_flat(true);
  1228. hbc->add_child(step);
  1229. step->set_tooltip(TTR("Step Into"));
  1230. step->set_shortcut(ED_GET_SHORTCUT("debugger/step_into"));
  1231. step->connect("pressed", callable_mp(this, &ScriptEditorDebugger::debug_step));
  1232. next = memnew(Button);
  1233. next->set_flat(true);
  1234. hbc->add_child(next);
  1235. next->set_tooltip(TTR("Step Over"));
  1236. next->set_shortcut(ED_GET_SHORTCUT("debugger/step_over"));
  1237. next->connect("pressed", callable_mp(this, &ScriptEditorDebugger::debug_next));
  1238. hbc->add_child(memnew(VSeparator));
  1239. dobreak = memnew(Button);
  1240. dobreak->set_flat(true);
  1241. hbc->add_child(dobreak);
  1242. dobreak->set_tooltip(TTR("Break"));
  1243. dobreak->set_shortcut(ED_GET_SHORTCUT("debugger/break"));
  1244. dobreak->connect("pressed", callable_mp(this, &ScriptEditorDebugger::debug_break));
  1245. docontinue = memnew(Button);
  1246. docontinue->set_flat(true);
  1247. hbc->add_child(docontinue);
  1248. docontinue->set_tooltip(TTR("Continue"));
  1249. docontinue->set_shortcut(ED_GET_SHORTCUT("debugger/continue"));
  1250. docontinue->connect("pressed", callable_mp(this, &ScriptEditorDebugger::debug_continue));
  1251. HSplitContainer *sc = memnew(HSplitContainer);
  1252. vbc->add_child(sc);
  1253. sc->set_v_size_flags(SIZE_EXPAND_FILL);
  1254. stack_dump = memnew(Tree);
  1255. stack_dump->set_allow_reselect(true);
  1256. stack_dump->set_columns(1);
  1257. stack_dump->set_column_titles_visible(true);
  1258. stack_dump->set_column_title(0, TTR("Stack Frames"));
  1259. stack_dump->set_h_size_flags(SIZE_EXPAND_FILL);
  1260. stack_dump->set_hide_root(true);
  1261. stack_dump->connect("cell_selected", callable_mp(this, &ScriptEditorDebugger::_stack_dump_frame_selected));
  1262. sc->add_child(stack_dump);
  1263. inspector = memnew(EditorDebuggerInspector);
  1264. inspector->set_h_size_flags(SIZE_EXPAND_FILL);
  1265. inspector->set_enable_capitalize_paths(false);
  1266. inspector->set_read_only(true);
  1267. inspector->connect("object_selected", callable_mp(this, &ScriptEditorDebugger::_remote_object_selected));
  1268. inspector->connect("object_edited", callable_mp(this, &ScriptEditorDebugger::_remote_object_edited));
  1269. inspector->connect("object_property_updated", callable_mp(this, &ScriptEditorDebugger::_remote_object_property_updated));
  1270. sc->add_child(inspector);
  1271. tabs->add_child(dbg);
  1272. }
  1273. { //errors
  1274. errors_tab = memnew(VBoxContainer);
  1275. errors_tab->set_name(TTR("Errors"));
  1276. HBoxContainer *errhb = memnew(HBoxContainer);
  1277. errors_tab->add_child(errhb);
  1278. Button *expand_all = memnew(Button);
  1279. expand_all->set_text(TTR("Expand All"));
  1280. expand_all->connect("pressed", callable_mp(this, &ScriptEditorDebugger::_expand_errors_list));
  1281. errhb->add_child(expand_all);
  1282. Button *collapse_all = memnew(Button);
  1283. collapse_all->set_text(TTR("Collapse All"));
  1284. collapse_all->connect("pressed", callable_mp(this, &ScriptEditorDebugger::_collapse_errors_list));
  1285. errhb->add_child(collapse_all);
  1286. Control *space = memnew(Control);
  1287. space->set_h_size_flags(SIZE_EXPAND_FILL);
  1288. errhb->add_child(space);
  1289. clearbutton = memnew(Button);
  1290. clearbutton->set_text(TTR("Clear"));
  1291. clearbutton->set_h_size_flags(0);
  1292. clearbutton->connect("pressed", callable_mp(this, &ScriptEditorDebugger::_clear_errors_list));
  1293. errhb->add_child(clearbutton);
  1294. error_tree = memnew(Tree);
  1295. error_tree->set_columns(2);
  1296. error_tree->set_column_expand(0, false);
  1297. error_tree->set_column_min_width(0, 140);
  1298. error_tree->set_column_expand(1, true);
  1299. error_tree->set_select_mode(Tree::SELECT_ROW);
  1300. error_tree->set_hide_root(true);
  1301. error_tree->set_v_size_flags(SIZE_EXPAND_FILL);
  1302. error_tree->set_allow_rmb_select(true);
  1303. error_tree->connect("item_rmb_selected", callable_mp(this, &ScriptEditorDebugger::_error_tree_item_rmb_selected));
  1304. errors_tab->add_child(error_tree);
  1305. item_menu = memnew(PopupMenu);
  1306. item_menu->connect("id_pressed", callable_mp(this, &ScriptEditorDebugger::_item_menu_id_pressed));
  1307. error_tree->add_child(item_menu);
  1308. tabs->add_child(errors_tab);
  1309. }
  1310. { // File dialog
  1311. file_dialog = memnew(EditorFileDialog);
  1312. file_dialog->connect("file_selected", callable_mp(this, &ScriptEditorDebugger::_file_selected));
  1313. add_child(file_dialog);
  1314. }
  1315. { //profiler
  1316. profiler = memnew(EditorProfiler);
  1317. profiler->set_name(TTR("Profiler"));
  1318. tabs->add_child(profiler);
  1319. profiler->connect("enable_profiling", callable_mp(this, &ScriptEditorDebugger::_profiler_activate), varray(PROFILER_SCRIPTS_SERVERS));
  1320. profiler->connect("break_request", callable_mp(this, &ScriptEditorDebugger::_profiler_seeked));
  1321. }
  1322. { //frame profiler
  1323. visual_profiler = memnew(EditorVisualProfiler);
  1324. visual_profiler->set_name(TTR("Visual Profiler"));
  1325. tabs->add_child(visual_profiler);
  1326. visual_profiler->connect("enable_profiling", callable_mp(this, &ScriptEditorDebugger::_profiler_activate), varray(PROFILER_VISUAL));
  1327. }
  1328. { //network profiler
  1329. network_profiler = memnew(EditorNetworkProfiler);
  1330. network_profiler->set_name(TTR("Network Profiler"));
  1331. tabs->add_child(network_profiler);
  1332. network_profiler->connect("enable_profiling", callable_mp(this, &ScriptEditorDebugger::_profiler_activate), varray(PROFILER_NETWORK));
  1333. }
  1334. { //monitors
  1335. performance_profiler = memnew(EditorPerformanceProfiler);
  1336. tabs->add_child(performance_profiler);
  1337. }
  1338. { //vmem inspect
  1339. VBoxContainer *vmem_vb = memnew(VBoxContainer);
  1340. HBoxContainer *vmem_hb = memnew(HBoxContainer);
  1341. Label *vmlb = memnew(Label(TTR("List of Video Memory Usage by Resource:") + " "));
  1342. vmlb->set_h_size_flags(SIZE_EXPAND_FILL);
  1343. vmem_hb->add_child(vmlb);
  1344. vmem_hb->add_child(memnew(Label(TTR("Total:") + " ")));
  1345. vmem_total = memnew(LineEdit);
  1346. vmem_total->set_editable(false);
  1347. vmem_total->set_custom_minimum_size(Size2(100, 0) * EDSCALE);
  1348. vmem_hb->add_child(vmem_total);
  1349. vmem_refresh = memnew(Button);
  1350. vmem_refresh->set_flat(true);
  1351. vmem_hb->add_child(vmem_refresh);
  1352. vmem_export = memnew(Button);
  1353. vmem_export->set_flat(true);
  1354. vmem_export->set_tooltip(TTR("Export list to a CSV file"));
  1355. vmem_hb->add_child(vmem_export);
  1356. vmem_vb->add_child(vmem_hb);
  1357. vmem_refresh->connect("pressed", callable_mp(this, &ScriptEditorDebugger::_video_mem_request));
  1358. vmem_export->connect("pressed", callable_mp(this, &ScriptEditorDebugger::_video_mem_export));
  1359. VBoxContainer *vmmc = memnew(VBoxContainer);
  1360. vmem_tree = memnew(Tree);
  1361. vmem_tree->set_v_size_flags(SIZE_EXPAND_FILL);
  1362. vmem_tree->set_h_size_flags(SIZE_EXPAND_FILL);
  1363. vmmc->add_child(vmem_tree);
  1364. vmmc->set_v_size_flags(SIZE_EXPAND_FILL);
  1365. vmem_vb->add_child(vmmc);
  1366. vmem_vb->set_name(TTR("Video RAM"));
  1367. vmem_tree->set_columns(4);
  1368. vmem_tree->set_column_titles_visible(true);
  1369. vmem_tree->set_column_title(0, TTR("Resource Path"));
  1370. vmem_tree->set_column_expand(0, true);
  1371. vmem_tree->set_column_expand(1, false);
  1372. vmem_tree->set_column_title(1, TTR("Type"));
  1373. vmem_tree->set_column_min_width(1, 100 * EDSCALE);
  1374. vmem_tree->set_column_expand(2, false);
  1375. vmem_tree->set_column_title(2, TTR("Format"));
  1376. vmem_tree->set_column_min_width(2, 150 * EDSCALE);
  1377. vmem_tree->set_column_expand(3, false);
  1378. vmem_tree->set_column_title(3, TTR("Usage"));
  1379. vmem_tree->set_column_min_width(3, 80 * EDSCALE);
  1380. vmem_tree->set_hide_root(true);
  1381. tabs->add_child(vmem_vb);
  1382. }
  1383. { // misc
  1384. VBoxContainer *misc = memnew(VBoxContainer);
  1385. misc->set_name(TTR("Misc"));
  1386. tabs->add_child(misc);
  1387. GridContainer *info_left = memnew(GridContainer);
  1388. info_left->set_columns(2);
  1389. misc->add_child(info_left);
  1390. clicked_ctrl = memnew(LineEdit);
  1391. clicked_ctrl->set_h_size_flags(SIZE_EXPAND_FILL);
  1392. info_left->add_child(memnew(Label(TTR("Clicked Control:"))));
  1393. info_left->add_child(clicked_ctrl);
  1394. clicked_ctrl_type = memnew(LineEdit);
  1395. info_left->add_child(memnew(Label(TTR("Clicked Control Type:"))));
  1396. info_left->add_child(clicked_ctrl_type);
  1397. scene_tree = memnew(SceneDebuggerTree);
  1398. live_edit_root = memnew(LineEdit);
  1399. live_edit_root->set_h_size_flags(SIZE_EXPAND_FILL);
  1400. {
  1401. HBoxContainer *lehb = memnew(HBoxContainer);
  1402. Label *l = memnew(Label(TTR("Live Edit Root:")));
  1403. info_left->add_child(l);
  1404. lehb->add_child(live_edit_root);
  1405. le_set = memnew(Button(TTR("Set From Tree")));
  1406. lehb->add_child(le_set);
  1407. le_clear = memnew(Button(TTR("Clear")));
  1408. lehb->add_child(le_clear);
  1409. info_left->add_child(lehb);
  1410. }
  1411. misc->add_child(memnew(VSeparator));
  1412. HBoxContainer *buttons = memnew(HBoxContainer);
  1413. export_csv = memnew(Button(TTR("Export measures as CSV")));
  1414. export_csv->connect("pressed", callable_mp(this, &ScriptEditorDebugger::_export_csv));
  1415. buttons->add_child(export_csv);
  1416. misc->add_child(buttons);
  1417. }
  1418. msgdialog = memnew(AcceptDialog);
  1419. add_child(msgdialog);
  1420. live_debug = true;
  1421. camera_override = CameraOverride::OVERRIDE_NONE;
  1422. last_path_id = false;
  1423. error_count = 0;
  1424. warning_count = 0;
  1425. _update_buttons_state();
  1426. }
  1427. ScriptEditorDebugger::~ScriptEditorDebugger() {
  1428. if (peer.is_valid()) {
  1429. peer->close();
  1430. peer.unref();
  1431. }
  1432. memdelete(scene_tree);
  1433. }