Instead of this check
return context && !context->IsPendingKill();
You might need to do something like:
return context->IsValidLowLevel() && !context->IsPendingKill();
I seem to remember that just a nullptr check is not always 100% as opposed to IsValidLowLevel