From fc8faab5a46c8b58ce6fbc64b59bebc934081df9 Mon Sep 17 00:00:00 2001 From: Ooggle <33269056+Ooggle@users.noreply.github.com> Date: Sun, 12 Feb 2023 14:18:04 +0100 Subject: [PATCH] :bug: Fix glitch on Windows compiled animations + crash when compiling same animation twice --- .circleci/deb_linux/DEBIAN/control | 2 +- src/Animation.cpp | 27 +++++++++++++++------------ src/Animation.hpp | 3 ++- src/main.cpp | 2 +- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/.circleci/deb_linux/DEBIAN/control b/.circleci/deb_linux/DEBIAN/control index 9dc4ff2..29fa1a9 100644 --- a/.circleci/deb_linux/DEBIAN/control +++ b/.circleci/deb_linux/DEBIAN/control @@ -1,5 +1,5 @@ Package: flipper-am -Version: 1.3.0 +Version: 1.3.1 Section: development Priority: optional Architecture: all diff --git a/src/Animation.cpp b/src/Animation.cpp index a1311cf..b97e3b9 100644 --- a/src/Animation.cpp +++ b/src/Animation.cpp @@ -115,7 +115,7 @@ Animation::~Animation() void Animation::next_frame() { this->current_frame_number+= 1; - if(this->current_frame_number >= this->frames_order.size()) + if(this->current_frame_number >= (int)this->frames_order.size()) { this->current_frame_number = 0; } @@ -147,8 +147,8 @@ bool Animation::read_frames_from_files() // if a good format is found, proceed to load the files into textures this->frames = (GLuint*)malloc(this->total_frames_files * sizeof(GLuint)); - this->frames_pixels = (unsigned char**)malloc(this->total_frames_files * sizeof(unsigned char*)); - memset(this->frames_pixels, 0, this->total_frames_files * sizeof(unsigned char*)); + this->frames_pixels = (uint8_t**)malloc(this->total_frames_files * sizeof(uint8_t*)); + memset(this->frames_pixels, 0, this->total_frames_files * sizeof(uint8_t*)); for(int i = 0; i < this->total_frames_files; i++) { if(!this->LoadImageFromFile(this->anim_folder + "frame_" + std::to_string(i), i)) @@ -163,7 +163,7 @@ bool Animation::LoadImageFromFile(std::string filename, int file_number) // Image dimensions int image_width = 128; int image_height = 64; - unsigned char* image_data = NULL; + uint8_t* image_data = NULL; if(this->format == BM) { @@ -178,12 +178,12 @@ bool Animation::LoadImageFromFile(std::string filename, int file_number) fseek(f, 0, SEEK_END); int len = ftell(f); fseek(f, 0, SEEK_SET); - unsigned char* buffer = (unsigned char*)malloc(len+1); - unsigned char* out_buff = (unsigned char*)malloc(1024); + uint8_t* buffer = (uint8_t*)malloc(len+1); + uint8_t* out_buff = (uint8_t*)malloc(1024); fread(buffer, sizeof(char), len, f); fclose(f); - unsigned char* good_buffer = NULL; + uint8_t* good_buffer = NULL; if(buffer[0] == 1) { // Decompress using lzss heatshrink lib @@ -202,7 +202,7 @@ bool Animation::LoadImageFromFile(std::string filename, int file_number) heatshrink_decoder_finish(decoder); heatshrink_decoder_free(decoder); - image_data = (unsigned char*)malloc((1024*8)*4); + image_data = (uint8_t*)malloc((1024*8)*4); int pos = 0; // 1024: (128*64) / 8 int count_bytes = (image_width * image_height) / 8; @@ -239,7 +239,7 @@ bool Animation::LoadImageFromFile(std::string filename, int file_number) { good_buffer = buffer + 1; - image_data = (unsigned char*)malloc((1024*8)*4); + image_data = (uint8_t*)malloc((1024*8)*4); int pos = 0; for(int i = 0; i < 1024; i++) { @@ -354,6 +354,8 @@ void Animation::export_to_bm() std::string export_path = this->anim_folder.substr(0, this->anim_folder.length() - 1) + std::string("_compiled"); std::filesystem::create_directory(export_path); + if(std::filesystem::exists(export_path + std::string("/meta.txt"))) + std::filesystem::remove(export_path + std::string("/meta.txt")); std::filesystem::copy_file(this->anim_folder + std::string("meta.txt"), export_path + std::string("/meta.txt")); int image_width = 128; @@ -361,13 +363,13 @@ void Animation::export_to_bm() for(int f = 0; f < this->total_frames_files; f++) { - unsigned char* bm_frame = (unsigned char*)malloc(((image_width * image_height) / 8) + 1); + uint8_t* bm_frame = (uint8_t*)malloc(((image_width * image_height) / 8) + 1); bm_frame[0] = 0; int bm_frame_pos = 1; int L, P; int pixel_pos = 0; - unsigned char byte_buffer = 0; + uint8_t byte_buffer = 0; int byte_buffer_count = 0; int count_bytes = (image_width * image_height) * 4; for(pixel_pos = 0; pixel_pos < count_bytes; pixel_pos+= 4) @@ -397,8 +399,9 @@ void Animation::export_to_bm() byte_buffer_count = 0; } } + printf("\n"); std::ofstream manifest_file; - manifest_file.open((export_path + std::string("/frame_") + std::to_string(f) + std::string(".bm")).c_str(), std::ofstream::out | std::ofstream::trunc); + manifest_file.open((export_path + std::string("/frame_") + std::to_string(f) + std::string(".bm")).c_str(), std::ofstream::trunc | std::ofstream::binary); if(!manifest_file.is_open()) { perror("Error: open frame"); diff --git a/src/Animation.hpp b/src/Animation.hpp index 5632998..3a926f5 100644 --- a/src/Animation.hpp +++ b/src/Animation.hpp @@ -1,6 +1,7 @@ #ifndef ANIMATION_H #define ANIMATION_H +#include #include #include #include @@ -26,7 +27,7 @@ class Animation int total_frames_number = 0; int total_frames_files = 0; GLuint* frames = NULL; - unsigned char** frames_pixels = NULL; + uint8_t** frames_pixels = NULL; float time_per_frame; std::vector frames_order; std::chrono::system_clock::time_point time_at_last_frame; diff --git a/src/main.cpp b/src/main.cpp index 55fba18..5907fa3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -47,7 +47,7 @@ int main(int argc, char* argv[]) { const int version_major = 1; const int version_minor = 3; - const int version_patch = 0; + const int version_patch = 1; // Setup SDL // (Some versions of SDL before <2.0.10 appears to have performance/stalling issues on a minority of Windows systems, // depending on whether SDL_INIT_GAMECONTROLLER is enabled or disabled.. updating to the latest version of SDL is recommended!)