Cron failing on Update Membership Statuses and Send Renewal Reminders
I solved the issue with the help of xurizaemon on the Mattermost chat channel.

The script was failing because it was trying to delete a membership that looked like it was already deleted.

Hints below:


  so "call to member function delete() on null" means that CiviCRM
  expected there to be an object and called a method on it - but the
  object didn't exist
  
  i'd guess that
  here(https://github.com/civicrm/civicrm-core/blob/master/CRM/Member/BAO/Membership.php#L631)
  Civi tried to fetch a membership
  
  then
  here(https://github.com/civicrm/civicrm-core/blob/master/CRM/Member/BAO/Membership.php#L665)
  Civi tried to delete the membership
  
  but it didn't look to see if the first thing failed - and so when it
  tries to call delete on null, it falls over.
  
  IMO it makes sense to inspect the result of line 631 before it treats
  it as an object
  
  ie if ($membership = $memberships[$membershipId]) { /* do all the
  stuff with $membership */ }
  
  or (easier to read) if (!$membership = $memberships[$membershipId]) {
  /* bail out / throw exception */ }


So I downloaded a DB dump to a dev environment. Checked the error was still there.

Then ran the task from the scheduled tasks page. With a vardump in the membership.php script just after the lines noted above.

var_dump($membership);

and then

var_dump($membershipID);

The memberships in the dump were both linked to the same parent membership, so I deleted that parent membership and recreated it from scratch.

Membership scheduled task is now running as usual.

I think the db may have been corrupted a bit on a recent server move.