diff --git a/src/canvas.cpp b/src/canvas.cpp index 3565cfe..803a458 100644 --- a/src/canvas.cpp +++ b/src/canvas.cpp @@ -1079,6 +1079,22 @@ void Canvas::resize(int width, int height) m_smask.create(width, height, "mask"); m_unsaved = true; } + +void Canvas::destroy() +{ + for (int i = 0; i < 6; i++) + { + m_tmp[i].destroy(); + m_tmp_dual[i].destroy(); + m_tex[i].destroy(); + m_tex2[i].destroy(); + } + for (auto& l : m_layers) + l.destroy(); + m_smask.destroy(); + m_mixer.destroy(); +} + bool Canvas::create(int width, int height) { m_width = width; @@ -1097,7 +1113,7 @@ bool Canvas::create(int width, int height) m_tex[i].create(width, height, GL_RGBA32F); m_sampler_brush.create(GL_LINEAR, GL_CLAMP_TO_BORDER); #endif - m_tex2[i].create(width, height, GL_RGBA8); // TODO: destroy before recreating + m_tex2[i].create(width, height, GL_RGBA8); } m_sampler.create(GL_NEAREST); m_sampler.create(GL_LINEAR); diff --git a/src/canvas.h b/src/canvas.h index 788013d..3e2a2be 100644 --- a/src/canvas.h +++ b/src/canvas.h @@ -13,6 +13,8 @@ class Layer { public: + //Layer() = default; + //Layer(const Layer&) = delete; RTT m_rtt[6]; glm::vec4 m_dirty_box[6] = SIXPLETTE(glm::vec4(0)); bool m_dirty_face[6] = SIXPLETTE(false); @@ -223,6 +225,8 @@ public: std::vector m_layers_snapshot; Canvas() { I = this; } + ~Canvas() { destroy(); } + void destroy(); bool create(int width, int height); void resize(int width, int height); void layer_remove(int idx); diff --git a/src/hmd.cpp b/src/hmd.cpp index cecb7d9..8e52e2f 100644 --- a/src/hmd.cpp +++ b/src/hmd.cpp @@ -34,6 +34,8 @@ bool Vive::Initialize() void Vive::Terminate() { vr::VR_Shutdown(); + for (int eye = 0; eye < 2; ++eye) + m_eyes[eye].destroy(); } void Vive::Update() diff --git a/src/layout.cpp b/src/layout.cpp index fe103fe..48adc61 100644 --- a/src/layout.cpp +++ b/src/layout.cpp @@ -8,6 +8,8 @@ void LayoutManager::unload() { + for (auto& l : m_layouts) + l.second->destroy_immediate(); m_layouts.clear(); } diff --git a/src/node.cpp b/src/node.cpp index 274b820..1005744 100644 --- a/src/node.cpp +++ b/src/node.cpp @@ -72,6 +72,12 @@ void Node::destroy() key_release(); } +void Node::destroy_immediate() +{ + for (auto c : m_children) + c->destroy_immediate(); +} + Node* Node::root() { @@ -485,7 +491,7 @@ Node::Node(Node&& o) m_flood_events = o.m_flood_events; m_force_mouse_capture = o.m_force_mouse_capture; m_capture_children = o.m_capture_children; - m_destroyed = o.m_destroyed; + m_destroyed = false;// o.m_destroyed; m_scale = o.m_scale; m_pos_origin = o.m_pos_origin; @@ -767,6 +773,7 @@ void Node::update_internal(const glm::vec2& origin, const glm::mat4& proj) { if (m_children[i]->m_destroyed) { + m_children[i]->destroy_immediate(); remove_child(m_children[i].get()); i--; } @@ -1118,7 +1125,7 @@ void Node::clone_copy(Node* dest) const dest->m_mvp = m_mvp; dest->m_mouse_inside = m_mouse_inside; dest->m_capture_children = m_capture_children; - dest->m_destroyed = m_destroyed; + dest->m_destroyed = false;// m_destroyed; dest->m_scale = m_scale; dest->m_pos_origin = m_pos_origin; dest->m_pos_offset = m_pos_offset; diff --git a/src/node.h b/src/node.h index 772ddc7..2085535 100644 --- a/src/node.h +++ b/src/node.h @@ -184,6 +184,7 @@ public: virtual void clone_finalize(Node* dest) const;; void watch(std::function observer); void destroy(); + virtual void destroy_immediate(); Node* root(); template T* find(const char* ids) diff --git a/src/node_canvas.cpp b/src/node_canvas.cpp index fae7e9a..d6e7f0a 100644 --- a/src/node_canvas.cpp +++ b/src/node_canvas.cpp @@ -523,3 +523,14 @@ void NodeCanvas::reset_camera() m_canvas->m_cam_fov = 85; m_canvas->m_pan = {0, 0}; } + +void NodeCanvas::destroy_immediate() +{ + Node::destroy_immediate(); + m_blender_rtt.destroy(); + m_cache_rtt.destroy(); + m_blender_bg.destroy(); + m_face_plane.destroy(); + m_line.destroy(); + m_grid.destroy(); +} diff --git a/src/node_canvas.h b/src/node_canvas.h index c7f49f4..b0e467f 100644 --- a/src/node_canvas.h +++ b/src/node_canvas.h @@ -23,5 +23,6 @@ public: virtual void draw() override; virtual void handle_resize(glm::vec2 old_size, glm::vec2 new_size) override; virtual kEventResult handle_event(Event* e) override; + virtual void destroy_immediate() override; void reset_camera(); }; diff --git a/src/node_panel_stroke.cpp b/src/node_panel_stroke.cpp index b0b36f9..0ffbf11 100644 --- a/src/node_panel_stroke.cpp +++ b/src/node_panel_stroke.cpp @@ -143,6 +143,8 @@ bool NodePanelStroke::import_abr(const std::string& path) async_update(); async_end(); //save(); + + return true; } void NodePanelStroke::update_controls() diff --git a/src/node_stroke_preview.cpp b/src/node_stroke_preview.cpp index 825218b..4d6176c 100644 --- a/src/node_stroke_preview.cpp +++ b/src/node_stroke_preview.cpp @@ -30,7 +30,6 @@ void NodeStrokePreview::clone_finalize(Node* dest) const void NodeStrokePreview::init_controls() { - m_mesh.create(); m_sampler_linear.create(); m_sampler_linear_repeat.create(GL_LINEAR, GL_REPEAT); m_sampler_mipmap.create(); @@ -470,3 +469,14 @@ void NodeStrokePreview::handle_resize(glm::vec2 old_size, glm::vec2 new_size) draw_stroke(); } + +void NodeStrokePreview::destroy_immediate() +{ + Node::destroy_immediate(); + m_rtt.destroy(); + m_rtt_mixer.destroy(); + m_tex.destroy(); + m_tex_dual.destroy(); + m_tex_background.destroy(); + m_brush_shape.destroy(); +} diff --git a/src/node_stroke_preview.h b/src/node_stroke_preview.h index e84ee67..c6be585 100644 --- a/src/node_stroke_preview.h +++ b/src/node_stroke_preview.h @@ -22,7 +22,6 @@ class NodeStrokePreview : public NodeBorder Sampler m_sampler_linear; Sampler m_sampler_linear_repeat; Sampler m_sampler_mipmap; - BrushMesh m_mesh; DynamicShape m_brush_shape; public: std::shared_ptr m_brush; @@ -45,4 +44,5 @@ public: void draw_stroke(); virtual void draw() override; virtual void handle_resize(glm::vec2 old_size, glm::vec2 new_size) override; + virtual void destroy_immediate() override; }; diff --git a/src/rtt.cpp b/src/rtt.cpp index 90eeb04..57457ca 100644 --- a/src/rtt.cpp +++ b/src/rtt.cpp @@ -14,7 +14,9 @@ RTT::RTT() RTT::~RTT() { - destroy(); + //destroy(); + if (texID || rboID || fboID) + LOG("RTT not destroyed"); } void RTT::resize(int width, int height) diff --git a/src/rtt.h b/src/rtt.h index b5a5b82..9549d33 100644 --- a/src/rtt.h +++ b/src/rtt.h @@ -13,6 +13,8 @@ class RTT int h = 0; public: + //RTT(const RTT&) = delete; + //RTT(RTT&&) = default; RTT(); ~RTT();