mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-19 14:19:57 +01:00
Memory Leaks fix
Fixed tiny leaks in thumbnail saving to XML. Also cleaner ending freeing all allocated.
This commit is contained in:
@@ -52,6 +52,15 @@
|
|||||||
FilteringProgram _whitebalance("Whitebalance", "shaders/filters/whitebalance.glsl", "", { { "Red", 1.0}, { "Green", 1.0}, { "Blue", 1.0}, { "Temperature", 0.5} });
|
FilteringProgram _whitebalance("Whitebalance", "shaders/filters/whitebalance.glsl", "", { { "Red", 1.0}, { "Green", 1.0}, { "Blue", 1.0}, { "Temperature", 0.5} });
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
WindowPreview::~WindowPreview()
|
||||||
|
{
|
||||||
|
if (renderbuffer_)
|
||||||
|
delete renderbuffer_;
|
||||||
|
if (output_render_)
|
||||||
|
delete output_render_;
|
||||||
|
}
|
||||||
|
|
||||||
DisplaysView::DisplaysView() : View(DISPLAYS)
|
DisplaysView::DisplaysView() : View(DISPLAYS)
|
||||||
{
|
{
|
||||||
scene.root()->scale_ = glm::vec3(DISPLAYS_DEFAULT_SCALE, DISPLAYS_DEFAULT_SCALE, 1.0f);
|
scene.root()->scale_ = glm::vec3(DISPLAYS_DEFAULT_SCALE, DISPLAYS_DEFAULT_SCALE, 1.0f);
|
||||||
@@ -68,6 +77,10 @@ DisplaysView::DisplaysView() : View(DISPLAYS)
|
|||||||
windows_ = std::vector<WindowPreview>(MAX_OUTPUT_WINDOW);
|
windows_ = std::vector<WindowPreview>(MAX_OUTPUT_WINDOW);
|
||||||
for (auto w = windows_.begin(); w != windows_.end(); ++w){
|
for (auto w = windows_.begin(); w != windows_.end(); ++w){
|
||||||
|
|
||||||
|
// surface & buffer for render
|
||||||
|
w->output_render_ = new Surface;
|
||||||
|
w->renderbuffer_ = new FrameBuffer(1024, 1024);
|
||||||
|
|
||||||
// root node
|
// root node
|
||||||
w->root_ = new Group;
|
w->root_ = new Group;
|
||||||
scene.ws()->attach(w->root_);
|
scene.ws()->attach(w->root_);
|
||||||
@@ -78,14 +91,11 @@ DisplaysView::DisplaysView() : View(DISPLAYS)
|
|||||||
w->title_->scale_ = glm::vec3(1.002f, WINDOW_TITLEBAR_HEIGHT, 1.f);
|
w->title_->scale_ = glm::vec3(1.002f, WINDOW_TITLEBAR_HEIGHT, 1.f);
|
||||||
w->title_->translation_ = glm::vec3(0.f, 1.f + WINDOW_TITLEBAR_HEIGHT, 0.f);
|
w->title_->translation_ = glm::vec3(0.f, 1.f + WINDOW_TITLEBAR_HEIGHT, 0.f);
|
||||||
w->root_->attach(w->title_);
|
w->root_->attach(w->title_);
|
||||||
|
|
||||||
// surface background and texture
|
// surface background and texture
|
||||||
w->renderbuffer_ = new FrameBuffer(1024, 1024); // TODO delete on close
|
|
||||||
w->shader_ = new ImageFilteringShader;
|
w->shader_ = new ImageFilteringShader;
|
||||||
w->shader_->setCode( _whitebalance.code().first );
|
w->shader_->setCode( _whitebalance.code().first );
|
||||||
w->surface_ = new FrameBufferSurface(w->renderbuffer_, w->shader_);
|
w->surface_ = new FrameBufferSurface(w->renderbuffer_, w->shader_);
|
||||||
w->root_->attach(w->surface_);
|
w->root_->attach(w->surface_);
|
||||||
w->output_render_ = new Surface;
|
|
||||||
// icon if disabled
|
// icon if disabled
|
||||||
w->icon_ = new Handles(Handles::EYESLASHED);
|
w->icon_ = new Handles(Handles::EYESLASHED);
|
||||||
w->icon_->visible_ = false;
|
w->icon_->visible_ = false;
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ struct WindowPreview
|
|||||||
fullscreen_ = nullptr;
|
fullscreen_ = nullptr;
|
||||||
monitor_ = "";
|
monitor_ = "";
|
||||||
}
|
}
|
||||||
|
~WindowPreview();
|
||||||
|
|
||||||
struct hasNode
|
struct hasNode
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -388,14 +388,14 @@ void FrameBuffer::setProjectionArea(glm::vec2 c)
|
|||||||
|
|
||||||
|
|
||||||
FrameBufferImage::FrameBufferImage(int w, int h) :
|
FrameBufferImage::FrameBufferImage(int w, int h) :
|
||||||
rgb(nullptr), width(w), height(h)
|
rgb(nullptr), width(w), height(h), is_stbi(false)
|
||||||
{
|
{
|
||||||
if (width>0 && height>0)
|
if (width>0 && height>0)
|
||||||
rgb = new uint8_t[width*height*3];
|
rgb = new uint8_t[width*height*3];
|
||||||
}
|
}
|
||||||
|
|
||||||
FrameBufferImage::FrameBufferImage(jpegBuffer jpgimg) :
|
FrameBufferImage::FrameBufferImage(jpegBuffer jpgimg) :
|
||||||
rgb(nullptr), width(0), height(0)
|
rgb(nullptr), width(0), height(0), is_stbi(true)
|
||||||
{
|
{
|
||||||
int c = 0;
|
int c = 0;
|
||||||
if (jpgimg.buffer != nullptr && jpgimg.len >0)
|
if (jpgimg.buffer != nullptr && jpgimg.len >0)
|
||||||
@@ -403,7 +403,7 @@ FrameBufferImage::FrameBufferImage(jpegBuffer jpgimg) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
FrameBufferImage::FrameBufferImage(const std::string &filename) :
|
FrameBufferImage::FrameBufferImage(const std::string &filename) :
|
||||||
rgb(nullptr), width(0), height(0)
|
rgb(nullptr), width(0), height(0), is_stbi(true)
|
||||||
{
|
{
|
||||||
int c = 0;
|
int c = 0;
|
||||||
if (!filename.empty())
|
if (!filename.empty())
|
||||||
@@ -412,8 +412,12 @@ FrameBufferImage::FrameBufferImage(const std::string &filename) :
|
|||||||
|
|
||||||
FrameBufferImage::~FrameBufferImage()
|
FrameBufferImage::~FrameBufferImage()
|
||||||
{
|
{
|
||||||
if (rgb!=nullptr)
|
if (rgb!=nullptr) {
|
||||||
delete rgb;
|
if (is_stbi)
|
||||||
|
stbi_image_free(rgb);
|
||||||
|
else
|
||||||
|
delete [] rgb;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FrameBufferImage::jpegBuffer FrameBufferImage::getJpeg() const
|
FrameBufferImage::jpegBuffer FrameBufferImage::getJpeg() const
|
||||||
@@ -423,14 +427,13 @@ FrameBufferImage::jpegBuffer FrameBufferImage::getJpeg() const
|
|||||||
// if we hold a valid image
|
// if we hold a valid image
|
||||||
if (rgb!=nullptr && width>0 && height>0) {
|
if (rgb!=nullptr && width>0 && height>0) {
|
||||||
|
|
||||||
// allocate JPEG buffer
|
// dynamically allocate JPEG buffer
|
||||||
// (NB: JPEG will need less than this but we can't know before...)
|
|
||||||
jpgimg.buffer = (unsigned char *) malloc( width * height * 3 * sizeof(unsigned char));
|
|
||||||
|
|
||||||
stbi_write_jpg_to_func( [](void *context, void *data, int size)
|
stbi_write_jpg_to_func( [](void *context, void *data, int size)
|
||||||
{
|
{
|
||||||
memcpy(((FrameBufferImage::jpegBuffer*)context)->buffer + ((FrameBufferImage::jpegBuffer*)context)->len, data, size);
|
uint pos = ((FrameBufferImage::jpegBuffer*)context)->len;
|
||||||
((FrameBufferImage::jpegBuffer*)context)->len += size;
|
((FrameBufferImage::jpegBuffer*)context)->len += size;
|
||||||
|
((FrameBufferImage::jpegBuffer*)context)->buffer = (unsigned char *) realloc(((FrameBufferImage::jpegBuffer*)context)->buffer, ((FrameBufferImage::jpegBuffer*)context)->len);
|
||||||
|
memmove(((FrameBufferImage::jpegBuffer*)context)->buffer + pos, data, size);
|
||||||
}
|
}
|
||||||
,&jpgimg, width, height, 3, rgb, FBI_JPEG_QUALITY);
|
,&jpgimg, width, height, 3, rgb, FBI_JPEG_QUALITY);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ public:
|
|||||||
uint8_t *rgb;
|
uint8_t *rgb;
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
|
bool is_stbi;
|
||||||
|
|
||||||
struct jpegBuffer {
|
struct jpegBuffer {
|
||||||
unsigned char *buffer = nullptr;
|
unsigned char *buffer = nullptr;
|
||||||
|
|||||||
@@ -217,7 +217,6 @@ bool UserInterface::Init()
|
|||||||
|
|
||||||
// setup settings filename
|
// setup settings filename
|
||||||
std::string inifile = SystemToolkit::full_filename(SystemToolkit::settings_path(), "imgui.ini");
|
std::string inifile = SystemToolkit::full_filename(SystemToolkit::settings_path(), "imgui.ini");
|
||||||
char *inifilepath = (char *) malloc( (inifile.size() + 1) * sizeof(char) );
|
|
||||||
std::sprintf(inifilepath, "%s", inifile.c_str() );
|
std::sprintf(inifilepath, "%s", inifile.c_str() );
|
||||||
io.IniFilename = inifilepath;
|
io.IniFilename = inifilepath;
|
||||||
|
|
||||||
|
|||||||
@@ -484,6 +484,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
|
|
||||||
// internal
|
// internal
|
||||||
|
char inifilepath[2048];
|
||||||
uint64_t start_time;
|
uint64_t start_time;
|
||||||
bool ctrl_modifier_active;
|
bool ctrl_modifier_active;
|
||||||
bool alt_modifier_active;
|
bool alt_modifier_active;
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ XMLElement *tinyxml2::XMLElementEncodeArray(XMLDocument *doc, const void *array,
|
|||||||
gchar *compressed_array = g_new(gchar, compressed_size);
|
gchar *compressed_array = g_new(gchar, compressed_size);
|
||||||
|
|
||||||
// encoded string will hold the base64 encoding of the array
|
// encoded string will hold the base64 encoding of the array
|
||||||
const gchar *encoded_array = nullptr;
|
gchar *encoded_array = nullptr;
|
||||||
|
|
||||||
// zlib compress ((Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen));
|
// zlib compress ((Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen));
|
||||||
if ( Z_OK == compress((Bytef *)compressed_array, &compressed_size,
|
if ( Z_OK == compress((Bytef *)compressed_array, &compressed_size,
|
||||||
@@ -158,6 +158,7 @@ XMLElement *tinyxml2::XMLElementEncodeArray(XMLDocument *doc, const void *array,
|
|||||||
|
|
||||||
// encode the compressed array
|
// encode the compressed array
|
||||||
encoded_array = g_base64_encode( (guchar *) compressed_array, (gsize) compressed_size);
|
encoded_array = g_base64_encode( (guchar *) compressed_array, (gsize) compressed_size);
|
||||||
|
|
||||||
}
|
}
|
||||||
// failed compression
|
// failed compression
|
||||||
else {
|
else {
|
||||||
@@ -169,8 +170,9 @@ XMLElement *tinyxml2::XMLElementEncodeArray(XMLDocument *doc, const void *array,
|
|||||||
XMLText *text = doc->NewText( encoded_array );
|
XMLText *text = doc->NewText( encoded_array );
|
||||||
newelement->InsertEndChild( text );
|
newelement->InsertEndChild( text );
|
||||||
|
|
||||||
// free temporary array
|
// free temporary arrays
|
||||||
g_free(compressed_array);
|
g_free(compressed_array);
|
||||||
|
g_free(encoded_array);
|
||||||
|
|
||||||
return newelement;
|
return newelement;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user