From 4af68dc72cac992303ff6ae353002ddd369c780c Mon Sep 17 00:00:00 2001 From: jatin Date: Tue, 27 May 2025 12:38:54 -0700 Subject: [PATCH] Make sure that it's okay to detroy a null object --- .gitignore | 2 +- chowdsp_convolution.cpp | 6 ++++-- test/chowdsp_convolution_test.cpp | 14 +++++++++----- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 324378d..aec0873 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ build*/ .focus-config -.raddbg_project +*.raddbg_project .vscode/ .idea/ diff --git a/chowdsp_convolution.cpp b/chowdsp_convolution.cpp index 1d5bfd3..28d41e1 100644 --- a/chowdsp_convolution.cpp +++ b/chowdsp_convolution.cpp @@ -35,7 +35,8 @@ void create_config (Config* config, int max_block_size) void destroy_config (Config* config) { - fft::fft_destroy_setup (config->fft); + if (config->fft != nullptr) + fft::fft_destroy_setup (config->fft); *config = {}; } @@ -215,7 +216,8 @@ void reset_process_state (const Config* config, Process_Uniform_State* state) void destroy_process_state (Process_Uniform_State* state) { - fft::aligned_free (state->state_data[0].segments); + if (state->state_data != nullptr) + fft::aligned_free (state->state_data[0].segments); *state = {}; } diff --git a/test/chowdsp_convolution_test.cpp b/test/chowdsp_convolution_test.cpp index 95b394b..3357f12 100644 --- a/test/chowdsp_convolution_test.cpp +++ b/test/chowdsp_convolution_test.cpp @@ -351,10 +351,12 @@ static bool test_convolution (int ir_length_samples, int block_size, int num_blo std::vector test_output (input.size()); chowdsp::convolution::Config conv_config {}; + chowdsp::convolution::destroy_config (&conv_config); // destroying an empty config should be okay... chowdsp::convolution::create_config (&conv_config, block_size); auto* fft_scratch = (float*) chowdsp::fft::aligned_malloc (conv_config.fft_size * sizeof (float)); chowdsp::convolution::IR_Uniform conv_ir {}; + chowdsp::convolution::destroy_ir (&conv_ir); // destroying an empty IR should be okay... chowdsp::convolution::create_ir (&conv_config, &conv_ir, ir.data(), @@ -362,6 +364,7 @@ static bool test_convolution (int ir_length_samples, int block_size, int num_blo fft_scratch); chowdsp::convolution::Process_Uniform_State conv_state {}; + chowdsp::convolution::destroy_process_state (&conv_state); // destroying an empty state should be okay... chowdsp::convolution::create_process_state (&conv_config, &conv_ir, &conv_state); start = std::chrono::high_resolution_clock::now(); @@ -577,11 +580,11 @@ static bool test_convolution_non_uniform (int ir_length_samples, int block_size, chowdsp::convolution::Config tail_config {}; chowdsp::convolution::create_config (&tail_config, head_size); - chowdsp::convolution::IR_Non_Uniform conv_ir { - .head_config = &head_config, - .tail_config = &tail_config, - .head_size = head_size, - }; + chowdsp::convolution::IR_Non_Uniform conv_ir {}; + chowdsp::convolution::destroy_nuir (&conv_ir); + conv_ir.head_config = &head_config; + conv_ir.tail_config = &tail_config; + conv_ir.head_size = head_size; auto* scratch = (float*) chowdsp::fft::aligned_malloc (chowdsp::convolution::get_required_nuir_scratch_bytes (&conv_ir)); chowdsp::convolution::create_nuir (&conv_ir, @@ -590,6 +593,7 @@ static bool test_convolution_non_uniform (int ir_length_samples, int block_size, scratch); chowdsp::convolution::Process_Non_Uniform_State conv_state {}; + chowdsp::convolution::destroy_nuir_process_state (&conv_state); // destroying an empty state should be okay... chowdsp::convolution::create_nuir_process_state (&conv_ir, &conv_state); start = std::chrono::high_resolution_clock::now();