# Always getting a nullptr from Bus::getChannelGroup long after everything's loaded

**URL:** <https://qa.fmod.com/t/always-getting-a-nullptr-from-bus-getchannelgroup-long-after-everythings-loaded/20081>\
**Category:** FMOD Studio\
**Tags:** cpp\
**Created:** [April 7, 2023, 3:14pm UTC](https://qa.fmod.com/t/always-getting-a-nullptr-from-bus-getchannelgroup-long-after-everythings-loaded/20081 "2023-04-07T15:14:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![benjitrosch](https://avatars.discourse-cdn.com/v4/letter/b/dfb087/32.png) [@benjitrosch](https://qa.fmod.com/u/benjitrosch)\
**Post date:** [April 7, 2023, 3:14pm UTC](https://qa.fmod.com/t/always-getting-a-nullptr-from-bus-getchannelgroup-long-after-everythings-loaded/20081/1 "2023-04-07T15:14:41Z")

</div>

I’m using the C++ API to attach a custom DSP to the Master Bus’s Channel Group (eventually in an attempt to record the output).

Everything seems to work up until using `Bus::getChannelGroup` because, despite receiving an `FMOD_RESULT` of `FMOD_OK` from the function, it’s clearly a nullptr when logged and using any function on it results in `FMOD_ERR_INVALID_HANDLE`.

I’ve tried several things to make sure the Banks and Master Bus have loaded before trying to get the Channel Group, even calling the logic after 100 updates have passed, but no luck.

* * *

My code to initialize FMOD Studio and load my banks is very basic:

```cpp
FMOD::Studio::System* studio;
FMOD_CALL(FMOD::Studio::System::create(&studio));
FMOD_CALL(studio->initialize(32, FMOD_STUDIO_INIT_NORMAL, FMOD_INIT_NORMAL, nullptr));

FMOD::Studio::Bank* bank = nullptr;
FMOD_CALL(studio->loadBankFile((content_dir + "sounds/Desktop/Master.bank").c_str(), FMOD_STUDIO_LOAD_BANK_NORMAL, &bank));
FMOD_CALL(studio->loadBankFile((content_dir + "sounds/Desktop/Master.strings.bank").c_str(), FMOD_STUDIO_LOAD_BANK_NORMAL, &bank));

```

After that is when I’ve experimented with calling `studio->update()` with no luck.

Next I create the DSP, which I’ll abbreviate, and the get the master bus. Both are definitely working as far as I can tell and are not null:

```cpp
FMOD_DSP_DESCRIPTION dsp_description = {};
// ... creating DSP settings here
FMOD::DSP* dsp = nullptr;
FMOD::System* core_system = nullptr;
FMOD_CALL(studio->getCoreSystem(&core_system));
FMOD_CALL(core_system->createDSP(&dsp_description, &dsp));

FMOD::Studio::Bus* master_bus = nullptr;
FMOD_RESULT result = FMOD_ERR_INVALID_HANDLE;

while (result == FMOD_ERR_INVALID_HANDLE)
{
    result = FMOD_CALL(studio->getBus("bus:/", &master_bus));
    std::this_thread::sleep_for(std::chrono::milliseconds(10));
}

```

Finally, the ChannelGroup, which usually fails just ONCE with `FMOD_ERR_STUDIO_NOT_LOADED` before finally getting `FMOD_OK`:

```cpp
FMOD::ChannelGroup* channel_group = nullptr;
result = FMOD_ERR_INVALID_HANDLE;

while (result == FMOD_ERR_INVALID_HANDLE)
{
    result = FMOD_CALL(master_bus->getChannelGroup(&channel_group));
    std::this_thread::sleep_for(std::chrono::milliseconds(10));
}

```

It then fails here due to being null:

```cpp
FMOD_CALL(master_bus->lockChannelGroup());
FMOD_CALL(channel_group->addDSP(FMOD_CHANNELCONTROL_DSP_HEAD, dsp));
FMOD_CALL(master_bus->unlockChannelGroup());

```

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [April 11, 2023, 4:53am UTC](https://qa.fmod.com/t/always-getting-a-nullptr-from-bus-getchannelgroup-long-after-everythings-loaded/20081/2 "2023-04-11T04:53:53Z")

</div>

Hi,

I would recommend adding `flushCommands()` and `flushSampleData()` after `lockChannelGroup()` which will make sure the channel is loaded in memory before we try and access it to add the DSP.

```auto
FMOD_CALL(master_bus->lockChannelGroup());
FMOD_CALL(studio->flushCommands());
FMOD_CALL(studio->flushSampleData());
FMOD_CALL(channel_group->addDSP(FMOD_CHANNELCONTROL_DSP_HEAD, dsp));
FMOD_CALL(master_bus->unlockChannelGroup());

```

You can read more about these functions under [FMOD API | Studio API Reference - Studio::System](https://fmod.com/docs/2.02/api/studio-api-system.html#studio_system_flushcommands).

Hope this helps!

---

<div class="post-metadata">

**Author:** ![benjitrosch](https://avatars.discourse-cdn.com/v4/letter/b/dfb087/32.png) [@benjitrosch](https://qa.fmod.com/u/benjitrosch)\
**Post date:** [April 15, 2023, 2:04am UTC](https://qa.fmod.com/t/always-getting-a-nullptr-from-bus-getchannelgroup-long-after-everythings-loaded/20081/3 "2023-04-15T02:04:14Z")

</div>

Hi Connor, I’m not seeing any function named `flushSampleData` in the docs you linked, and I don’t see it as a method on FMOD::Studio::System either.

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [April 16, 2023, 10:31pm UTC](https://qa.fmod.com/t/always-getting-a-nullptr-from-bus-getchannelgroup-long-after-everythings-loaded/20081/4 "2023-04-16T22:31:58Z")

</div>

Hi,

Apologies, it was meant to be `FMOD_CALL(studio->flushSampleLoading());`. Which can be found here [FMOD API | Studio API Reference - Studio::System](https://fmod.com/docs/2.02/api/studio-api-system.html#studio_system_flushsampleloading).
