Skip to content

Commit fc8faab

Browse files
committed
🐛 Fix glitch on Windows compiled animations + crash when compiling same animation twice
1 parent 0506734 commit fc8faab

4 files changed

Lines changed: 19 additions & 15 deletions

File tree

.circleci/deb_linux/DEBIAN/control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: flipper-am
2-
Version: 1.3.0
2+
Version: 1.3.1
33
Section: development
44
Priority: optional
55
Architecture: all

src/Animation.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ Animation::~Animation()
115115
void Animation::next_frame()
116116
{
117117
this->current_frame_number+= 1;
118-
if(this->current_frame_number >= this->frames_order.size())
118+
if(this->current_frame_number >= (int)this->frames_order.size())
119119
{
120120
this->current_frame_number = 0;
121121
}
@@ -147,8 +147,8 @@ bool Animation::read_frames_from_files()
147147

148148
// if a good format is found, proceed to load the files into textures
149149
this->frames = (GLuint*)malloc(this->total_frames_files * sizeof(GLuint));
150-
this->frames_pixels = (unsigned char**)malloc(this->total_frames_files * sizeof(unsigned char*));
151-
memset(this->frames_pixels, 0, this->total_frames_files * sizeof(unsigned char*));
150+
this->frames_pixels = (uint8_t**)malloc(this->total_frames_files * sizeof(uint8_t*));
151+
memset(this->frames_pixels, 0, this->total_frames_files * sizeof(uint8_t*));
152152
for(int i = 0; i < this->total_frames_files; i++)
153153
{
154154
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)
163163
// Image dimensions
164164
int image_width = 128;
165165
int image_height = 64;
166-
unsigned char* image_data = NULL;
166+
uint8_t* image_data = NULL;
167167

168168
if(this->format == BM)
169169
{
@@ -178,12 +178,12 @@ bool Animation::LoadImageFromFile(std::string filename, int file_number)
178178
fseek(f, 0, SEEK_END);
179179
int len = ftell(f);
180180
fseek(f, 0, SEEK_SET);
181-
unsigned char* buffer = (unsigned char*)malloc(len+1);
182-
unsigned char* out_buff = (unsigned char*)malloc(1024);
181+
uint8_t* buffer = (uint8_t*)malloc(len+1);
182+
uint8_t* out_buff = (uint8_t*)malloc(1024);
183183
fread(buffer, sizeof(char), len, f);
184184
fclose(f);
185185

186-
unsigned char* good_buffer = NULL;
186+
uint8_t* good_buffer = NULL;
187187
if(buffer[0] == 1)
188188
{
189189
// Decompress using lzss heatshrink lib
@@ -202,7 +202,7 @@ bool Animation::LoadImageFromFile(std::string filename, int file_number)
202202
heatshrink_decoder_finish(decoder);
203203
heatshrink_decoder_free(decoder);
204204

205-
image_data = (unsigned char*)malloc((1024*8)*4);
205+
image_data = (uint8_t*)malloc((1024*8)*4);
206206
int pos = 0;
207207
// 1024: (128*64) / 8
208208
int count_bytes = (image_width * image_height) / 8;
@@ -239,7 +239,7 @@ bool Animation::LoadImageFromFile(std::string filename, int file_number)
239239
{
240240
good_buffer = buffer + 1;
241241

242-
image_data = (unsigned char*)malloc((1024*8)*4);
242+
image_data = (uint8_t*)malloc((1024*8)*4);
243243
int pos = 0;
244244
for(int i = 0; i < 1024; i++)
245245
{
@@ -354,20 +354,22 @@ void Animation::export_to_bm()
354354

355355
std::string export_path = this->anim_folder.substr(0, this->anim_folder.length() - 1) + std::string("_compiled");
356356
std::filesystem::create_directory(export_path);
357+
if(std::filesystem::exists(export_path + std::string("/meta.txt")))
358+
std::filesystem::remove(export_path + std::string("/meta.txt"));
357359
std::filesystem::copy_file(this->anim_folder + std::string("meta.txt"), export_path + std::string("/meta.txt"));
358360

359361
int image_width = 128;
360362
int image_height = 64;
361363

362364
for(int f = 0; f < this->total_frames_files; f++)
363365
{
364-
unsigned char* bm_frame = (unsigned char*)malloc(((image_width * image_height) / 8) + 1);
366+
uint8_t* bm_frame = (uint8_t*)malloc(((image_width * image_height) / 8) + 1);
365367
bm_frame[0] = 0;
366368
int bm_frame_pos = 1;
367369

368370
int L, P;
369371
int pixel_pos = 0;
370-
unsigned char byte_buffer = 0;
372+
uint8_t byte_buffer = 0;
371373
int byte_buffer_count = 0;
372374
int count_bytes = (image_width * image_height) * 4;
373375
for(pixel_pos = 0; pixel_pos < count_bytes; pixel_pos+= 4)
@@ -397,8 +399,9 @@ void Animation::export_to_bm()
397399
byte_buffer_count = 0;
398400
}
399401
}
402+
printf("\n");
400403
std::ofstream manifest_file;
401-
manifest_file.open((export_path + std::string("/frame_") + std::to_string(f) + std::string(".bm")).c_str(), std::ofstream::out | std::ofstream::trunc);
404+
manifest_file.open((export_path + std::string("/frame_") + std::to_string(f) + std::string(".bm")).c_str(), std::ofstream::trunc | std::ofstream::binary);
402405

403406
if(!manifest_file.is_open()) {
404407
perror("Error: open frame");

src/Animation.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef ANIMATION_H
22
#define ANIMATION_H
33

4+
#include <stdint.h>
45
#include <chrono>
56
#include <string>
67
#include <vector>
@@ -26,7 +27,7 @@ class Animation
2627
int total_frames_number = 0;
2728
int total_frames_files = 0;
2829
GLuint* frames = NULL;
29-
unsigned char** frames_pixels = NULL;
30+
uint8_t** frames_pixels = NULL;
3031
float time_per_frame;
3132
std::vector<int> frames_order;
3233
std::chrono::system_clock::time_point time_at_last_frame;

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ int main(int argc, char* argv[])
4747
{
4848
const int version_major = 1;
4949
const int version_minor = 3;
50-
const int version_patch = 0;
50+
const int version_patch = 1;
5151
// Setup SDL
5252
// (Some versions of SDL before <2.0.10 appears to have performance/stalling issues on a minority of Windows systems,
5353
// depending on whether SDL_INIT_GAMECONTROLLER is enabled or disabled.. updating to the latest version of SDL is recommended!)

0 commit comments

Comments
 (0)