0
0

I’ve been evaluating FMOD for use with some C# applications and I’m getting into some unstable situations which are rather concerning. I’ve been able to reduce my code to that which follows. The code as well as a binary are available at http://www.communikey.us/fmod/. I have run the binary on 3 machines (Windows XP, .NET 2.0 sp 1) and it fails every time. You will notice there are comments in the code that say things like ‘comment this and it works’, ‘uncomment this and it works’. Give it a try. Some of these are not what you would expect from a stable platform. Additionally, I have tested this on version 4.6.9 as well as 4.7.13 with the same failed results. The code at the URL provided was compiled with 4.6.9. Please let me know if I am doing something wrong, or overlooking something. I have spent quite some time with this code, changing it, comparing it to the examples, rewriting it and reducing it to what it is now so that it fails in a non-intermittent fashion.

The Error:

[code:ffu1nc3k]Attempted to read or write protected memory. This is often an indication that ot
her memory is corrupt.
at FMOD.System.FMOD_System_Update(IntPtr system)
at FMOD.System.update() in C:\rick\dev\fmod_test_csharp\ChannelCallbackFailur
e\ChannelCallbackFailure\fmod.cs:line 1622
at ChannelCallbackFailure.Player.Init() in C:\rick\dev\fmod_test_csharp\Chann
elCallbackFailure\ChannelCallbackFailure\Player.cs:line 59[/code:ffu1nc3k]

The code:

[code:ffu1nc3k]
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace ChannelCallbackFailure
{
public class Player
{
private FMOD.System system = null;
private FMOD.Sound sound = null;
private FMOD.Channel channel = null;

    public Player()
    {
    }

    public void Init()
    {
        uint version = 0;

        FMOD.RESULT result;

        result = FMOD.Factory.System_Create(ref this.system);
        ERRCHECK(result);

        result = system.getVersion(ref version);
        ERRCHECK(result);

        if (version < FMOD.VERSION.number)
        {
            throw new ApplicationException("Error!  You are using an old version of FMOD " + version.ToString("X") + ".  This program requires " + FMOD.VERSION.number.ToString("X") + ".");
        }

        result = system.init(32, FMOD.INITFLAG.NORMAL, (IntPtr)null);
        ERRCHECK(result);

        result = system.createSound("jaguar.wav", FMOD.MODE.HARDWARE, ref this.sound);
        ERRCHECK(result);

        result = sound.setMode(FMOD.MODE.LOOP_OFF);
        ERRCHECK(result);

        result = system.playSound(FMOD.CHANNELINDEX.FREE, sound, false, ref channel);
        ERRCHECK(result);
        // comment this and it works.
        result = this.channel.setCallback(FMOD.CHANNEL_CALLBACKTYPE.END, new FMOD.CHANNEL_CALLBACK(endCallback), (int)1);
        ERRCHECK(result);


        try
        {
            while (this.channel != null)
            {
                // Uncomment this and it works.
                //Thread.Sleep(10);
                // Comment this and it works.
                Console.WriteLine("Tick Thread: " + Thread.CurrentThread.ManagedThreadId);
                system.update();
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
            Console.WriteLine(ex.StackTrace);
            Console.WriteLine(ex.InnerException);
            this.channel = null;
        }

        Dispose();

        Console.WriteLine("Hit a key to continue");
        Console.ReadKey();
    }

    public void Dispose()
    {
        FMOD.RESULT result;

        if (sound != null)
        {
            result = sound.release();
            ERRCHECK(result);
        }

        if (system != null)
        {
            result = system.close();
            ERRCHECK(result);
            result = system.release();
            ERRCHECK(result);
        }
    }

    public FMOD.RESULT endCallback(IntPtr channelraw, FMOD.CHANNEL_CALLBACKTYPE type, int command, uint commanddata1, uint commanddata)
    {
        Console.WriteLine("endCallback");

        if (this.channel != null)
        {
            this.channel = null;
        }

        return FMOD.RESULT.OK;
    }

    private void ERRCHECK(FMOD.RESULT result)
    {
        if (result != FMOD.RESULT.OK)
        {
            throw new ApplicationException("Audio Player Error! " + result + " - " + FMOD.Error.String(result));
        }
    }

    public static void Main(string[] args)
    {
        Player p = new Player();
        p.Init();
    }
}

}
[/code:ffu1nc3k]

Kind Regards

-rick

  • You must to post comments
0
0

I usually get an error like this when I’m doing something multi-threaded and start crossing threads with fmod or try to use fmod in a thread I didn’t create the system object in (which has always been the UI thread, which may or may not apply).

  • You must to post comments
0
0

As you can see here, I’ve included the Main. As such, I should mention that this is the entire program right here; no UI, no timer, single threaded, no events, etc.; just a simple stripped down console program to explore this exception.

  • You must to post comments
0
0

I get the

[code:3ap2tdwe]Attempted to read or write protected memory. This is often an indication that other memory is corrupt. [/code:3ap2tdwe]

error message sometimes when I try to read tags from a file and on very rare occasions when I try to reload a MP3 file that I unloaded previously. Rebooting the computer usually stops the error from reoccurring, but it’s still slightly worrying.

  • You must to post comments
0
0

As it’s callback related and I’m not familiar with c# / classes, here just some notes:

  • The callback function must be stdcallback
  • You cannot free/release the song for which you recieved the callback.
  • You must to post comments
0
0

i suspect it could be…..

[code:pdkw0nt7]if (this.channel != null)
{
this.channel = null;
}
}
[/code:pdkw0nt7]

FMOD does it’s own internal channel memory management, so it’s not needed. Regardless, the logic you are using does not make sense. you are testing then setting the channel to null inside code belonging to the channel.

  • You must to post comments
Showing 5 results
Your Answer

Please first to submit.