You may know that I have a mostly-weekly stream with @AutomaticTiger where we play random Game Boy games. I have fully automated this using Firebot so that I don't have to open games manually - it pulls the filename from a txt file, then runs Retroarch using two arguments, one to pick the core and one for the ROM file.
Lately, this has stopped working on about 1 in 10 games, and it seemed completely random. Loading the exact same ROM manually worked just fine, so it wasn't the ROMs. So I set out to troubleshoot this today.
What follows is exactly how I went about this and the absolutely dumbfounding conclusion.
Step 1: Testing
I added a log file that would save the commands any time I randomized a ROM. Then, I just hit the button over and over until I found a ROM that failed to load. This was the exact set of arguments for the first failed launch:
-L "D:\Emulation\Emulators\Retroarch Feb 21 2023\cores\gambatte_libretro.dll" "D:\Emulation\ROMs\GBRandom\Palamedes.gb"
(scroll to the right for the filename)
The rom exists exactly where it's specified, and loading it manually works - all of this is expected.
I ran it some more until I got one more failed launch, so I could see if there was some sort of pattern. The next failure was:
-L "D:\Emulation\Emulators\Retroarch Feb 21 2023\cores\gambatte_libretro.dll" "D:\Emulation\ROMs\GB\GBRandom\Puzznic.gb"
So we've got a few things in common here:
- They both have short filenames
- They both are .gb rather than .gbc
- They have no special characters at all
- They both...start with P??
Step 2: Process of elimination
We have four theories so far. It's time to start ruling them out.
First, I tried running both of those arguments a second time through Firebot, to make sure it wasn't truly at random. Nope, they both failed again. So we have consistency.
Next, I tried using a shortcut to Retroarch in windows (rather than Firebot) with those arguments. I fully expected this to fail as well, but to my surprise they both worked just fine!! So what the hell is different about doing this in Windows vs. Firebot?
So we have to troubleshoot Firebot only, which is a relief honestly. I started changing the workflow in Firebot manually to test different ROMs:
- Puzzled.gbc: Failed. This rules out that the file extension is the issue
- Pyramids of Ra.gb: Success. This rules out the P theory
- 1942.gbc: Failed. So it's not just ROMs with exactly 7 character names - maybe short file names are still a problem?
- Aladdin.gb: Failed. this really doesn't tell me anything, but I start renaming the file to test further theories. I'm starting to think it's the length of the filename:
- Aladdin2.gb: Failed. So 8 characters is not enough.
- Aladdin21. gb: Failed. 9 Characters still not enough
- Aladdin and the story of my balls.gb: Success? So extremely long file names do work, but why?
- Aladdin21321312312312.gb: Failed?? So it's not the length after all.
Step 3: Forming a Hypothesis
So if it's not the ROM itself, the arguments, the length of the filename, the extension, or the beginning character, then what the hell is the problem?
Well, so far the only ones that have successfully run are file names with spaces in them. The only ones that have failed do not have spaces. What the fuck?? So let's test that too:
- a a.gb: Success.
So the file name has to have a space to work??? but only when launched from Firebot???!?!
But yes, every time I try a file name with a space it works. Without a space, it fails.
Step 4: A theory as to what the fuck is going on
Obviously, the answer is "computers are bad and should feel bad." But my guess, and this is just a guess, is that the quotes are throwing this off. Let's look at that first failed argument again:
-L "D:\Emulation\Emulators\Retroarch Feb 21 2023\cores\gambatte_libretro.dll" "D:\Emulation\ROMs\GBRandom\Palamedes.gb"
The second string is surrounded by quotes, but technically they aren't needed. There are no special characters anywhere in there, including spaces. So you could run this without quotes.
My guess is that you must run this without quotes, and the only reason it works in a Windows shortcut is because they automatically strip unnecessary quotes. But Firebot doesn't know to do that, so it doesn't.
Step 5: Find a solution
I could somehow add a space to every file name, but I really don't want to do that. Instead, I simply add a space to the folder name, and rewrite the argument like so:
-L "D:\Emulation\Emulators\Retroarch Feb 21 2023\cores\gambatte_libretro.dll" "D:\Emulation\ROMs\GB Random\Palamedes.gb"
And now it works. Every test I run works just fine. It's fine. Everything is fine now.
Step 6: Try your best not to think about the fact that these machines we rely on for almost every task in our lives can fail in ways that seem almost absurdly random, cruel even, and that only through the massive effort of bugtesters, QA people, software developers, and schmucks on the internet does anything continue to run. Don't think about how fragile all of this is, how a single character can mean the difference between success and failure, how our entire infrastructure could melt like a sand castle at high tide simply because someone accidentally put a space after their last name when submitting a form to their bank.
Don't think about it.
