From 9560744930c1cfae645a138b3c8fbef9b751087e Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Wed, 20 Jul 2022 23:17:51 +0200 Subject: [PATCH] config: Catch exceptions from localStorage usage localStorage may not be available e.g. in incognito sessions. --- src/config.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/config.c b/src/config.c index e630ebc..09b3d39 100644 --- a/src/config.c +++ b/src/config.c @@ -54,7 +54,11 @@ SYMBOL_EXPORT void SetConfigOption(struct Game* game, char* section, char* name, #ifdef __EMSCRIPTEN__ EM_ASM({ var key = '[' + UTF8ToString($0) + '] ' + UTF8ToString($1); - window.localStorage.setItem(key, UTF8ToString($2)); + try { + window.localStorage.setItem(key, UTF8ToString($2)); + } catch (e) { + console.error(e); + } }, section, name, value); #endif @@ -65,7 +69,12 @@ SYMBOL_EXPORT const char* GetConfigOption(struct Game* game, char* section, char #ifdef __EMSCRIPTEN__ char* buf = (char*)EM_ASM_INT({ var key = '[' + UTF8ToString($0) + '] ' + UTF8ToString($1); - var value = window.localStorage.getItem(key); + var value; + try { + value = window.localStorage.getItem(key); + } catch (e) { + console.error(e); + } if (value) { var buf = _malloc(255); stringToUTF8(value, buf, 255); @@ -92,7 +101,11 @@ SYMBOL_EXPORT void DeleteConfigOption(struct Game* game, char* section, char* na #ifdef __EMSCRIPTEN__ EM_ASM({ var key = '[' + UTF8ToString($0) + '] ' + UTF8ToString($1); - window.localStorage.removeItem(key); + try { + window.localStorage.removeItem(key); + } catch (e) { + console.error(e); + } }, section, name); #endif