Cannot delete ListBox item when I change the orientation from vertical to horizontal

I made a custom horizontal ListBox and I want to remove an item when a button is clicked.
I’ve just changed Juce’s ListBox to make it horizontal.

Here’s what I’ve done so far:

In juce_ListBox.cpp I changed line 390 to (I’ll create a separate component later but for now I’m just trying and learning Juce GUI stuff)
rowComp->setBounds (0, row * rowH, w, rowH);
rowComp->setBounds (rowW * row, 0, rowW, rowH);

It’s just a one-line change and it’s all working (scroll bars, scroll, adding items etc).

When I want to remove an item I’m getting the below error at juce_ReferenceCountedObject.h file:

I’ve been debugging for hours but I couldn’t find a solution yet.
Does anyone know what’s the problem here?