Created .exe, when running .exe error unable to load audio file

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
Nine Iron
Prole
Posts: 13
Joined: Fri Oct 09, 2020 5:59 am

Re: Created .exe, when running .exe error unable to load audio file

Post by Nine Iron »

function requireFiles(files)
for _, file in ipairs(files) do
local file = file:sub(1, -5)
require(file)
end
end

I have the program run through a few folders containing .lua files and it saves me from adding all the requires in main.lua.
User avatar
pgimeno
Party member
Posts: 3548
Joined: Sun Oct 18, 2015 2:58 pm

Re: Created .exe, when running .exe error unable to load audio file

Post by pgimeno »

That can't be it, then, because it either works or doesn't work, and doesn't affect love.audio.

I'm out of ideas as to why love.audio can be nil at that point, and only when the executable is fused.
RNavega
Party member
Posts: 246
Joined: Sun Aug 16, 2020 1:28 pm

Re: Created .exe, when running .exe error unable to load audio file

Post by RNavega »

Does the audio system exist at the point where the 'newSource' function gets called? Regarding the timeline of events, is the sound loading at least invoked from within love.load() or later?

I would be concerned with using LÖVE's systems/API at any point before love.load() is called. Later than that should be fine (after all systems were initialized).
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Created .exe, when running .exe error unable to load audio file

Post by grump »

RNavega wrote: Mon Oct 12, 2020 9:51 pm I would be concerned with using LÖVE's systems/API at any point before love.load() is called. Later than that should be fine (after all systems were initialized).
AFAIK, love.load has no technical relevance. Anything you can do in in love.load, you can do at the top level of main.lua.

The error here is almost certainly a user error, but we can't be sure unless OP posts an example that reproduces the error.
User avatar
Nine Iron
Prole
Posts: 13
Joined: Fri Oct 09, 2020 5:59 am

Re: Created .exe, when running .exe error unable to load audio file

Post by Nine Iron »

RNavega wrote: Mon Oct 12, 2020 9:51 pm Does the audio system exist at the point where the 'newSource' function gets called? Regarding the timeline of events, is the sound loading at least invoked from within love.load() or later?

I would be concerned with using LÖVE's systems/API at any point before love.load() is called. Later than that should be fine (after all systems were initialized).
The newSource is in a file named sound.lua. It names a few sources and has two play functions, just simple audio.play(). The only mention of sound.lua before love.load() is the require for the file. As far as I've read, you can do anything above love.load() and it will read it as if it's in or below love.load().


The error traces back to my require function, which consists of

------

local conf_files = {}
recursiveEnumerate('conf', conf_files)
requireFiles(conf_files)
local object_files = {}
recursiveEnumerate('objects', object_files)
requireFiles(object_files)
local room_files = {}
recursiveEnumerate('rooms', room_files)
requireFiles(room_files)

----- from there it sends the files to...

function recursiveEnumerate(folder, file_list)
local items = love.filesystem.getDirectoryItems(folder)
for _, item in ipairs(items) do
local file = folder .. '/' .. item
if love.filesystem.getInfo(file, 'file') then
table.insert(file_list, file)
elseif love.filesystem.getInfo(file, 'directory') then
--recursiveEnumerate(file, file_list)
end
end
end

function requireFiles(files)
for _, file in ipairs(files) do
local file = file:sub(1, -5)
require(file)
end
end


I commented out the rE() for the directory because it was causing issues, I probably have something wrong but wasn't ready to dive into that issue yet. When I commented out the rE() the program ran fine. As long as I wasn't trying to run the exe.




For the person asking about sound.lua contents, I just saw your comment. Here it is.

missilefx = love.audio.newSource("sound/missile.ogg", "static")
pew = love.audio.newSource("sound/pew.ogg", "static")
splat = love.audio.newSource("sound/splat.ogg", "static")
franks = love.audio.newSource("sound/franks.ogg", "stream")
coinappear = love.audio.newSource("sound/coin.ogg", "static")
coincollect = love.audio.newSource("sound/coincollect.ogg", "static")
thunder = love.audio.newSource('sound/thunder.ogg', 'static')
pain = love.audio.newSource('sound/pain.ogg', 'stream')
pain:setLooping(true)
franks:setLooping(true)
love.audio.setVolume(.01)


function music(x)
local sound = x
if sound:isPlaying() == false then
playSound(sound)
end
end


function playSound(sound)
sound:play()
end
User avatar
pgimeno
Party member
Posts: 3548
Joined: Sun Oct 18, 2015 2:58 pm

Re: Created .exe, when running .exe error unable to load audio file

Post by pgimeno »

The error message says: "attempt to index field 'audio' (a nil value)".

This says that:
  • 'audio' is a field of a table (keyword: field). The only table that fits in the line given is 'love';
  • The 'audio' field is nil;
  • the code is attempting to access an index inside of 'audio' but 'audio' is nil instead of a table, and can't be indexed.
This exact error message is easily reproducible with this setup:

Code: Select all

love.audio = nil
love.audio.newSource("abc", "stream")
It meets all three requisites that lead to that error message.

Alternatively, placing 'c.modules.audio = false' without 'love.audio = nil' inside love.conf also leads to that message.

If the 'love.audio = nil' line is taken out, without disabling the audio module, the error message is different:

Code: Select all

Error: Could not open file abc. Does not exist.
That's the actual error when a file does not exist. I was confused at the beginning because I assumed that this was the error that Nine Iron was getting, because he said that the file couldn't be found. But the error message does not point to a problem with finding the file.

Something is clearing the audio table/module when the error is triggered. But I can't figure out what, with the information given so far.

@Nine Iron, do you think you can trim down your project to a point where the problem is still reproducible, but you're comfortable with sharing it? That is, removing everything after (including love.draw, love.update and so on, and maybe replacing some required modules with empty files, and the assets with dummy assets).
User avatar
Nine Iron
Prole
Posts: 13
Joined: Fri Oct 09, 2020 5:59 am

Re: Created .exe, when running .exe error unable to load audio file

Post by Nine Iron »

pgimeno wrote: Tue Oct 13, 2020 8:24 pm
@Nine Iron, do you think you can trim down your project to a point where the problem is still reproducible, but you're comfortable with sharing it? That is, removing everything after (including love.draw, love.update and so on, and maybe replacing some required modules with empty files, and the assets with dummy assets).
To be honest, I'd probably share the whole thing. It's just a stupid little incomplete level I put together while learning some lua.

I can't recreate the error though. I've gone through this thread at least three times to check that I've undone everything I mentioned. After deleting and replacing the zip file contents and the making a new exe, it runs every time.

I've tried manual require of sound.lua from multiple folders. I've tried having it called from the require function. The only errors I've seen are syntax related, nothing stating that index field 'audio' is invalid. The commented line in the rE() function for directory was set long before I tried to make the exe.

The conf settings were never touched. I listed all the values the wiki suggested long before I tried making the exe as well. t.modules.audio was always set to true.

I haven't touched this project since I started the thread, other than the changes I've listed. I couldn't get it to run in the beginning, now I can't get it to fail. :\
Post Reply

Who is online

Users browsing this forum: No registered users and 136 guests