fixed crashes on low memory systems, handles loss of webgl context