Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6529481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:38:27+00:00 2026-05-25T09:38:27+00:00

Been messing around with FMOD for C# game development and I’ve hit a snag

  • 0

Been messing around with FMOD for C# game development and I’ve hit a snag early on that I can’t seem to get around. I want to do some branching audio stuff and sync some gameplay action to beats and such, so I’ve tried adding syncpoints to my music tracks. Here’s code:

public class Music
{
    private Sound music;
    private Channel channel;
    private IntPtr syncPtr;

    public string File { get; private set; }  

    public Music(string file)
    {
        File = file;
    }

    public void Load()
    {
        music = new Sound();
        Audio.System.createSound(File, MODE.HARDWARE, ref music);
    }

    public void Unload()
    {
        music.release();
    }

    public virtual void Play()
    {
        Audio.System.playSound(channel == null ? CHANNELINDEX.FREE : CHANNELINDEX.REUSE, music, false, ref channel);
        music.addSyncPoint(500, TIMEUNIT.MS, "wooo", ref syncPtr);
        channel.setCallback(channelCallback);
    }

    private RESULT channelCallback(IntPtr channelraw, CHANNEL_CALLBACKTYPE type, IntPtr commanddata1, IntPtr commanddata2)
    {
        if (type == CHANNEL_CALLBACKTYPE.SYNCPOINT)
            Console.WriteLine("sync!");

        return RESULT.OK;
    }
}

And then…

m = new Music(MUS_TUTORIAL);  //m is static
m.Load();
m.Play();

The song loads and plays fine… until it hits that 500ms syncpoint I added. At this point, VC# spits out the following error from within FMOD.EventSystem.update():

A callback was made on a garbage collected delegate of type
‘Game!FMOD.CHANNEL_CALLBACK::Invoke’. This may cause application crashes, corruption and
data loss. When passing delegates to unmanaged code, they must be kept alive by the
managed application until it is guaranteed that they will never be called.

So somehow FMOD is losing track of the delegate I passed it. The Music instance that holds the delegate has not been garbage collected – I’m storing it in a static variable for now – but I’ve tried with a static method too to no avail. If I disable the CallbackOnCollectedDelegate MDA the error becomes a null reference exception, so the MDA isn’t mistaken. I assume I must just not fully understand what FMOD is doing here.

Are any C# + FMOD gurus able to see my mistake?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T09:38:28+00:00Added an answer on May 25, 2026 at 9:38 am
        channel.setCallback(channelCallback);
    

    That’s the problem statement. FMod is unmanaged code. You are creating a delegate object here and passing it to the unmanaged code. Problem is, the garbage collector cannot track references held by native code. The next garbage collection will find no references to the object and collect it. Kaboom when the native code makes the callback.

    You need to keep a reference yourself so this won’t happen:

    public class Music
    {
        private SomeDelegateType callback
        //...
        public Music(string file)
        {
            File = file;
            callback = new SomeDelegateType(channelCallback);
        }
    
        public virtual void Play()
        {
            Audio.System.playSound(channel == null ? CHANNELINDEX.FREE : CHANNELINDEX.REUSE, music, false, ref channel);
            music.addSyncPoint(500, TIMEUNIT.MS, "wooo", ref syncPtr);
            channel.setCallback(callback);
        }
    

    You need to find the actual delegate type from the FMod wrapper code, I merely guessed at “SomeDelegateType”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been messing around with this for a while now, but I can't seem
I've been messing around with this for a while now but I can't seem
I've been messing around with Android development. I made a simple form that has
I've just been messing around with threads in Java to get my head around
I have been messing around with recursion today. Often a programming technique that is
I've been messing around with a radiobox. I'm encountering an issue that varies depending
I have been messing around with GWT uploads lately. I want to have the
I've been messing around with different forms and tables, now I need something that
There's a .net program for students that I've been messing around with in Reflector
I have been messing around with recursion a few hours and just cant get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.