Skip to content

Commit

Permalink
Added a warning about the need to delete DD3D_WorldWatcher when sav…
Browse files Browse the repository at this point in the history
…ing a SubViewport with OwnWorld to a file if it was used in the editor.
  • Loading branch information
DmitriySalnikov committed Mar 31, 2024
1 parent ab3718c commit e445674
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
19 changes: 13 additions & 6 deletions src/3d/debug_draw_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ GODOT_WARNING_RESTORE()
#define NEED_LEAVE (!_is_enabled_override())

#ifndef DISABLE_DEBUG_RENDERING
void _DD3D_WorldWatcher::init(DebugDraw3D *p_root, uint64_t p_world_id) {
m_owner = p_root;
m_world_id = p_world_id;
void _DD3D_WorldWatcher::_process(double p_delta) {
set_process(false);
if (!m_owner) {
PRINT_WARNING("{0} is an internal DebugDraw3D node. Remove it from your scene to avoid crashes in the future.", get_name());
}
}

void _DD3D_WorldWatcher::_notification(int p_what) {
if (p_what == NOTIFICATION_EXIT_WORLD && m_owner) {
if ((p_what == NOTIFICATION_EXIT_WORLD || p_what == NOTIFICATION_EXIT_TREE) && m_owner) {
m_owner->_remove_debug_container(m_world_id);
m_owner = nullptr;

if (!is_queued_for_deletion()) {
if (get_parent()) {
Expand All @@ -34,6 +37,11 @@ void _DD3D_WorldWatcher::_notification(int p_what) {
}
}
}

_DD3D_WorldWatcher::_DD3D_WorldWatcher(DebugDraw3D *p_root, uint64_t p_world_id) {
m_owner = p_root;
m_world_id = p_world_id;
}
#endif

DebugDraw3D *DebugDraw3D::singleton = nullptr;
Expand Down Expand Up @@ -334,10 +342,9 @@ void DebugDraw3D::_register_viewport_world_deferred(Viewport *p_vp, const uint64
return;
}

auto watcher = memnew(_DD3D_WorldWatcher);
auto *watcher = memnew(_DD3D_WorldWatcher(this, p_world_id));
p_vp->add_child(watcher);
p_vp->move_child(watcher, 0);
watcher->init(this, p_world_id);
}

Viewport *DebugDraw3D::_get_root_world_viewport(Viewport *p_vp) {
Expand Down
7 changes: 5 additions & 2 deletions src/3d/debug_draw_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ class _DD3D_WorldWatcher : public Node3D {
static void _bind_methods(){};

public:
void init(DebugDraw3D *p_root, uint64_t p_world_id);

virtual void _process(double p_delta);
virtual void _notification(int p_what);

_DD3D_WorldWatcher() :
m_world_id() {}
_DD3D_WorldWatcher(DebugDraw3D *p_root, uint64_t p_world_id);
};

#endif
Expand Down

0 comments on commit e445674

Please sign in to comment.