Skip to content

Commit

Permalink
Work around a crash in data file loading
Browse files Browse the repository at this point in the history
When using datafile abstraction of aldumb 2, allegro 4 does a double
free and crashes (see kode54/dumb#78).
  • Loading branch information
carstene1ns committed Nov 1, 2017
1 parent ab3dae7 commit 6805e88
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
15 changes: 10 additions & 5 deletions src/main.c
Expand Up @@ -81,6 +81,7 @@ Tactor actor[MAX_ACTORS];
int editing = 0;

// music and stuff
static DUMBFILE *dmbf = NULL;
static AL_DUH_PLAYER *dp = NULL;
static DUH_SIGRENDERER *sr = NULL;
static DUH *duh = NULL;
Expand Down Expand Up @@ -721,10 +722,11 @@ int init_game(const char *map_file) {

// register dumb
log2file(" registering dumb");
dumb_register_packfiles();
dumb_register_dat_mod(DUMB_DAT_MOD);
dumb_resampling_quality = get_config_int("dumb", "dumb_resampling_quality", 4);
dumb_it_max_to_mix = get_config_int("dumb", "dumb_it_max_to_mix", 128);
//dumb_register_packfiles();
//dumb_register_dat_mod(DUMB_DAT_MOD);
//dumb_resampling_quality = get_config_int("dumb", "dumb_resampling_quality", 4);
//dumb_it_max_to_mix = get_config_int("dumb", "dumb_it_max_to_mix", 128);


// load data
log2file(" loading data");
Expand Down Expand Up @@ -903,7 +905,9 @@ int init_game(const char *map_file) {
if (got_sound) {
int s = 0;
// load music
duh = (DUH *)data[MSC_GAME].dat;
//duh = (DUH *)data[MSC_GAME].dat;
dmbf = dumbfile_open_memory(data[MSC_GAME].dat, data[MSC_GAME].size);
duh = dumb_read_mod(dmbf, 0);

if (get_config_int("sound", "use_sound_datafile", 1)) {
log2file(" loading sound datafile");
Expand Down Expand Up @@ -1070,6 +1074,7 @@ void uninit_game() {
}

log2file(" exiting dumb");
unload_duh(duh);
dumb_exit();

log2file(" exiting allegro");
Expand Down
7 changes: 6 additions & 1 deletion src/shooter.c
Expand Up @@ -50,6 +50,7 @@ Tspace_object s_sign;

// music
int s_got_sound = 0;
static DUMBFILE *s_dmbf = NULL;
static AL_DUH_PLAYER *s_dp = NULL;
static DUH_SIGRENDERER *s_sr = NULL;
static DUH *s_duh = NULL;
Expand Down Expand Up @@ -1462,7 +1463,9 @@ int s_init_shooter() {


// lock onto music
s_duh = (DUH *)s_data[SPACEMOD].dat;
//s_duh = (DUH *)s_data[SPACEMOD].dat;
s_dmbf = dumbfile_open_memory(s_data[SPACEMOD].dat, s_data[SPACEMOD].size);
s_duh = dumb_read_mod(s_dmbf, 0);

// done
log2file(" init OK!");
Expand All @@ -1484,6 +1487,8 @@ void s_uninit_shooter() {

log2file(" unloading datafile");
if (s_data != NULL) unload_datafile(s_data);

unload_duh(s_duh);
}


Expand Down

0 comments on commit 6805e88

Please sign in to comment.