We have an attributed string and need to change its font:
attrStr.setFont (Range<int>(0, 3), Font (20.0f));
Unexpectedly, this line triggered the assertion in ArrayBase::checkSourceIsNotMember().
The comment on the assertion talks about passing a *copy rather than a *reference:
“When you pass a reference to an existing element into a method like add() which may need to reallocate the array to make more space, the incoming reference may be deleted indirectly during the reallocation operation! To work around this, make a local copy of the item you’re trying to add (and maybe use std::move to move it into the add() method to avoid any extra overhead.”
So, tracing the stack back to AttributedString::splitAttributeRanges (ArrayAttributedString::Attribute&, int), we noticed that a *reference is being passed rather than a *copy:
const AttributedString::Attribute& att = atts.getReference (i);
atts.insert (i + 1, att);
Simply deleting the & on that first line solves our problem.
I have tried to create a minimal example but can’t reproduce the problem. It could well be that we’ve messed something else up to cause this. But in any case the fix that we’ve made *seems to honour the comment on the assertion better than the code that was already there.
Any thoughts on this? Thanks very much.