# HG changeset patch # User Matti Hamalainen # Date 1530892708 -10800 # Node ID 653ce10184e525a456f02dfc6be7e63648baeee6 # Parent 019909b7ab6ec1765368c85a029b5ec0cbec4f5d Improve error handling of local storage saving/loading. diff -r 019909b7ab6e -r 653ce10184e5 events.pde --- 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");