Skip to content

Commit

Permalink
fix assets uncompress size
Browse files Browse the repository at this point in the history
  • Loading branch information
julesgrc0 committed Feb 12, 2024
1 parent 33d4722 commit f243a89
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 0 additions & 2 deletions src/screen/loading.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include "loading.h"

void load_assets(w_state *state) {
printf("Loading assets...\n");

state->render = LoadRenderTexture(RENDER_W, RENDER_H);
// LoadRenderTexture(state->config->render_size, state->config->render_size);
state->src_rnd = (Rectangle){0.0f, 0.0f, (float)state->render.texture.width,
Expand Down
19 changes: 17 additions & 2 deletions src/unpack/unpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,26 @@ w_asset *unpack_assets(HINSTANCE hInstance, size_t *size) {
if (!out_buffer)
return NULL;

if (uncompress(out_buffer, (uLongf *)&out_size, in_buffer, (uLong)in_size) !=
Z_OK) {
size_t try_index = 0;
for (try_index; try_index < MAX_UNCOMPRESSE_TRY; try_index++) {
if (uncompress(out_buffer, (uLongf *)&out_size, in_buffer,
(uLong)in_size) != Z_OK) {
out_size *= 2;
void *new_outbuff = realloc(out_buffer, out_size);
if (new_outbuff == NULL) {
sfree(out_buffer);
return NULL;
}
out_buffer = new_outbuff;
} else {
break;
}
}
if (try_index >= MAX_UNCOMPRESSE_TRY) {
sfree(out_buffer);
return NULL;
}

void *new_outbuff = realloc(out_buffer, out_size);
if (new_outbuff == NULL) {
sfree(out_buffer);
Expand Down
2 changes: 2 additions & 0 deletions src/unpack/unpack.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "../resource.h"
#include "../stdafx.h"

#define MAX_UNCOMPRESSE_TRY 4

typedef struct w_asset {
char *name;

Expand Down

0 comments on commit f243a89

Please sign in to comment.