Skip to content

Commit

Permalink
quick fix for the js exception when trying to load/save indexeddb data
Browse files Browse the repository at this point in the history
  • Loading branch information
floooh committed Dec 11, 2024
1 parent 82f7e32 commit 731e3eb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2486,11 +2486,11 @@ ui_diffview_t ui_get_diffview(void) {

static const char* ui_save_key(void) {
#if defined(CHIP_Z80)
return "z80";
return "cpu_z80";
#elif defined(CHIP_6502)
return "6502";
return "cpu_6502";
#elif defined(CHIP_2A03)
return "2A03";
return "cpu_2A03";
#else
#error "FIXME UNHANDLED CPU"
#endif
Expand Down
19 changes: 17 additions & 2 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,14 @@ EM_JS(void, emsc_js_save_async, (const char* c_key, const void* bytes, uint32_t
open_request.onsuccess = () => {
console.log('emsc_js_save_async: onsuccess');
const db = open_request.result;
const transaction = db.transaction([db_store_name], 'readwrite');
let transaction;
try {
transaction = db.transaction([db_store_name], 'readwrite');
} catch (err) {
console.warn('emsc_js_save_async: db.transaction failed with: ', err);
_util_emsc_save_callback(false, completed, userdata);
return;
}
const file = transaction.objectStore(db_store_name);
const blob = HEAPU8.subarray(bytes, bytes + num_bytes);
const put_request = file.put(blob, 'imgui.ini');
Expand Down Expand Up @@ -167,6 +174,7 @@ EM_JS(void, emsc_js_load_async, (const char* c_key, util_load_callback_t complet
_util_emsc_load_callback(false, completed, 0, 0, userdata);
return;
}
console.log('after indexedDB open');
open_request.onupgradeneeded = () => {
console.log('emsc_js_load_async: onupgradeneeded');
const db = open_request.result;
Expand All @@ -175,7 +183,14 @@ EM_JS(void, emsc_js_load_async, (const char* c_key, util_load_callback_t complet
open_request.onsuccess = () => {
console.log('emsc_js_load_async: open_request onsuccess');
let db = open_request.result;
const transaction = db.transaction([db_store_name], 'readwrite');
let transaction;
try {
transaction = db.transaction([db_store_name], 'readwrite');
} catch (err) {
console.warn('emsc_js_load_async: db.transaction failed with: ', err);
_util_emsc_load_callback(false, completed, 0, 0, userdata);
return;
}
const file = transaction.objectStore(db_store_name);
const get_request = file.get('imgui.ini');
get_request.onsuccess = () => {
Expand Down

0 comments on commit 731e3eb

Please sign in to comment.