ScopedPointer check for nullptr


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



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.


Thanks - found the issue.