# adding DSP Plugin causes crash

**URL:** <https://qa.fmod.com/t/adding-dsp-plugin-causes-crash/14147>\
**Category:** FMOD Studio\
**Created:** [October 16, 2018, 7:47pm UTC](https://qa.fmod.com/t/adding-dsp-plugin-causes-crash/14147 "2018-10-16T19:47:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![atillacsa](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@atillacsa](https://qa.fmod.com/u/atillacsa)\
**Post date:** [October 16, 2018, 7:47pm UTC](https://qa.fmod.com/t/adding-dsp-plugin-causes-crash/14147/1 "2018-10-16T19:47:04Z")

</div>

I wrote a simple DSP bitcrush effect, it loads in FMOD Studio, I can see it in the effects. The problem is, if I don’t comment out a piece from my code, it crashes instantly when trying to add the effect:

```auto
FMOD_RESULT F_CALLBACK FMOD_BitCrusher_dspcreate(FMOD_DSP_STATE* dsp_state)
{
	// THIS IS THE SECTION THAT IS GIVING ME TROUBLES:
	BitCrusher* state = (BitCrusher*)FMOD_DSP_ALLOC(
		dsp_state,
		sizeof(BitCrusher));
	state->Init(dsp_state);
	dsp_state->plugindata = state;
	// END OF SECTION //////////////////////////////////////////

	if (!state)
	{
		return FMOD_ERR_MEMORY;
	}
	return FMOD_OK;
}

```

That is how it is in the fmod\_distance\_filter.cpp example in the api, if I do this, it works:  
(this is in the fmod\_gain.cpp example)

```auto
FMOD_RESULT F_CALLBACK FMOD_BitCrusher_dspcreate(FMOD_DSP_STATE *dsp_state)
{
    dsp_state->plugindata = (BitCrusher*)FMOD_DSP_ALLOC(dsp_state, sizeof(BitCrusher));
    if (!dsp_state->plugindata)
    {
        return FMOD_ERR_MEMORY;
    }
    return FMOD_OK;
}

```

However, I still can’t call FMOD\_DSP\_GETSAMPLERATE(dsp\_state, &sampleRate); anywhere in my code, except in the dspprocess/dspread methods… Which is my goal, to be able to fetch the current sample rate once when it’s created, and not at every buffer segment…

---

<div class="post-metadata">

**Author:** ![atillacsa](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@atillacsa](https://qa.fmod.com/u/atillacsa)\
**Post date:** [October 17, 2018, 8:10am UTC](https://qa.fmod.com/t/adding-dsp-plugin-causes-crash/14147/2 "2018-10-17T08:10:49Z")

</div>

Okay… so… this is a bit embarrassing… It works…

This was the problem, it was caused by me not paying attention, and commenting out code, to debug:

```auto
FMOD_RESULT F_CALLBACK FMOD_BitCrusher_dspgetparamint(
	FMOD_DSP_STATE *dsp_state, int index, int* value, char* valuestr)
{
	BitCrusher *state = (BitCrusher*)dsp_state->plugindata;

	[...commented out code...]

	//This should not been there:
	return FMOD_ERR_INVALID_PARAM;
}

```

This was the case on the dspsetparamint method too…  
It was always giving FMOD\_ERR\_INVALID\_PARAM as the return value…
