Skip to content

Commit

Permalink
Improve error handling and memory management
Browse files Browse the repository at this point in the history
  • Loading branch information
theol0403 committed Sep 19, 2019
1 parent 80bd862 commit dc0de76
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
Binary file modified bin/gif-pros.a
Binary file not shown.
Binary file modified gif-pros@2.0.0.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion include/gif-pros/gifclass.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Gif {
lv_color_t* _cbuf = nullptr; // canvas buffer
lv_obj_t* _canvas = nullptr; // canvas object

pros::task_t _task; // render task
pros::task_t _task = nullptr; // render task

Transparency _mode = Gif::Transparency::automatic; // transparency mode

Expand Down
16 changes: 9 additions & 7 deletions src/gif-pros/gifclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ Gif::Gif(const char* fname, lv_obj_t* parent, Transparency mode) {
// will allocate memory for background and one animation frame.
_gif = gd_open_gif(memfp);
if(_gif == NULL) {
std::cerr << "Gif::Gif - not enough memory to open gif" << std::endl;
std::cerr << "Gif::Gif - error opening \"" + std::string(fname) + "\"" << std::endl;
_cleanup();
return;
}

Expand Down Expand Up @@ -73,12 +74,13 @@ Gif::~Gif() {
* Cleans and frees all allocated memory
*/
void Gif::_cleanup() {
pros::c::task_delete(_task);
lv_obj_del(_canvas);
delete[] _cbuf; _cbuf = nullptr;
free(_buffer); _buffer = nullptr;
gd_close_gif(_gif);
free(_gifmem); _gifmem = nullptr;
if(_canvas) { lv_obj_del(_canvas); _canvas = nullptr; }
if(_cbuf) { delete[] _cbuf; _cbuf = nullptr; }
if(_buffer) { free(_buffer); _buffer = nullptr; }
if(_gif) { gd_close_gif(_gif); _gif = nullptr; }
if(_gifmem) { free(_gifmem); _gifmem = nullptr; }
// deleting task kills this thread
if(_task) { pros::c::task_delete(_task); _task = nullptr; }
}


Expand Down

0 comments on commit dc0de76

Please sign in to comment.