check if _mem is NULL

added checks for NULL Memory* parameter. GL backends crashes with NULL param.