1
0
mirror of https://github.com/godotengine/godot.git synced 2026-01-05 19:31:35 +00:00

Fix GameStateSnapshots not being freed

Updated GameStateSnapshot to inherit from RefCounted, to be automatically deleted when reference count reaches zero, and removed GameStateSnapshotRef wrapper class.
This commit is contained in:
aaronp64
2025-11-30 12:48:09 -05:00
parent 7ed0b61676
commit ed6181c943
4 changed files with 25 additions and 49 deletions

View File

@@ -41,7 +41,9 @@
#include "core/os/time.h"
#include "editor/debugger/editor_debugger_node.h"
#include "editor/debugger/script_editor_debugger.h"
#include "editor/docks/inspector_dock.h"
#include "editor/editor_node.h"
#include "editor/inspector/editor_inspector.h"
#include "editor/themes/editor_scale.h"
#include "scene/gui/button.h"
#include "scene/gui/label.h"
@@ -167,7 +169,7 @@ TreeItem *ObjectDBProfilerPanel::_add_snapshot_button(const String &p_snapshot_f
void ObjectDBProfilerPanel::_show_selected_snapshot() {
if (snapshot_list->get_selected()->get_text(0) == (String)diff_button->get_selected_metadata()) {
for (int i = 0; i < diff_button->get_item_count(); i++) {
if (diff_button->get_item_text(i) == current_snapshot->get_snapshot()->name) {
if (diff_button->get_item_text(i) == current_snapshot->name) {
diff_button->select(i);
break;
}
@@ -184,7 +186,7 @@ void ObjectDBProfilerPanel::_on_snapshot_deselected() {
_update_enabled_diff_items();
}
Ref<GameStateSnapshotRef> ObjectDBProfilerPanel::get_snapshot(const String &p_snapshot_file_name) {
Ref<GameStateSnapshot> ObjectDBProfilerPanel::get_snapshot(const String &p_snapshot_file_name) {
if (snapshot_cache.has(p_snapshot_file_name)) {
return snapshot_cache.get(p_snapshot_file_name);
}
@@ -201,7 +203,7 @@ Ref<GameStateSnapshotRef> ObjectDBProfilerPanel::get_snapshot(const String &p_sn
Vector<uint8_t> content = snapshot_file->get_buffer(snapshot_file->get_length()); // We want to split on newlines, so normalize them.
ERR_FAIL_COND_V_MSG(content.is_empty(), nullptr, "ObjectDB Snapshot file is empty: " + full_file_path);
Ref<GameStateSnapshotRef> snapshot = GameStateSnapshot::create_ref(p_snapshot_file_name, content);
Ref<GameStateSnapshot> snapshot = GameStateSnapshot::create_ref(p_snapshot_file_name, content);
if (snapshot.is_valid()) {
snapshot_cache.insert(p_snapshot_file_name, snapshot);
}
@@ -225,8 +227,8 @@ void ObjectDBProfilerPanel::_view_tab_changed(int p_tab_idx) {
// Populating tabs only on tab changed because we're handling a lot of data,
// and the editor freezes for a while if we try to populate every tab at once.
SnapshotView *view = cast_to<SnapshotView>(view_tabs->get_current_tab_control());
GameStateSnapshot *snapshot = current_snapshot.is_null() ? nullptr : current_snapshot->get_snapshot();
GameStateSnapshot *diff = diff_snapshot.is_null() ? nullptr : diff_snapshot->get_snapshot();
GameStateSnapshot *snapshot = current_snapshot.ptr();
GameStateSnapshot *diff = diff_snapshot.ptr();
if (snapshot != nullptr && !view->is_showing_snapshot(snapshot, diff)) {
view->show_snapshot(snapshot, diff);
}
@@ -237,6 +239,11 @@ void ObjectDBProfilerPanel::clear_snapshot(bool p_update_view_tabs) {
view->clear_snapshot();
}
const Object *edited_object = InspectorDock::get_inspector_singleton()->get_edited_object();
if (Object::cast_to<SnapshotDataObject>(edited_object)) {
EditorNode::get_singleton()->push_item(nullptr);
}
current_snapshot.unref();
diff_snapshot.unref();
@@ -333,7 +340,7 @@ void ObjectDBProfilerPanel::_edit_snapshot_name() {
ObjectDBProfilerPanel::ObjectDBProfilerPanel() {
set_name(TTRC("ObjectDB Profiler"));
snapshot_cache = LRUCache<String, Ref<GameStateSnapshotRef>>(SNAPSHOT_CACHE_MAX_SIZE);
snapshot_cache = LRUCache<String, Ref<GameStateSnapshot>>(SNAPSHOT_CACHE_MAX_SIZE);
EditorDebuggerNode::get_singleton()->get_current_debugger()->connect("breaked", callable_mp(this, &ObjectDBProfilerPanel::_on_debug_breaked));