8/20/2014 – WTF Windows

It seems like every day I’m fighting with some obscure limitation with the engine or the OS instead of polishing the gameplay or implementing more quest stuff. Really frustrating.

Today I crashed into an absurd limit: the 259 max character limit for file paths in Windows. A exceptionally deep part of my WIGroup hierarchy produced a 160+ character path, which when combined with the path of the project resulted in 263 characters. So the file wouldn’t save, resulting in lost progress and disappearing items.

I briefly considered truncating the offending group names so the items would save. But there’s no arbitrary limit on WIGroup hierarchy depth so that would only be a temporary solution. *sigh* better squash this permanently.

I know for a fact that NTFS file system supports file paths with up to 32,000 characters. So I looked into libraries that circumvented the ridiculous limit that the Windows API forces on you. At that moment I didn’t care that this solution would be Windows-specific – I just wanted the problem gone so I could move forward. But it was a moot point anyway – all of the libraries available required tools that aren’t included in the .NET 2.0 subset that Unity forces me to use. Oh well, whatever. Guess I’ll roll up my sleeves and implement a cross-platform solution. Maybe Unity’s half-assed 2.0 subset actually saved me some trouble down the road.

Soooo I ended up implementing a string compression system that takes these uber-long paths and converts them to a guaranteed-to-be-unique 64-bit integer, which is then converted to hexadecimal for a (semi) readable directory name (eg Root.World.C-2-3-14.WI.AG becomes 9BDB8EA3B81D90AE). Thankfully because I’m not an idiot I funnel every request to save and load through two primary functions, both of which are abstracted to hell before any in-game object touches them. So I was able to make this change relatively painlessly. This setup kind of cramps modding in my opinion (since you could actually browse the hierarchy as it existed in game before, where now you have to jot down IDs to find stuff) but whatever. Gotta do what you gotta do.

Just so we’re clear here: My goal was to save a file to disk.

Save a file.

To disk.

Save. A. File. To. Disk. For fuck’s sake. Could today have been any less productive? I doubt it. Thanks, Windows!

Read more here: 8/20/2014 – WTF Windows