Unexplainable behaviour (to me) in process(), MIDI noteOn event output

Dear VST Developer Community and Steinberg

I’m observing unexplainable behaviour (likely due to limited knowledge on my part) in the process() function of a plain Instrument plugin created with the official Project Generator (using VST 3 SDK 3.7.11).

Here’s the most reduced code example I could create:

  • I can successfully periodically output (e.g. every 22050 samples) a noteOn event with the following simple example. (I don’t think understanding the output logic is that relevant to my question below. samplesToNextBeat is initialized as 0. I’m aware that I’m not outputting corresponding noteOff events in this simple example.)

  • :thinking: However, as soon as I comment out the unused (!) local variable FOOBAR_1, i.e. as soon as I write // double FOOBAR_1 = -1;, the event output stops working…

:question: Why would this happen?

Thank you for any insights you may be able to share to put me on the right path to solve this. I’m completely at a loss why an unused local variable would change the behaviour of the code.

Thanks again and all the best!

(I’m building the plugin with Xcode on an M1 Mac, if that is of any relevance, and I’m testing and seeing this behaviour in Cubase)

tresult PLUGIN_API TestProcessor::process (Vst::ProcessData& data)

    int bufferSize = data.numSamples;

    // (!) Why does commenting this unused local variable cause event output to stop working?
    double FOOBAR_1 = -1;
    // Event input. Does nothing in this example
    Vst::IEventList* eventListInput = data.inputEvents;
    if (eventListInput) {
        int32 numEvent = eventListInput->getEventCount ();
        for (int32 i = 0; i < numEvent; i++) {
            Vst::Event event;
            if (eventListInput->getEvent (i, event) == kResultOk) {

    // Event output. Periodically outputs a noteOn event
	if (bufferSize > 0) {

        if (samplesToNextBeat < bufferSize) {

            Vst::IEventList* eventListOutput = data.outputEvents;

            if (eventListOutput) {

                Vst::Event event;
                event.type = Vst::Event::kNoteOnEvent;
                event.noteOn.channel = 1;
                event.noteOn.pitch = 60;
                event.noteOn.tuning = 0.f;
                event.noteOn.velocity = 0.75f;
                event.noteOn.noteId = 1;
                event.sampleOffset = samplesToNextBeat;
            samplesToNextBeat += 22050;
        samplesToNextBeat -= bufferSize;

    // Unchanged project generator example code to output silence on the audio out
    // ...