OwnedArray problem size = 1


#1

When the cardinality of OwnedArray Object is equal to 1, oa.remove(0) will crash. :?:

Could you help me?

thanx


#2

…by cardinality, you mean the size of the array?

It’ll only crash if there’s a problem deleting that object - most likely you’ve already deleted it by some other means and you’ve got a dangling pointer.


#3

Yes Jules, the size.

Exactly, the remove() crashes in the last line

... irList.insert(0,&dlgResult); removeFilesWithoutTheseProperties(getFilter()->getNumOutputChannels(),getFilter()->getSampleRate()); ...

In removeFilesWithoutTheseProperties I do

irList.remove(i);

It is the same I do when irList has more than one objects.
It crashes only if irList.size() = 1.


#4

Looks like a basic c++ blooper to me. You’re adding a reference to something, then deleting the object, which is maybe on the stack?


#5

When irList has more objects I use findChildFiles to fill it.

In this case I have only one result in dglResult, it is a member of the Editor class.

So you think it is better,in this case, set the 0 element to NULL instead of removing it?


#6

Instead of
irList.insert(0,&dlgResult);

I do
irList.add (new File (dlgResult));

It seems to work fine now.


#7

yep. Deleting objects on the stack is never a good move.


#8