[RESOLVED] Custom file system prematurely decides on bad file

Hi! I’m working on implementing FMOD into a custom engine of mine that I’ve been writing in C#.

So far everything has been working just fine, until I decided to try implementing custom filesystem callbacks for loading/writing using the content pipeline I’ve written.

When I try to load a file, I get the error ERR_FILE_BAD, which I would assume means that there’s an issue with the file data, and after adding breakpoints to my FS callbacks I noticed that the userread callback is never invoked, which leads me to believe that FMOD is doing some funky stuff(or maybe the C# GC, but that doesn’t make sense given the code I’ll be attaching).

Code responsible for FS callbacks(ReferenceTable is just a simple helper for storing the Streams, the IntPtr’s are just keys to a dictionary): FS functions - Pastebin.com

Setting of the filesystem is done just before StudioSystem.initialize like so:

CoreSystem.setFileSystem(FSUserOpen, FSUserClose, FSUserRead, FSUserSeek, null!, null!, -1);

EDIT: I forgot to attach the code responsible for loading the banks:

RESULT result = StudioSystem.loadBankFile(bank, LOAD_BANK_FLAGS.NORMAL, out bankH);

bankH is a Bank, and bank is a string w/ a path.

I also forgot to tell you how Content.LoadXXX works.
Load - Loads a so-called ContentLump, basically just a way to keep track of content data.
LoadStream - Makes the Lump into a stream(in this case it returns a FIleStream)

EDIT 2:

I should probably tell you what I have been able to see FMOD do:

  • Call FSUserOpen
  • Call FSUserSeek - Seeking to 0 with success
  • Call FSUserClose
  • Return ERR_FILE_BAD
    I have debug logging set up, and it does not contain any related info, nor does it log anything during bank logging.

Edit 3:
Wow, a lot of edits, huh?
I got some stuff out of FMOD regarding file loading:

I managed to solve it myself, did a minor oversight and never set the filesize ref variable in FSUserOpen.

Sometimes it’s the small things that cause the biggest issues :sweat_smile: