SIGSEGV with URL class

Hello JUCE Community.

While developing my plugin I encountered a really weird issue with the URL class.
I am using a HyperlinkButton, and when I use HyperlinkButton::setURL, it copies the the passed URL object to the button’s.

That’s where the problems arise.
After hours of tracking down the issue, I came across the URL::filesToUpload variable which’s copy constructor seems to trigger a SIGSEGV.
I am using GCC in Release configuration on Linux 64 bit.

Through coincidence, because I put Logger statements everywhere to track the issue down, it happened that it started to work again when I put a Logger statement between two lines,
like this:

    ReferenceCountedArray (const ReferenceCountedArray& other) noexcept
    const ScopedLockType lock (other.getLock());
    values.addArray (other.begin(), other.size());
    for (auto* o : *this)
        if (o != nullptr)

Since this totally unrelated statement made the thing work again and I am in Release mode, I figured it might be some weird GCC re-ordering issue.
Please correct me if I’m mistaken, I began developing with C++ a year ago.

How would I fix this and, out of interest, why does this happen?

Ok I put a memory barrier in between to stop the problems for now, works like a charm.

Only thing that bothers me is that it required changing JUCE code and that can’t be a permanent solution, so I am hoping still for any tips or maybe it even needs a fix, I don’t know.

Anyway, for now it works.

Just FYI, I’ve stumbled across this exact issue where the assignment operator of the ReferenceCountedArray class threw a segfault for optimized Linux builds.


asm volatile("": : : "memory")

before the for loop (the debugger hinted something about the this object being optimized away) solved the crash like @Elanda suggested. I have no idea why this happens (and why nobody else is experiencing this problem since it’s such a basic operation), but somehow this fix doesn’t feel like a proper solution…