Mercurial > hg > forks > multipaint-js
changeset 115:653ce10184e5
Improve error handling of local storage saving/loading.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 06 Jul 2018 18:58:28 +0300 |
parents | 019909b7ab6e |
children | 1180249d713d |
files | events.pde |
diffstat | 1 files changed, 10 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/events.pde Fri Jul 06 18:44:19 2018 +0300 +++ b/events.pde Fri Jul 06 18:58:28 2018 +0300 @@ -904,15 +904,17 @@ if (mpHaveLocalStorage()) { - var fdata = mpGetNativeImage(); - if (fdata != null) + try { + var fdata = mpGetNativeImage(); var fstr = JSON.stringify(fdata); localStorage.setItem("MPIMAGE_DATA"+ str(machine), fstr); message("Saved to lstorage"); } - else + catch (err) + { message("ERROR"); + } } else message("Lstorage is not available"); @@ -923,9 +925,9 @@ g_data[int('L')] = 0; if (mpHaveLocalStorage()) { - var fstr = localStorage.getItem("MPIMAGE_DATA"+ str(machine)); - if (fstr != null && typeof(fstr) == "string") + try { + var fstr = localStorage.getItem("MPIMAGE_DATA"+ str(machine)); var fdata = JSON.parse(fstr); if (typeof(fdata) == "object" && Array.isArray(fdata)) @@ -939,8 +941,10 @@ else message("Invalid data in lstorage"); } - else + catch (err) + { message("No data in lstorage"); + } } else message("Lstorage is not available");