free resources on app destruction

This commit is contained in:
2019-02-24 12:31:53 +01:00
parent 420e0a8c2a
commit 3d1412aee2
13 changed files with 66 additions and 6 deletions

View File

@@ -1079,6 +1079,22 @@ void Canvas::resize(int width, int height)
m_smask.create(width, height, "mask"); m_smask.create(width, height, "mask");
m_unsaved = true; 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) bool Canvas::create(int width, int height)
{ {
m_width = width; m_width = width;
@@ -1097,7 +1113,7 @@ bool Canvas::create(int width, int height)
m_tex[i].create(width, height, GL_RGBA32F); m_tex[i].create(width, height, GL_RGBA32F);
m_sampler_brush.create(GL_LINEAR, GL_CLAMP_TO_BORDER); m_sampler_brush.create(GL_LINEAR, GL_CLAMP_TO_BORDER);
#endif #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_NEAREST);
m_sampler.create(GL_LINEAR); m_sampler.create(GL_LINEAR);

View File

@@ -13,6 +13,8 @@
class Layer class Layer
{ {
public: public:
//Layer() = default;
//Layer(const Layer&) = delete;
RTT m_rtt[6]; RTT m_rtt[6];
glm::vec4 m_dirty_box[6] = SIXPLETTE(glm::vec4(0)); glm::vec4 m_dirty_box[6] = SIXPLETTE(glm::vec4(0));
bool m_dirty_face[6] = SIXPLETTE(false); bool m_dirty_face[6] = SIXPLETTE(false);
@@ -223,6 +225,8 @@ public:
std::vector<Layer::Snapshot> m_layers_snapshot; std::vector<Layer::Snapshot> m_layers_snapshot;
Canvas() { I = this; } Canvas() { I = this; }
~Canvas() { destroy(); }
void destroy();
bool create(int width, int height); bool create(int width, int height);
void resize(int width, int height); void resize(int width, int height);
void layer_remove(int idx); void layer_remove(int idx);

View File

@@ -34,6 +34,8 @@ bool Vive::Initialize()
void Vive::Terminate() void Vive::Terminate()
{ {
vr::VR_Shutdown(); vr::VR_Shutdown();
for (int eye = 0; eye < 2; ++eye)
m_eyes[eye].destroy();
} }
void Vive::Update() void Vive::Update()

View File

@@ -8,6 +8,8 @@
void LayoutManager::unload() void LayoutManager::unload()
{ {
for (auto& l : m_layouts)
l.second->destroy_immediate();
m_layouts.clear(); m_layouts.clear();
} }

View File

@@ -72,6 +72,12 @@ void Node::destroy()
key_release(); key_release();
} }
void Node::destroy_immediate()
{
for (auto c : m_children)
c->destroy_immediate();
}
Node* Node::root() Node* Node::root()
{ {
@@ -485,7 +491,7 @@ Node::Node(Node&& o)
m_flood_events = o.m_flood_events; m_flood_events = o.m_flood_events;
m_force_mouse_capture = o.m_force_mouse_capture; m_force_mouse_capture = o.m_force_mouse_capture;
m_capture_children = o.m_capture_children; m_capture_children = o.m_capture_children;
m_destroyed = o.m_destroyed; m_destroyed = false;// o.m_destroyed;
m_scale = o.m_scale; m_scale = o.m_scale;
m_pos_origin = o.m_pos_origin; 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) if (m_children[i]->m_destroyed)
{ {
m_children[i]->destroy_immediate();
remove_child(m_children[i].get()); remove_child(m_children[i].get());
i--; i--;
} }
@@ -1118,7 +1125,7 @@ void Node::clone_copy(Node* dest) const
dest->m_mvp = m_mvp; dest->m_mvp = m_mvp;
dest->m_mouse_inside = m_mouse_inside; dest->m_mouse_inside = m_mouse_inside;
dest->m_capture_children = m_capture_children; 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_scale = m_scale;
dest->m_pos_origin = m_pos_origin; dest->m_pos_origin = m_pos_origin;
dest->m_pos_offset = m_pos_offset; dest->m_pos_offset = m_pos_offset;

View File

@@ -184,6 +184,7 @@ public:
virtual void clone_finalize(Node* dest) const;; virtual void clone_finalize(Node* dest) const;;
void watch(std::function<bool(Node*)> observer); void watch(std::function<bool(Node*)> observer);
void destroy(); void destroy();
virtual void destroy_immediate();
Node* root(); Node* root();
template<class T = Node> T* find(const char* ids) template<class T = Node> T* find(const char* ids)

View File

@@ -523,3 +523,14 @@ void NodeCanvas::reset_camera()
m_canvas->m_cam_fov = 85; m_canvas->m_cam_fov = 85;
m_canvas->m_pan = {0, 0}; 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();
}

View File

@@ -23,5 +23,6 @@ public:
virtual void draw() override; virtual void draw() override;
virtual void handle_resize(glm::vec2 old_size, glm::vec2 new_size) override; virtual void handle_resize(glm::vec2 old_size, glm::vec2 new_size) override;
virtual kEventResult handle_event(Event* e) override; virtual kEventResult handle_event(Event* e) override;
virtual void destroy_immediate() override;
void reset_camera(); void reset_camera();
}; };

View File

@@ -143,6 +143,8 @@ bool NodePanelStroke::import_abr(const std::string& path)
async_update(); async_update();
async_end(); async_end();
//save(); //save();
return true;
} }
void NodePanelStroke::update_controls() void NodePanelStroke::update_controls()

View File

@@ -30,7 +30,6 @@ void NodeStrokePreview::clone_finalize(Node* dest) const
void NodeStrokePreview::init_controls() void NodeStrokePreview::init_controls()
{ {
m_mesh.create();
m_sampler_linear.create(); m_sampler_linear.create();
m_sampler_linear_repeat.create(GL_LINEAR, GL_REPEAT); m_sampler_linear_repeat.create(GL_LINEAR, GL_REPEAT);
m_sampler_mipmap.create(); m_sampler_mipmap.create();
@@ -470,3 +469,14 @@ void NodeStrokePreview::handle_resize(glm::vec2 old_size, glm::vec2 new_size)
draw_stroke(); 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();
}

View File

@@ -22,7 +22,6 @@ class NodeStrokePreview : public NodeBorder
Sampler m_sampler_linear; Sampler m_sampler_linear;
Sampler m_sampler_linear_repeat; Sampler m_sampler_linear_repeat;
Sampler m_sampler_mipmap; Sampler m_sampler_mipmap;
BrushMesh m_mesh;
DynamicShape m_brush_shape; DynamicShape m_brush_shape;
public: public:
std::shared_ptr<Brush> m_brush; std::shared_ptr<Brush> m_brush;
@@ -45,4 +44,5 @@ public:
void draw_stroke(); void draw_stroke();
virtual void draw() override; virtual void draw() override;
virtual void handle_resize(glm::vec2 old_size, glm::vec2 new_size) override; virtual void handle_resize(glm::vec2 old_size, glm::vec2 new_size) override;
virtual void destroy_immediate() override;
}; };

View File

@@ -14,7 +14,9 @@ RTT::RTT()
RTT::~RTT() RTT::~RTT()
{ {
destroy(); //destroy();
if (texID || rboID || fboID)
LOG("RTT not destroyed");
} }
void RTT::resize(int width, int height) void RTT::resize(int width, int height)

View File

@@ -13,6 +13,8 @@ class RTT
int h = 0; int h = 0;
public: public:
//RTT(const RTT&) = delete;
//RTT(RTT&&) = default;
RTT(); RTT();
~RTT(); ~RTT();