Skip to content

Commit

Permalink
Bugfix/memory leaks (#42)
Browse files Browse the repository at this point in the history
* Fixes memory leaks.
* Moves settings unset to separate function call.
  • Loading branch information
FiniteSingularity authored Jul 2, 2024
1 parent 7c1aeac commit c7d5cf2
Show file tree
Hide file tree
Showing 32 changed files with 168 additions and 79 deletions.
13 changes: 8 additions & 5 deletions src/filters/analog-glitch.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ void analog_glitch_destroy(retro_effects_filter_data_t *filter)

obs_leave_graphics();

obs_data_t *settings = obs_source_get_settings(filter->base->context);
// obs_data_unset_user_value(settings, "analog_glitch_size");
bfree(filter->active_filter_data);
filter->active_filter_data = NULL;
}

void analog_glitch_unset_settings(retro_effects_filter_data_t* filter)
{
obs_data_t* settings = obs_source_get_settings(filter->base->context);
obs_data_unset_user_value(settings, "analog_glitch_primary_speed");
obs_data_unset_user_value(settings, "analog_glitch_primary_scale");
obs_data_unset_user_value(settings, "analog_glitch_secondary_speed");
Expand All @@ -40,9 +45,6 @@ void analog_glitch_destroy(retro_effects_filter_data_t *filter)
obs_data_unset_user_value(settings, "analog_glitch_line_magnitude");
obs_data_unset_user_value(settings, "analog_glitch_interfence_alpha");
obs_data_release(settings);

bfree(filter->active_filter_data);
filter->active_filter_data = NULL;
}

void analog_glitch_filter_update(retro_effects_filter_data_t *data,
Expand Down Expand Up @@ -325,6 +327,7 @@ static void analog_glitch_set_functions(retro_effects_filter_data_t *filter)
filter->filter_defaults = analog_glitch_filter_defaults;
filter->filter_update = analog_glitch_filter_update;
filter->filter_video_tick = analog_glitch_filter_video_tick;
filter->filter_unset_settings = analog_glitch_unset_settings;
}

