Fix segfault resulting from bad ScopeDelete

Close #2781