Skip to content

Commit d08ed95

Browse files
committed
Fix crash due to undefined MIDI name variable
In ec445fe, the variable song_midi wasn't initialized properly when the greeting window was disabled, causing the program to crash. It's now defined both on startup and in the reset code. What caused this whole business is the fact that MIDI import happens in two steps: open_midi (parses all the info in the file) and import_midi (converts the data into note blocks after you've picked instruments, etc.) Before the latter occurs, all the song data is reset, which also resets the MIDI filename that was stored on the first step. That made it necessary to remove it from the reset script and, instead, reset the name on unusual places, like in the greeting window and in the call for creating a new song. Applied solution: The first variable, midifile, stores the name on the first step. Every reset copies its value to a second variable, song_midi, used only for display. midifile is then set to "". With that, song_midi holds the song name for that session and displays it properly. When a song is created or loaded, a reset will occur and "" will be copied into song_midi, effectively clearing the display. This also fixes an unintended side effect of how the name was being handled: if you loaded a MIDI but clicked 'Cancel' in the MIDI settings window, the name would still be displayed in song info. To prevent that from happening, the first variable (midifile) is reset when the user clicks 'Cancel', to prevent it from being copied over to the display variable (song_midi) on the next reset.
1 parent 292e718 commit d08ed95

File tree

7 files changed

+5
-7
lines changed

7 files changed

+5
-7
lines changed

scripts/control_create/control_create.gml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ tonextbackup = 0
4747
filename = ""
4848
changed = 0
4949
midifile = ""
50+
song_midi = ""
5051
for (a = 0; a < 11; a += 1) {
5152
mididevice_instrument[a] = -1
5253
recent_song[a] = ""

scripts/draw_window_greeting/draw_window_greeting.gml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ a += (a && (mouse_check_button(mb_left) || mouse_check_button_released(mb_left))
7676
draw_sprite(spr_frame2, a + 3 * theme, b, c)
7777
draw_sprite(spr_bigicons, 0, b + (a > 1), c + (a > 1))
7878
draw_text(b + 48 + (a > 1), c + 9 + (a > 1), "Create a new song")
79-
if (a = 2 && mouse_check_button_released(mb_left)) window = 0 song_midi = ""
79+
if (a = 2 && mouse_check_button_released(mb_left)) window = 0
8080

8181
c += 44
8282
b = x1 + 300

scripts/draw_window_midi_import/draw_window_midi_import.gml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ if (draw_checkbox(x1 + 300, y1 + 72, w_midi_octave, "Keep within octave range",
2121
if (draw_checkbox(x1 + 300, y1 + 92, w_midi_vel, "Read note velocity", "Whether to copy the volume data found\nin each MIDI note.") && wmenu = 0) w_midi_vel=!w_midi_vel
2222
if (draw_checkbox(x1 + 12, y1 + 374, w_midi_remember, "Remember changes", "Whether to use these settings the\nnext time you import a MIDI file.") && wmenu = 0) w_midi_remember=!w_midi_remember
2323
if (draw_button2(x1 + 520, y1 + 368, 72, "Import") && wmenu = 0) {w_midi_tab = 0 window = -1 import_midi()}
24-
if (draw_button2(x1 + 520 - 80, y1 + 368, 72, "Cancel") && wmenu = 0) {w_midi_tab = 0 window = 0}
24+
if (draw_button2(x1 + 520 - 80, y1 + 368, 72, "Cancel") && wmenu = 0) {midifile = "" w_midi_tab = 0 window = 0}
2525
if (draw_button2(x1 + 520 - 160, y1 + 368, 72, "Use default") && wmenu = 0) {
2626
if (question("Are you sure?", "Confirm")) {
2727
midi_instruments()

scripts/load_song/load_song.gml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,7 @@ if (file_ext = ".nbs") {
8686
a = buffer_read_int()
8787
work_remove = max(0, a)
8888
// MIDI FILENAME
89-
a = buffer_read_string_int()
90-
if (filename_ext(a) = ".mid" || filename_ext(a) = ".midi") song_midi = a
91-
else song_midi = ""
89+
song_midi = buffer_read_string_int()
9290
// LOOP
9391
if (song_nbs_version >= 4) {
9492
loop = buffer_read_byte()

scripts/new_song/new_song.gml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// new_song()
2-
song_midi = ""
32
if (confirm() > -1) {
43
reset()
54
backup_clear()

scripts/open_midi/open_midi.gml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ if (r != 0 && r != 1 && r != 2) {message("Error loading MIDI file:\n\nFormat not
2525

2626
midi_tracks = buffer_read_short_be()
2727
midifile = filename_name(fn)
28-
song_midi = string(midifile)
2928
midi_trackamount[midi_tracks] = 0
3029
reset_midi()
3130
midi_tempo = buffer_read_short_be()

scripts/reset/reset.gml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ for (a = 0; a <= enda; a += 1) {
2626
// File
2727
filename = ""
2828
changed = 0
29+
song_midi = midifile
2930
midifile = ""
3031

3132
// Playback

0 commit comments

Comments
 (0)