Fix audio load fclose crashes

This commit is contained in:
Allen Webster 2021-01-17 12:56:49 -08:00
parent 3ff0968538
commit ee3ad5c0e0
5 changed files with 376 additions and 365 deletions

View File

@ -262,9 +262,12 @@ audio_clip_from_wav_FILE(Arena *arena, FILE *file){
function Audio_Clip
audio_clip_from_wav_file_name(Arena *arena, char *file_name){
Audio_Clip result = {};
String_Const_u8 data = {};
FILE *file = fopen(file_name, "rb");
Audio_Clip result = audio_clip_from_wav_FILE(arena, file);
if (file != 0){
result = audio_clip_from_wav_FILE(arena, file);
fclose(file);
}
return(result);
}

View File

@ -217,9 +217,11 @@ CUSTOM_DOC("Starts the music.")
if (the_music_clip.sample_count == 0){
Scratch_Block scratch(app);
FILE *file = def_search_normal_fopen(scratch, "audio_test/chtulthu.wav", "rb");
if (file != 0){
the_music_clip = audio_clip_from_wav_FILE(&global_permanent_arena, file);
fclose(file);
}
}
if (!def_audio_is_playing(&the_music_control)){
the_music_control.loop = true;
@ -242,9 +244,11 @@ CUSTOM_DOC("Play the hit sound effect")
if (the_hit_clip.sample_count == 0){
Scratch_Block scratch(app);
FILE *file = def_search_normal_fopen(scratch, "audio_test/hit.wav", "rb");
if (file != 0){
the_hit_clip = audio_clip_from_wav_FILE(&global_permanent_arena, file);
fclose(file);
}
}
local_persist u32 index = 0;
local_persist Audio_Control controls[8] = {};

View File

@ -340,7 +340,7 @@ static Command_Metadata fcoder_metacmd_table[252] = {
{ PROC_LINKS(goto_prev_jump_no_skips, 0), false, "goto_prev_jump_no_skips", 23, "If a buffer containing jump locations has been locked in, goes to the previous jump in the buffer, and does not skip sub jump locations.", 136, "../code/custom/4coder_jump_sticky.cpp", 37, 511 },
{ PROC_LINKS(hide_filebar, 0), false, "hide_filebar", 12, "Sets the current view to hide it's filebar.", 43, "../code/custom/4coder_base_commands.cpp", 39, 704 },
{ PROC_LINKS(hide_scrollbar, 0), false, "hide_scrollbar", 14, "Sets the current view to hide it's scrollbar.", 45, "../code/custom/4coder_base_commands.cpp", 39, 690 },
{ PROC_LINKS(hit_sfx, 0), false, "hit_sfx", 7, "Play the hit sound effect", 25, "../code/custom/4coder_examples.cpp", 34, 238 },
{ PROC_LINKS(hit_sfx, 0), false, "hit_sfx", 7, "Play the hit sound effect", 25, "../code/custom/4coder_examples.cpp", 34, 240 },
{ PROC_LINKS(hms_demo_tutorial, 0), false, "hms_demo_tutorial", 17, "Tutorial for built in 4coder bindings and features.", 51, "../code/custom/4coder_tutorial.cpp", 34, 869 },
{ PROC_LINKS(if0_off, 0), false, "if0_off", 7, "Surround the range between the cursor and mark with an '#if 0' and an '#endif'", 78, "../code/custom/4coder_combined_write_commands.cpp", 49, 70 },
{ PROC_LINKS(if_read_only_goto_position, 0), false, "if_read_only_goto_position", 26, "If the buffer in the active view is writable, inserts a character, otherwise performs goto_jump_at_cursor.", 106, "../code/custom/4coder_jump_sticky.cpp", 37, 564 },
@ -416,7 +416,7 @@ static Command_Metadata fcoder_metacmd_table[252] = {
{ PROC_LINKS(multi_paste_interactive, 0), false, "multi_paste_interactive", 23, "Paste multiple lines from the clipboard history, controlled with arrow keys", 75, "../code/custom/4coder_clipboard.cpp", 35, 371 },
{ PROC_LINKS(multi_paste_interactive_quick, 0), false, "multi_paste_interactive_quick", 29, "Paste multiple lines from the clipboard history, controlled by inputing the number of lines to paste", 100, "../code/custom/4coder_clipboard.cpp", 35, 380 },
{ PROC_LINKS(music_start, 0), false, "music_start", 11, "Starts the music.", 17, "../code/custom/4coder_examples.cpp", 34, 213 },
{ PROC_LINKS(music_stop, 0), false, "music_stop", 10, "Stops the music.", 16, "../code/custom/4coder_examples.cpp", 34, 232 },
{ PROC_LINKS(music_stop, 0), false, "music_stop", 10, "Stops the music.", 16, "../code/custom/4coder_examples.cpp", 34, 234 },
{ PROC_LINKS(open_all_code, 0), false, "open_all_code", 13, "Open all code in the current directory. File types are determined by extensions. An extension is considered code based on the extensions specified in 4coder.config.", 164, "../code/custom/4coder_project_commands.cpp", 42, 805 },
{ PROC_LINKS(open_all_code_recursive, 0), false, "open_all_code_recursive", 23, "Works as open_all_code but also runs in all subdirectories.", 59, "../code/custom/4coder_project_commands.cpp", 42, 814 },
{ PROC_LINKS(open_file_in_quotes, 0), false, "open_file_in_quotes", 19, "Reads a filename from surrounding '\"' characters and attempts to open the corresponding file.", 94, "../code/custom/4coder_base_commands.cpp", 39, 1576 },

BIN
custom/metadata_generator Executable file

Binary file not shown.

View File

@ -26,35 +26,39 @@ load_paths = {
commands = {
.build_x64 = {
.win = "echo build: x64 & bin\build.bat",
.win = "echo build: x64 & bin\\build.bat",
.linux = "echo build: x64 & bin/build-linux.sh",
.out = "*compilation*",
.footer_panel = true,
.save_dirty_files = true,
.cursor_at_end = false,
},
.build_x86 = {
.win = "echo build: x86 & bin\build.bat /DDEV_BUILD_X86",
.win = "echo build: x86 & bin\\build.bat /DDEV_BUILD_X86",
.linux = "echo build: x86 & bin/build-linux.sh /DDEV_BUILD_X86",
.out = "*compilation*",
.footer_panel = true,
.save_dirty_files = true,
.cursor_at_end = false,
},
.package = {
.win = "echo package & bin\package.bat",
.win = "echo package & bin\\package.bat",
.linux = "echo package & bin/package.sh",
.out = "*compilation*",
.footer_panel = false,
.save_dirty_files = true,
.cursor_at_end = false,
},
.run_one_time = {
.win = "pushd ..\build & one_time",
.win = "pushd ..\\build & one_time",
.linux = "pushd ../build & one_time",
.out = "*run*",
.footer_panel = false,
.save_dirty_files = false,
.cursor_at_end = false,
},
.build_custom_api_docs = {
.win = "custom\bin\build_one_time docs\4ed_doc_custom_api_main.cpp ..\build",
.win = "custom\\bin\\build_one_time docs\\4ed_doc_custom_api_main.cpp ..\\build",
.out = "*compilation*",
.footer_panel = true,
.save_dirty_files = true,