# pinvokestackimbalance when calling ChannelGroup.addGroup

**URL:** <https://qa.fmod.com/t/pinvokestackimbalance-when-calling-channelgroup-addgroup/12250>\
**Category:** FMOD Studio\
**Created:** [January 18, 2016, 6:15pm UTC](https://qa.fmod.com/t/pinvokestackimbalance-when-calling-channelgroup-addgroup/12250 "2016-01-18T18:15:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![02leeken](https://avatars.discourse-cdn.com/v4/letter/0/b19c9b/32.png) [@02leeken](https://qa.fmod.com/u/02leeken)\
**Post date:** [January 18, 2016, 6:15pm UTC](https://qa.fmod.com/t/pinvokestackimbalance-when-calling-channelgroup-addgroup/12250/1 "2016-01-18T18:15:56Z")

</div>

Hi there,

I’m pretty new to FMOD, so I apologize if this is incorrect.

The VS2012 MDA is triggering a pInvokeStackImbalance whenever I call ChannelGroup.addGroup in C#. It looks like it might be a bug with the C# wrapper, with the pInvoke signature not matching the DLLs.

The MDA exception no longer triggers if I change the DLLImport to include a bool and an out ref for the dsp connection. I’m unfamiliar with audio programming, so I’m not sure what to do with the dsp reference (if anything at all). The code below works:

```
private static extern RESULT FMOD_ChannelGroup_AddGroup(IntPtr channelgroup, IntPtr group, bool propagatedspclock, out IntPtr dspConnection);
```

---

<div class="post-metadata">

**Author:** ![nick1](https://avatars.discourse-cdn.com/v4/letter/n/47e85d/32.png) [@nick1](https://qa.fmod.com/u/nick1)\
**Post date:** [January 19, 2016, 2:54am UTC](https://qa.fmod.com/t/pinvokestackimbalance-when-calling-channelgroup-addgroup/12250/2 "2016-01-19T02:54:49Z")

</div>

Thanks for the bug report. We’ll get that fixed in the next release. In addition to your changes the ChannelGroup.addGroup function should look like

```
    public RESULT addGroup (ChannelGroup group, bool propagatedspclock, out DSPConnection connection)
    {
        connection = null;

        IntPtr connectionRaw;
        RESULT result = FMOD5_ChannelGroup_AddGroup(getRaw(), group.getRaw(), propagatedspclock, out connectionRaw);
        connection = new DSPConnection(connectionRaw);

        return result;

    }
```

---

<div class="post-metadata">

**Author:** ![02leeken](https://avatars.discourse-cdn.com/v4/letter/0/b19c9b/32.png) [@02leeken](https://qa.fmod.com/u/02leeken)\
**Post date:** [January 19, 2016, 3:03am UTC](https://qa.fmod.com/t/pinvokestackimbalance-when-calling-channelgroup-addgroup/12250/3 "2016-01-19T03:03:51Z")

</div>

> [@](#):
>
> Thanks for the bug report. We’ll get that fixed in the next release. In addition to your changes the ChannelGroup.addGroup function should look like
> 
> ```
> public RESULT addGroup (ChannelGroup group, bool propagatedspclock, out DSPConnection connection)
> {
> connection = null;
> 
> IntPtr connectionRaw;
> RESULT result = FMOD5_ChannelGroup_AddGroup(getRaw(), group.getRaw(), propagatedspclock, out connectionRaw);
> connection = new DSPConnection(connectionRaw);
> 
> return result;
> 
> }
> 
> ```

Cool, thanks!
