ScopedPointer check for nullptr


#1

I have a scopedPointer which has not been assigned yet (ex. = new somehthing()) and I am checking for nullptr.  The issue is it crashes (EXC_BAD_ACCES) when I check for nullptr on the following line inside of scopedPointer:

inline operator ObjectType*() const noexcept                                    { return object; }

In my header I have:

ScopedPointer<AudioPlayer> audioPlayer;

Then later I do a (before the object is created):

if (audioPlayer !=nullptr) {​  --  this is the culprit

 


#2

No, that's definitely not the reason for your crash. If it crashes looking inside a ScopedPointer, then it's the ScopedPointer itself which must not be a valid object, not the thing that it points to.


#3

Thanks - found the issue.