diff --git a/Backends/Kinc-hxcpp/lib/khalib/loader.c b/Backends/Kinc-hxcpp/lib/khalib/loader.c index c21708578..15d2a3af7 100644 --- a/Backends/Kinc-hxcpp/lib/khalib/loader.c +++ b/Backends/Kinc-hxcpp/lib/khalib/loader.c @@ -31,7 +31,7 @@ static bool string_ends_with(char *str, const char *end) { return strcmp(&str[str_len - end_len], end) == 0; } -static void run(void* param) { +static void run(void *param) { for (;;) { kinc_event_wait(&event); @@ -54,7 +54,7 @@ static void run(void* param) { kinc_file_reader_t reader; if (kinc_file_reader_open(&reader, next.name, KINC_FILE_TYPE_ASSET)) { next.data.blob.size = kinc_file_reader_size(&reader); - next.data.blob.bytes = (uint8_t*)malloc(next.data.blob.size); + next.data.blob.bytes = (uint8_t *)malloc(next.data.blob.size); kinc_file_reader_read(&reader, next.data.blob.bytes, next.data.blob.size); kinc_file_reader_close(&reader); } @@ -75,7 +75,8 @@ static void run(void* param) { free(data); next.error = true; } - } else { + } + else { next.error = true; } break; @@ -96,16 +97,22 @@ static void run(void* param) { } else { kinc_a1_sound_t *sound = kinc_a1_sound_create(next.name); - next.data.sound.size = sound->size * 2; - next.data.sound.samples = (float *)malloc(next.data.sound.size * sizeof(float)); - for (int i = 0; i < sound->size; ++i) { - next.data.sound.samples[i * 2 + 0] = (float)(sound->left[i] / 32767.0); - next.data.sound.samples[i * 2 + 1] = (float)(sound->right[i] / 32767.0); + if (sound != NULL) { + next.data.sound.size = sound->size * 2; + next.data.sound.samples = (float *)malloc(next.data.sound.size * sizeof(float)); + for (int i = 0; i < sound->size; ++i) { + next.data.sound.samples[i * 2 + 0] = (float)(sound->left[i] / 32767.0); + next.data.sound.samples[i * 2 + 1] = (float)(sound->right[i] / 32767.0); + } + next.data.sound.channels = sound->format.channels; + next.data.sound.sample_rate = sound->format.samples_per_second; + next.data.sound.length = + (sound->size / (sound->format.bits_per_sample / 8) / sound->format.channels) / (float)sound->format.samples_per_second; + kinc_a1_sound_destroy(sound); + } + else { + next.error = true; } - next.data.sound.channels = sound->format.channels; - next.data.sound.sample_rate = sound->format.samples_per_second; - next.data.sound.length = (sound->size / (sound->format.bits_per_sample / 8) / sound->format.channels) / (float)sound->format.samples_per_second; - kinc_a1_sound_destroy(sound); } break; } diff --git a/Kinc b/Kinc index df90cbfbd..dd1a661c6 160000 --- a/Kinc +++ b/Kinc @@ -1 +1 @@ -Subproject commit df90cbfbd8fcf2bf8df3600739f5ca782471d5c9 +Subproject commit dd1a661c67f5c99bf9c5090ef85c04901abc57cb