HostPluginDemo audio errors

Hello! I am making a plugin host based on the HostPluginDemo, which comes without audio implemented by default.

My host will only use stereo input and stereo output.
Audio input is currently not working and producing noise.
Some plugins output only in the Right channel and the Left is muted.
Plugins that have more than 2 in/outs crash the application, hiting this jassert:

    Type* getWritePointer (int channelNumber) noexcept
    {
        jassert (isPositiveAndBelow (channelNumber, numChannels));
        isClear = false;
        return channels[channelNumber];
    }

The code for audio is as follows:

void processBlock (AudioBuffer<float>& buffer, MidiBuffer& midimessages) override
    {

     if (inner)
     {
         inner->processBlock(newbuffer, midimessages);

         for (size_t c = 0; c < 2; c++)
         {
             auto destchannelindex = getChannelIndexInProcessBlockBuffer(false, 0, c);
             auto* readpointer = newbuffer.getReadPointer(c);
             

             buffer.copyFrom(destchannelindex, 0, readpointer, buffer.getNumSamples());
             buffer.applyGain(gain);
         }
     }
     else {
         buffer.clear();
         midimessages.clear();
     }

    }
  void setNewPlugin (const PluginDescription& pd, EditorStyle where, const MemoryBlock& mb = {})
    {
        const ScopedLock sl (innerMutex);

        const auto callback = [this, where, mb] (std::unique_ptr<AudioPluginInstance> instance, const String& error)
        {            if (inner != nullptr)
        {
            inner->setRateAndBufferSizeDetails(getSampleRate(), getBlockSize());
            inner->prepareToPlay(getSampleRate(), getBlockSize());
        }
            if (error.isNotEmpty())
            {
                NativeMessageBox::showMessageBoxAsync (MessageBoxIconType::WarningIcon,
                                                       "Plugin Load Failed",
                                                       error,
                                                       nullptr,
                                                       nullptr);
                return;
            }

            inner = std::move (instance);

            editorStyle = where;

            if (inner != nullptr && ! mb.isEmpty())
                inner->setStateInformation (mb.getData(), (int) mb.getSize());

            auto busesLayout = getBusesLayout();
            if (inner->checkBusesLayoutSupported(busesLayout))
                inner->setBusesLayout(busesLayout);

            else
            {
                // fallback
                busesLayout.inputBuses.clear();
                busesLayout.outputBuses.clear();
                if (inner->checkBusesLayoutSupported(busesLayout))
                    inner->setBusesLayout(busesLayout);
            }
            if (inner != nullptr)
            {
                inner->setRateAndBufferSizeDetails(getSampleRate(), getBlockSize());
                inner->prepareToPlay(getSampleRate(), getBlockSize());
            }

            NullCheckedInvocation::invoke (pluginChanged);
        };

        pluginFormatManager.createPluginInstanceAsync (pd, getSampleRate(), getBlockSize(), callback);
    }

    void prepareToPlay (double sr, int bs) override
    {
        const ScopedLock sl (innerMutex);
        newbuffer.setSize(2, bs, false, true);
        active = true;

        if (inner != nullptr)
        {
            inner->setRateAndBufferSizeDetails (sr, bs);
            inner->prepareToPlay (sr, bs);
        }
    }

Some errors I face hosting some plugins:

B3LV2: LV message buffer is only 0 bytes. Expect problems.
B3LV2: if your LV2 host allows one to configure a buffersize use at least 4kBytes.
Segmentation fault
/**
   Run `instance` for `sample_count` frames.

   If the hint lv2:hardRTCapable is set for this plugin, this function is
   guaranteed not to block.
*/
static inline void
lilv_instance_run(LilvInstance* instance, uint32_t sample_count)
{
  instance->lv2_descriptor->run(instance->lv2_handle, sample_count);
}

The following code:

auto busesLayout = getBusesLayout();
if (inner->checkBusesLayoutSupported(busesLayout))
    inner->setBusesLayout(busesLayout);

means that the plugins will only work if they accept the bus layout of the host.

inner->processBlock(newbuffer, midimessages);

should have buffer instead of newbuffer in the argument.

PS. Did you write this code or was it ChatGPT?