# \[RESOLVED\] Custom file system prematurely decides on bad file

**URL:** <https://qa.fmod.com/t/resolved-custom-file-system-prematurely-decides-on-bad-file/21047>\
**Category:** FMOD Engine\
**Tags:** csharp\
**Created:** [January 2, 2024, 10:48am UTC](https://qa.fmod.com/t/resolved-custom-file-system-prematurely-decides-on-bad-file/21047 "2024-01-02T10:48:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![khhs](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/khhs/32/5892_2.png) [@khhs](https://qa.fmod.com/u/khhs)\
**Post date:** [January 2, 2024, 10:48am UTC](https://qa.fmod.com/t/resolved-custom-file-system-prematurely-decides-on-bad-file/21047/1 "2024-01-02T10:48:50Z")

</div>

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](https://pastebin.com/hV31jJYe)

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

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

```

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

```csharp
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:

> **[Log - Pastebin.com](https://pastebin.com/z89cHypx)**
>
> Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

---

<div class="post-metadata">

**Author:** ![khhs](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/khhs/32/5892_2.png) [@khhs](https://qa.fmod.com/u/khhs)\
**Post date:** [January 2, 2024, 11:06am UTC](https://qa.fmod.com/t/resolved-custom-file-system-prematurely-decides-on-bad-file/21047/2 "2024-01-02T11:06:12Z")

</div>

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 😅
