Skip to content

Commit 0e13cf3

Browse files
committed
Fixed a potential error that could prevent the music loader from loading all music files in a directory (#96)
1 parent c7c24b0 commit 0e13cf3

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

source/music.lua

+28-24
Original file line numberDiff line numberDiff line change
@@ -362,33 +362,37 @@ function music.loadStageMusicInDir(stageid, name)
362362
for k, file in ipairs(files) do
363363
local filepath = ("%s/%s"):format(name, file)
364364
local info = love.filesystem.getInfo(filepath)
365-
if info.type == "file" then
366-
local ext = string.getFileExtension(file):lower()
367-
368-
if valid_music_ext[ext] then
369-
local success, source = pcall(love.audio.newSource, filepath, "stream")
370-
if success and source then
371-
loaded = loaded + 1
372-
373-
-- Insert the newly loaded track into a random position in the playlist
374-
local pos = math.random(1, #music.PLAYLIST)
375-
local prob = tonumber(string.match(filepath, "[^%._\n]+_(%d+)%.%w+$")) or 1
376-
377-
if prob > 1 then
378-
music.USE_WEIGHTS = true
379-
end
380-
381-
local wavinfo
382-
if ext == "wav" then
383-
wavinfo = wav.parse(filepath)
365+
if info then
366+
if info.type == "file" then
367+
local ext = string.getFileExtension(file):lower()
368+
369+
if valid_music_ext[ext] then
370+
local success, source = pcall(love.audio.newSource, filepath, "stream")
371+
if success and source then
372+
loaded = loaded + 1
373+
374+
-- Insert the newly loaded track into a random position in the playlist
375+
local pos = math.random(1, #music.PLAYLIST)
376+
local prob = tonumber(string.match(filepath, "[^%._\n]+_(%d+)%.%w+$")) or 1
377+
378+
if prob > 1 then
379+
music.USE_WEIGHTS = true
380+
end
381+
382+
local wavinfo
383+
if ext == "wav" then
384+
wavinfo = wav.parse(filepath)
385+
end
386+
table.insert(music.PLAYLIST, pos, {STREAM = source, WEIGHT = prob, WAV = wavinfo})
387+
else
388+
local err = ("invalid music file \"%s/%s\""):format(name, file)
389+
log.error("[MUSIC] %s", err)
390+
notification.error(err)
384391
end
385-
table.insert(music.PLAYLIST, pos, {STREAM = source, WEIGHT = prob, WAV = wavinfo})
386-
else
387-
local err = ("invalid music file \"%s/%s\""):format(name, file)
388-
log.error("[MUSIC] %s", err)
389-
notification.error(err)
390392
end
391393
end
394+
else
395+
log.warn("[MUSIC] Unable to get file information for file %q", filepath)
392396
end
393397
end
394398
if loaded > 0 then

0 commit comments

Comments
 (0)