Access violation, scalar deleting destructor for no apparent reason

I’ll cut to the chase so I can get a bit of help on such a basic issue which is blocking my entire project.

Seems socket cannot be accessed for some reason, and it’s not nullptr.

Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x00000028
UE4Editor_MyGame_4209!AMyGameMode::`scalar deleting destructor’()


class UTCPSocket : public FRunnable

… and overrides the necessary.



class AMyGameMode : public AGameModeBase
{
    public:
        virtual void BeginPlay() override;
        ~AMyGameMode();

    private:
        UTCPSocket* socket;
}




void AMyGameMode::BeginPlay()
{
    socket = new UTCPSocket();
    socket->Run(); // works fine
}

AMyGameMode::~AMyGameMode()
{
    // socket is NOT nullptr at this point
    socket->literally anything here; // this crashes the engine
}


Don’t use the destructor with UObject types.

You should override BeginDestroy() if you want to perform some kind of cleanup. For Actors, it’s best to use either EndPlay() or Destroyed()