adding DSP Plugin causes crash

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:

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)

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…

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:

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…

1 Like