0

I get something reason unknown error.
from System::CreateChannelGroup function in C#

private void FmodERRCheck(Fmod.RESULT result){
    if (result != RESULT.OK)
    {
        MessageBox.Show(Fmod.Error.String(result));
    }
}

private void InitFmodSystems()
{
    Fmod.Factory.System_Create(out system);
    system = new Fmod.System(IntPtr.Zero);
    system.init(3, INITFLAGS.NORMAL, IntPtr.Zero);

    channelGroup = new ChannelGroup(IntPtr.Zero);

    FmodERRCheck(system.createChannelGroup("", out channelGroup));
}

the variables declared top on class.
I was written InitFmodSystems() method to initailize fmod system.

FmodERRCheck(system.createChannelGroup("", out channelGroup));

this line return to me 'ERR_INVALID_PARAM' error.
what is wrong?

OverMe
  • 1
  • 5

2 Answers2

0

The problem is passing IntPtr.Zero to the System constructor. In FMOD, you use FMOD_System_Create to get the pointer for a System object, and with that you can pass it to the other functions, or in the C# wrapper, to the constructor.

Working code would look like this:

Fmod.Factory.System_Create(out IntPtr handle);
System system = new Fmod.System(handle); 

In the FMOD C# wrapper, you cannot pass IntPtr.Zero to any of the "core" class constructors, that is an invalid handle, it is expecting a valid handle returned by the "create" functions within the System class.

So after you properly created the System object (see above example), you would then create a ChannelGroup as such:

FmodERRCheck(system.createChannelGroup("", out IntPtr channelGroup));
ChannelGroup group = new ChannelGroup(channelGroup);
ForeverZer0
  • 2,379
  • 1
  • 24
  • 32
-1

you are initialiseing the channelGroup variable. When using an out parameter you cannot use an initialized variable.

So it must be something like this.

ChannelGroup channelgroup;
FmodERRCheck(system.createChannelGroup("", out channelGroup));

in this example the channelGroup variable stays unassigned until it goes into the function as an out parameter.

EDIT

Its possible that the empty string for the name parameter is also not allowed. but the initialized out parameter is also a problem.

Gerrie Pretorius
  • 3,381
  • 2
  • 31
  • 34
  • This answer is just wrong on multiple levels... Passing an initialized parameter to `out` is perfectly acceptable. In addition, a ChannelGroup does not have to be given a name, its an optional parameter then can even be set to `null`. – ForeverZer0 Jul 13 '18 at 12:16
  • @ForeverZer0 look at this answer: https://stackoverflow.com/questions/388464/whats-the-difference-between-the-ref-and-out-keywords – Gerrie Pretorius Jul 15 '18 at 17:32
  • @ForeverZer0 if you try to write to console the out parameter in the first line of the method, in c# method, it wont even compile. regardless if you set the value before entering calling the method that have the out parameter. try and compile this: class Program { static void Main(string[] args) { int myInt = 40; GetSOmethingFromOutParam(out myInt); } private static void GetSOmethingFromOutParam(out int myInt) { Console.WriteLine(myInt); myInt = 50; } } – Gerrie Pretorius Jul 15 '18 at 17:35
  • Yeah, because, it only should be `out myInt`, not `out int myInt` within the method call if it is already initialized. You can't add the `int` again. Trust me, it is very possible, done all the time, and confirmed by the docs. – ForeverZer0 Jul 15 '18 at 19:20