void analog_glitch_filter_video_tick(retro_effects_filter_data_t *data,
Expand Down
1 change: 1 addition & 0 deletions src/filters/analog-glitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ struct analog_glitch_filter_data {

extern void analog_glitch_create(retro_effects_filter_data_t *filter);
extern void analog_glitch_destroy(retro_effects_filter_data_t *filter);
extern void analog_glitch_unset_settings(retro_effects_filter_data_t* filter);
extern void analog_glitch_filter_video_render(retro_effects_filter_data_t *data);
extern void analog_glitch_filter_video_tick(retro_effects_filter_data_t *data,
float seconds);
Expand Down
12 changes: 7 additions & 5 deletions src/filters/bloom-f.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,21 @@ void bloom_f_destroy(retro_effects_filter_data_t *filter)

obs_leave_graphics();

obs_data_t *settings = obs_source_get_settings(filter->base->context);
bfree(filter->active_filter_data);
filter->active_filter_data = NULL;
}

void bloom_f_unset_settings(retro_effects_filter_data_t* filter)
{
obs_data_t* settings = obs_source_get_settings(filter->base->context);
obs_data_unset_user_value(settings, "bloom_intensity");
obs_data_unset_user_value(settings, "bloom_threshold");
obs_data_unset_user_value(settings, "bloom_size");
obs_data_unset_user_value(settings, "bloom_threshold_type");
obs_data_unset_user_value(settings, "bloom_red_level");
obs_data_unset_user_value(settings, "bloom_green_level");
obs_data_unset_user_value(settings, "bloom_blue_level");

obs_data_release(settings);

bfree(filter->active_filter_data);
filter->active_filter_data = NULL;
}

void bloom_f_filter_update(retro_effects_filter_data_t *data,
Expand Down Expand Up @@ -183,6 +184,7 @@ static void bloom_f_set_functions(retro_effects_filter_data_t *filter)
filter->filter_defaults = bloom_f_filter_defaults;
filter->filter_update = bloom_f_filter_update;
filter->filter_video_tick = NULL;
filter->filter_unset_settings = bloom_f_unset_settings;
}

static bool threshold_type_modified(void *data, obs_properties_t *props,
Expand Down
2 changes: 2 additions & 0 deletions src/filters/bloom-f.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ struct bloom_f_filter_data {

extern void bloom_f_create(retro_effects_filter_data_t *filter);
extern void bloom_f_destroy(retro_effects_filter_data_t *filter);
extern void bloom_f_unset_settings(retro_effects_filter_data_t* filter);

extern void bloom_f_filter_video_render(retro_effects_filter_data_t *data);
extern void bloom_f_filter_properties(retro_effects_filter_data_t *data,
obs_properties_t *props);
Expand Down
15 changes: 9 additions & 6 deletions src/filters/cathode-boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,20 @@ void cathode_boot_create(retro_effects_filter_data_t *filter)
void cathode_boot_destroy(retro_effects_filter_data_t *filter)
{
cathode_boot_filter_data_t *data = filter->active_filter_data;

obs_enter_graphics();
if (data->effect_cathode_boot) {
gs_effect_destroy(data->effect_cathode_boot);
}

obs_leave_graphics();

obs_data_t *settings = obs_source_get_settings(filter->base->context);
bfree(filter->active_filter_data);
filter->active_filter_data = NULL;
}

void cathode_boot_unset_settings(retro_effects_filter_data_t* filter)
{
obs_data_t* settings = obs_source_get_settings(filter->base->context);
obs_data_unset_user_value(settings, "cathode_boot_progress");
obs_data_unset_user_value(settings, "cathode_boot_vert_thickness");
obs_data_unset_user_value(settings, "cathode_boot_vert_start");
Expand All @@ -36,9 +42,6 @@ void cathode_boot_destroy(retro_effects_filter_data_t *filter)
obs_data_unset_user_value(settings, "cathode_boot_fade_end");
obs_data_unset_user_value(settings, "cathode_boot_glow_size");
obs_data_release(settings);

bfree(filter->active_filter_data);
filter->active_filter_data = NULL;
}

void cathode_boot_filter_update(retro_effects_filter_data_t *data,
Expand Down Expand Up @@ -72,7 +75,6 @@ void cathode_boot_filter_defaults(obs_data_t *settings) {
obs_data_set_default_double(settings, "cathode_boot_vert_thickness", 1.0);
obs_data_set_default_double(settings, "cathode_boot_horiz_thickness", 1.0);
obs_data_set_default_double(settings, "cathode_boot_glow_size", 2.0);

}

void cathode_boot_filter_properties(retro_effects_filter_data_t *data,
Expand Down Expand Up @@ -239,6 +241,7 @@ static void cathode_boot_set_functions(retro_effects_filter_data_t *filter)
filter->filter_defaults = cathode_boot_filter_defaults;
filter->filter_update = cathode_boot_filter_update;
filter->filter_video_tick = NULL;
filter->filter_unset_settings = cathode_boot_unset_settings;
}

static void cathode_boot_load_effect(cathode_boot_filter_data_t *filter)
Expand Down
8 changes: 2 additions & 6 deletions src/filters/cathode-boot.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ struct cathode_boot_filter_data {

extern void cathode_boot_create(retro_effects_filter_data_t *filter);
extern void cathode_boot_destroy(retro_effects_filter_data_t *filter);
extern void cathode_boot_unset_settings(retro_effects_filter_data_t* filter);

extern void cathode_boot_filter_video_render(retro_effects_filter_data_t *data);
extern void cathode_boot_filter_properties(retro_effects_filter_data_t *data,
obs_properties_t *props);
Expand All @@ -37,9 +39,3 @@ extern void cathode_boot_filter_update(retro_effects_filter_data_t *data,
obs_data_t *settings);
static void cathode_boot_set_functions(retro_effects_filter_data_t *filter);
static void cathode_boot_load_effect(cathode_boot_filter_data_t *filter);
static bool cathode_boot_type_modified(obs_properties_t *props,
obs_property_t *p, obs_data_t *settings);
static bool cathode_boot_bayer_size_modified(void *data,
obs_properties_t *props,
obs_property_t *p,
obs_data_t *settings);
12 changes: 8 additions & 4 deletions src/filters/chromatic-aberration.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ void chromatic_aberration_destroy(retro_effects_filter_data_t *filter)

obs_leave_graphics();

obs_data_t *settings = obs_source_get_settings(filter->base->context);
bfree(filter->active_filter_data);
filter->active_filter_data = NULL;
}

void chromatic_aberration_unset_settings(retro_effects_filter_data_t* filter)
{
obs_data_t* settings = obs_source_get_settings(filter->base->context);
obs_data_unset_user_value(settings, "ca_type");
obs_data_unset_user_value(settings, "ca_red_offset");
obs_data_unset_user_value(settings, "ca_red_offset_angle");
Expand All @@ -29,9 +35,6 @@ void chromatic_aberration_destroy(retro_effects_filter_data_t *filter)
obs_data_unset_user_value(settings, "ca_blue_offset");
obs_data_unset_user_value(settings, "ca_blue_offset_angle");
obs_data_release(settings);

bfree(filter->active_filter_data);
filter->active_filter_data = NULL;
}

void chromatic_aberration_filter_update(retro_effects_filter_data_t *data,
Expand Down Expand Up @@ -227,6 +230,7 @@ chromatic_aberration_set_functions(retro_effects_filter_data_t *filter)
filter->filter_defaults = chromatic_aberration_filter_defaults;
filter->filter_update = chromatic_aberration_filter_update;
filter->filter_video_tick = NULL;
filter->filter_unset_settings = chromatic_aberration_unset_settings;
}

static void
Expand Down
2 changes: 2 additions & 0 deletions src/filters/chromatic-aberration.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ struct chromatic_aberration_filter_data {

extern void chromatic_aberration_create(retro_effects_filter_data_t *filter);
extern void chromatic_aberration_destroy(retro_effects_filter_data_t *filter);
extern void chromatic_aberration_unset_settings(retro_effects_filter_data_t* filter);

extern void chromatic_aberration_filter_video_render(retro_effects_filter_data_t *data);
extern void chromatic_aberration_filter_properties(retro_effects_filter_data_t *data,
obs_properties_t *props);
Expand Down
14 changes: 9 additions & 5 deletions src/filters/codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ void codec_destroy(retro_effects_filter_data_t *filter)
}
obs_leave_graphics();

obs_data_t *settings = obs_source_get_settings(filter->base->context);
bfree(filter->active_filter_data);
filter->active_filter_data = NULL;
}

void codec_unset_settings(retro_effects_filter_data_t* filter)
{
obs_data_t* settings = obs_source_get_settings(filter->base->context);
obs_data_unset_user_value(settings, "codec_px_scale");
obs_data_unset_user_value(settings, "codec_colors_per_channel");
obs_data_unset_user_value(settings, "codec_quality");
Expand All @@ -42,9 +48,6 @@ void codec_destroy(retro_effects_filter_data_t *filter)
obs_data_unset_user_value(settings, "codec_rpza_threshold_solid");
obs_data_unset_user_value(settings, "codec_rpza_threshold_gradient");
obs_data_release(settings);

bfree(filter->active_filter_data);
filter->active_filter_data = NULL;
}

float lerp(float x, float y, float a)
Expand Down Expand Up @@ -345,6 +348,7 @@ codec_set_functions(retro_effects_filter_data_t *filter)
filter->filter_defaults = codec_filter_defaults;
filter->filter_update = codec_filter_update;
filter->filter_video_tick = codec_filter_video_tick;
filter->filter_unset_settings = codec_unset_settings;
}

static void codec_load_effect(codec_filter_data_t *filter)
Expand Down Expand Up @@ -374,7 +378,7 @@ static void codec_load_effect(codec_filter_data_t *filter)
}
filter->effect_codec = gs_effect_create(shader_dstr.array, NULL, &errors);
obs_leave_graphics();

dstr_free(&shader_dstr);
bfree(shader_text);
if (filter->effect_codec == NULL) {
blog(LOG_WARNING,
Expand Down
2 changes: 2 additions & 0 deletions src/filters/codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ struct codec_filter_data {

extern void codec_create(retro_effects_filter_data_t *filter);
extern void codec_destroy(retro_effects_filter_data_t *filter);
extern void codec_unset_settings(retro_effects_filter_data_t* filter);

extern void codec_filter_video_tick(retro_effects_filter_data_t *data, float seconds);
extern void codec_filter_video_render(retro_effects_filter_data_t *data);
extern void codec_filter_properties(retro_effects_filter_data_t *data,
Expand Down
16 changes: 10 additions & 6 deletions src/filters/crt.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ void crt_create(retro_effects_filter_data_t *filter)
obs_data_release(settings);
}

void crt_destroy(retro_effects_filter_data_t *filter)
void crt_destroy(retro_effects_filter_data_t* filter)
{
crt_filter_data_t *data = filter->active_filter_data;
crt_filter_data_t* data = filter->active_filter_data;
obs_enter_graphics();
if (data->effect_crt) {
gs_effect_destroy(data->effect_crt);
Expand All @@ -30,7 +30,13 @@ void crt_destroy(retro_effects_filter_data_t *filter)
}
obs_leave_graphics();

obs_data_t *settings = obs_source_get_settings(filter->base->context);
bfree(filter->active_filter_data);
filter->active_filter_data = NULL;
}

void crt_unset_settings(retro_effects_filter_data_t* filter)
{
obs_data_t* settings = obs_source_get_settings(filter->base->context);
obs_data_unset_user_value(settings, "crt_phosphor_type");
obs_data_unset_user_value(settings, "crt_mask_intensity");
obs_data_unset_user_value(settings, "crt_bloom");
Expand All @@ -41,9 +47,6 @@ void crt_destroy(retro_effects_filter_data_t *filter)
obs_data_unset_user_value(settings, "crt_black_level");
obs_data_unset_user_value(settings, "crt_white_level");
obs_data_release(settings);

bfree(filter->active_filter_data);
filter->active_filter_data = NULL;
}

void crt_filter_update(retro_effects_filter_data_t *data, obs_data_t *settings)
Expand Down Expand Up @@ -344,6 +347,7 @@ static void crt_set_functions(retro_effects_filter_data_t *filter)
filter->filter_defaults = crt_filter_defaults;
filter->filter_update = crt_filter_update;
filter->filter_video_tick = NULL;
filter->filter_unset_settings = crt_unset_settings;
}

static void crt_load_effect(crt_filter_data_t *filter)
Expand Down
2 changes: 2 additions & 0 deletions src/filters/crt.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ struct crt_filter_data {

extern void crt_create(retro_effects_filter_data_t *filter);
extern void crt_destroy(retro_effects_filter_data_t *filter);
extern void crt_unset_settings(retro_effects_filter_data_t* filter);

extern void crt_filter_video_render(retro_effects_filter_data_t *data);
extern void crt_filter_properties(retro_effects_filter_data_t *data,
obs_properties_t *props);
Expand Down
13 changes: 9 additions & 4 deletions src/filters/digital-glitch.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,15 @@ void digital_glitch_destroy(retro_effects_filter_data_t *filter)

da_free(data->horiz_grid);
da_free(data->vert_grid);
da_free(data->rgb_drift_grid);

obs_data_t *settings = obs_source_get_settings(filter->base->context);
bfree(filter->active_filter_data);
filter->active_filter_data = NULL;
}

void digital_glitch_unset_settings(retro_effects_filter_data_t* filter)
{
obs_data_t* settings = obs_source_get_settings(filter->base->context);
obs_data_unset_user_value(settings, "digital_glitch_amount");
obs_data_unset_user_value(settings, "digital_glitch_max_disp");
obs_data_unset_user_value(settings, "digital_glitch_min_block_width");
Expand All @@ -52,9 +59,6 @@ void digital_glitch_destroy(retro_effects_filter_data_t *filter)
obs_data_unset_user_value(settings, "digital_glitch_min_rgb_interval");
obs_data_unset_user_value(settings, "digital_glitch_max_rgb_interval");
obs_data_release(settings);

bfree(filter->active_filter_data);
filter->active_filter_data = NULL;
}

void digital_glitch_filter_update(retro_effects_filter_data_t *data,
Expand Down Expand Up @@ -285,6 +289,7 @@ static void digital_glitch_set_functions(retro_effects_filter_data_t *filter)
filter->filter_defaults = digital_glitch_filter_defaults;
filter->filter_update = digital_glitch_filter_update;
filter->filter_video_tick = digital_glitch_filter_video_tick;
filter->filter_unset_settings = digital_glitch_unset_settings;
}

void digital_glitch_filter_video_tick(retro_effects_filter_data_t *data,
Expand Down
5 changes: 3 additions & 2 deletions src/filters/digital-glitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ struct digital_glitch_filter_data {

extern void digital_glitch_create(retro_effects_filter_data_t *filter);
extern void digital_glitch_destroy(retro_effects_filter_data_t *filter);
extern void
digital_glitch_filter_video_render(retro_effects_filter_data_t *data);
extern void digital_glitch_unset_settings(retro_effects_filter_data_t* filter);

extern void digital_glitch_filter_video_render(retro_effects_filter_data_t *data);
extern void digital_glitch_filter_properties(retro_effects_filter_data_t *data,
obs_properties_t *props);
extern void digital_glitch_filter_defaults(obs_data_t *settings);
Expand Down
12 changes: 8 additions & 4 deletions src/filters/dither.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ void dither_destroy(retro_effects_filter_data_t *filter)

obs_leave_graphics();

obs_data_t *settings = obs_source_get_settings(filter->base->context);
bfree(filter->active_filter_data);
filter->active_filter_data = NULL;
}

void dither_unset_settings(retro_effects_filter_data_t* filter)
{
obs_data_t* settings = obs_source_get_settings(filter->base->context);
obs_data_unset_user_value(settings, "dither_size");
obs_data_unset_user_value(settings, "dither_type");
obs_data_unset_user_value(settings, "dither_bayer_size");
Expand All @@ -35,9 +41,6 @@ void dither_destroy(retro_effects_filter_data_t *filter)
obs_data_unset_user_value(settings, "dither_offset_x");
obs_data_unset_user_value(settings, "dither_offset_y");
obs_data_release(settings);

bfree(filter->active_filter_data);
filter->active_filter_data = NULL;
}

void dither_filter_update(retro_effects_filter_data_t *data,
Expand Down Expand Up @@ -228,6 +231,7 @@ dither_set_functions(retro_effects_filter_data_t *filter)
filter->filter_defaults = dither_filter_defaults;
filter->filter_update = dither_filter_update;
filter->filter_video_tick = NULL;
filter->filter_unset_settings = dither_unset_settings;
}

static void dither_load_effect(dither_filter_data_t *filter)
Expand Down
2 changes: 2 additions & 0 deletions src/filters/dither.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ struct dither_filter_data {

extern void dither_create(retro_effects_filter_data_t *filter);
extern void dither_destroy(retro_effects_filter_data_t *filter);
extern void dither_unset_settings(retro_effects_filter_data_t* filter);

extern void dither_filter_video_render(retro_effects_filter_data_t *data);
extern void dither_filter_properties(retro_effects_filter_data_t *data,
obs_properties_t *props);
Expand Down
Loading

0 comments on commit c7d5cf2

Please sign in to comment.