Io.open failing with "Invalid Argument" (Solved - self inflicted)

Im running an io.open command to read in some data files from a fixed location. It works on my Desktop machine fine (Win 11 Pro +i9 and RTX 3070). however, when I run the same code on my laptop (Win 11 Home + i9 RTX 4070) it throws the error using the io.open.
Here is the sample command:

local fh, err = io.open( assetfilename, "rb" )
if( fh == nil ) then 
     pprint("[Error] Cannot open asset file: "..assetfilename.." with error: "..tostring(err) )
     return nil
end

The file path has ben checked. Ive used full paths, relative paths, win paths and linux paths. But I would expect a “File Not Found” err instead. So this is a little confusing.

Other things I tried were admin rights, file rights and similar security/firewall settings.
I was wondering if it might be timing. This occurs very early in the startup process of the application and I wonder because my laptop is quite a bit quicker than my desktop, that there is some incomplete setup for lua when its being called (grasping at straws, I know).

If anyone could make some suggestions or knows what might be causing this, Id be extremely grateful.

Well, if the Lua context is created, then it should work as expected.
I guess you could delay your io.open to verify.

Also, does it work when using vanilla Lua in the engine?
Does it work when using vanilla Lua or LuaJIT from the command line?

Thanks. Good questions. Will give that a try. Ive tried a few different files too, with no luck. Its odd the exact same code (from same repo with no changes) runs fine on my desktop. I keep trying to think of hw or os differences that could do this.

Is it a long path, and only one of the systems has NTFS long path support enabled?

1 Like

Its about 30 chars: one example: data/environments/default/default.glb
As mentioned Ive tried this with correct system path and with windows and linux pathing separators. Its quite odd. Im kinda wondering if its a windows 11 home folder permissions thing (that was my initial thought). Im tempted to reinstall win to windows 11 pro, but thats a pretty reasonable amount of time to do just to try out a possible fix.
Have run Defold as administrator too, which didnt help. Its a very curious one. Maybe theres a service blocking access? dunno.

At this stage I might try something like Process Monitor

2 Likes

Ok. I think I know what is causing this. It is permissions. The laptop is very new and it uses microsofts default install setup which is to use OneDrive for all the main user folders and it provides. And additionally the user login is different to the file account user (which is utterly annoying). The result is, I need to re-install and setup the windows 11 myself. I’ll probably buy and install win11 pro and also upgrade the hdd at the same time :slight_smile:

The way I found this was via the security settings. There were some odd grayed out permissions for the one of the users that Windows had created when I setup the machine. I then found it was that user that Defold was running as. Uggh… windows.

Thanks to all for their suggestions. Going to mark this as solved.

I ordered a new ssd, and started the whole process. But I thought Id try another old laptop. And… there it is . The same problem.

Ive then sprinkled the code with io.open in various places earlier than the problem call. And in some places, it works ok. Which kinda deepens the mystery. Maybe Ive left a file handle open? Or maybe there is a file handle limit somewhere and I have too many open. More investigation needed.

OMG. Whitespace characters. There was a \r in the end of the filenames. You couldnt really see it when debugging :slight_smile: because it looked fine in the log. I was also cutting the line from the log and using that to load, and it was fine.

The problem was, that some assets use a config file to load their mesh data. And some of those files had different line endings than that others. Uggh. Sorry to bother everyone. Stupid Dave again.

6 Likes