Assigning to 'std::atomic<float> *' from incompatible type 'float *'

I’m probably doing something stupid here, but I’ve come up with this error after working through reimplementing my plugin with the AudioProcessorValueTreeState. I’ve got the right bits (straight from the tutorial) as members:

std::atomic<float>* wetAmt = nullptr;
…
…
std::atomic<float>* lateAmt = nullptr;

and I’ve got the right bit of constructor:

AuralizerAudioProcessor() : parameters(*this, nullptr, Identifier("Auralizer"),
    {
     std::make_unique<AudioParameterFloat>("wetAmt", "Wet", 0.0f, 2.0f, 1.0f),
     ...
     ...
     std::make_unique<AudioParameterFloat>("lateAmt", "Late Level", 0.0f, 2.0f, 1.0f)
    })
{
    wetAmt      =   parameters.getRawParameterValue("wetAmt"); // [1]
    ...
    ...
    lateAmt     =   parameters.getRawParameterValue("lateAmt"); // [2]

But in [1] and [2], the error Assigning to 'std::atomic<float> *' from incompatible type 'float *' persists. It seems to be exactly the same operation that the tutorial is doing.

Anyone have any insight into why?

Replace std::atomic<float>* by float* and you should be fine.
You can’t assign a float-pointer to an atomic<float>-pointer. However, you can assign a float to an atomic<float> but that’s not what you want to do here.

It should also work with replacing std::atomic<float>* by std::atomic<float*>. (@McMartin was faster than my edit :wink: )

I think std::atomic<float>* should be replaced by std::atomic<float*>.

1 Like

Is your version of juce definitely completely up-to-date?
This was changed recently, and the atomic<float>* version is the latest.

Oh I see, it was changed in:

But that’s only on the develop branch…

I would assume people who are doing the tutorials are downloading JUCE from https://shop.juce.com/get-juce, or are using the master branch, but not the develop one.

I guess tutorials should be versioned, or live inside the JUCE repository.

3 Likes

https://docs.juce.com/master/tutorial_audio_processor_value_tree_state.html <- I assume the tutorial already uses the develop branch

Thanks all, I’ll make sure I’m updated. Would be nice for this to at least be mentioned in the tutorials though. I understand how quickly everything can move though.

Hi all, same problem here. I am using the last version of juce 5.4.5, and following this thread I changed std::atomic<float>* into std::atomic<float*>. However I get the error “Copying member subobject of type std::atomic<float *> invokes deleted constructor”. The only way to make it work is to use float*…I would like to use atomic to ensure threads safe operations with the editor. So, what should I do?

The correct type should be std::atomic<float>* (i.e. non-atomic pointer to atomic float). It’s weird that it works with float*; that suggests you’re not using the very latest juce from the develop branch.

1 Like

I got Juce from https://shop.juce.com/get-juce just last month.
There is no indication anywhere in the documentation/tutorials about why I should use the develop branch.
Not clear why the tutorial example works then. Any idea? There it is used std::atomic<float>*. So, I wonder what should I do now and in the future. Should I always use always the develop branch at https://github.com/WeAreROLI/JUCE/tree/develop and pull down every few days to have the repo in synch? Is this the recommended practice?

Let me clarify what’s happening…
Can I consider things that discussed in this post have been implemented officially?
https://forum.juce.com/t/audioparameter-thread-safety
I haven’t understood what “AudioParameter thread safety” post discussed about completely, so it’s just my guessing. Sorry if I had post completely wrong thing!