Disable offscreen canvases in case of no WebGL support (#559)

This commit is contained in:
Christian Semmler 2025-07-08 12:43:34 -07:00 committed by GitHub
parent 2761d9985a
commit 37c6abe3b5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 46 additions and 27 deletions

View File

@ -532,6 +532,7 @@ if (ISLE_BUILD_APP)
endif() endif()
if(EMSCRIPTEN) if(EMSCRIPTEN)
target_sources(isle PRIVATE target_sources(isle PRIVATE
ISLE/emscripten/config.cpp
ISLE/emscripten/events.cpp ISLE/emscripten/events.cpp
ISLE/emscripten/filesystem.cpp ISLE/emscripten/filesystem.cpp
ISLE/emscripten/messagebox.cpp ISLE/emscripten/messagebox.cpp

View File

@ -0,0 +1,17 @@
#include "config.h"
#include "filesystem.h"
#include <SDL3/SDL_log.h>
#include <iniparser.h>
void Emscripten_SetupDefaultConfigOverrides(dictionary* p_dictionary)
{
SDL_Log("Overriding default config for Emscripten");
iniparser_set(p_dictionary, "isle:diskpath", Emscripten_bundledPath);
iniparser_set(p_dictionary, "isle:cdpath", Emscripten_streamPath);
iniparser_set(p_dictionary, "isle:savepath", Emscripten_savePath);
iniparser_set(p_dictionary, "isle:Full Screen", "false");
iniparser_set(p_dictionary, "isle:Flip Surfaces", "true");
}

8
ISLE/emscripten/config.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef EMSCRIPTEN_CONFIG_H
#define EMSCRIPTEN_CONFIG_H
#include "dictionary.h"
void Emscripten_SetupDefaultConfigOverrides(dictionary* p_dictionary);
#endif // EMSCRIPTEN_CONFIG_H

View File

@ -140,14 +140,15 @@ index e8c9f7e21..caf1971d2 100644
- -
}); });
diff --git a/src/preamble.js b/src/preamble.js diff --git a/src/preamble.js b/src/preamble.js
index 572694517..0d2f4421b 100644 index 572694517..44e65c823 100644
--- a/src/preamble.js --- a/src/preamble.js
+++ b/src/preamble.js +++ b/src/preamble.js
@@ -1062,3 +1062,13 @@ function getCompilerSetting(name) { @@ -1062,3 +1062,19 @@ function getCompilerSetting(name) {
// dynamic linker as symbols are loaded. // dynamic linker as symbols are loaded.
var asyncifyStubs = {}; var asyncifyStubs = {};
#endif #endif
+ +
+if (typeof document !== "undefined") {
+ (async () => { + (async () => {
+ try { + try {
+ await navigator.storage.getDirectory(); + await navigator.storage.getDirectory();
@ -155,5 +156,10 @@ index 572694517..0d2f4421b 100644
+ } catch (e) { + } catch (e) {
+ Module["disableOpfs"] = true; + Module["disableOpfs"] = true;
+ } + }
+ console.log("disableOpfs: " + Module["disableOpfs"]);
+ })(); + })();
+ +
+ Module["disableOffscreenCanvases"] ||= !document.createElement('canvas').getContext('webgl');
+ console.log("disableOffscreenCanvases: " + Module["disableOffscreenCanvases"]);
+}
+

View File

@ -48,6 +48,7 @@
#include <time.h> #include <time.h>
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__
#include "emscripten/config.h"
#include "emscripten/events.h" #include "emscripten/events.h"
#include "emscripten/filesystem.h" #include "emscripten/filesystem.h"
#include "emscripten/messagebox.h" #include "emscripten/messagebox.h"
@ -1003,19 +1004,15 @@ bool IsleApp::LoadConfig()
} }
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__
const char* hdPath = Emscripten_bundledPath; Emscripten_SetupDefaultConfigOverrides(dict);
#else
const char* hdPath = iniparser_getstring(dict, "isle:diskpath", SDL_GetBasePath());
#endif #endif
const char* hdPath = iniparser_getstring(dict, "isle:diskpath", SDL_GetBasePath());
m_hdPath = new char[strlen(hdPath) + 1]; m_hdPath = new char[strlen(hdPath) + 1];
strcpy(m_hdPath, hdPath); strcpy(m_hdPath, hdPath);
MxOmni::SetHD(m_hdPath); MxOmni::SetHD(m_hdPath);
#ifdef __EMSCRIPTEN__
const char* cdPath = Emscripten_streamPath;
#else
const char* cdPath = iniparser_getstring(dict, "isle:cdpath", MxOmni::GetCD()); const char* cdPath = iniparser_getstring(dict, "isle:cdpath", MxOmni::GetCD());
#endif
m_cdPath = new char[strlen(cdPath) + 1]; m_cdPath = new char[strlen(cdPath) + 1];
strcpy(m_cdPath, cdPath); strcpy(m_cdPath, cdPath);
MxOmni::SetCD(m_cdPath); MxOmni::SetCD(m_cdPath);
@ -1025,13 +1022,7 @@ bool IsleApp::LoadConfig()
strcpy(m_mediaPath, mediaPath); strcpy(m_mediaPath, mediaPath);
m_flipSurfaces = iniparser_getboolean(dict, "isle:Flip Surfaces", m_flipSurfaces); m_flipSurfaces = iniparser_getboolean(dict, "isle:Flip Surfaces", m_flipSurfaces);
#ifdef __EMSCRIPTEN__
m_fullScreen = FALSE;
#else
m_fullScreen = iniparser_getboolean(dict, "isle:Full Screen", m_fullScreen); m_fullScreen = iniparser_getboolean(dict, "isle:Full Screen", m_fullScreen);
#endif
m_wideViewAngle = iniparser_getboolean(dict, "isle:Wide View Angle", m_wideViewAngle); m_wideViewAngle = iniparser_getboolean(dict, "isle:Wide View Angle", m_wideViewAngle);
m_use3dSound = iniparser_getboolean(dict, "isle:3DSound", m_use3dSound); m_use3dSound = iniparser_getboolean(dict, "isle:3DSound", m_use3dSound);
m_useMusic = iniparser_getboolean(dict, "isle:Music", m_useMusic); m_useMusic = iniparser_getboolean(dict, "isle:Music", m_useMusic);
@ -1071,11 +1062,7 @@ bool IsleApp::LoadConfig()
// [library:config] // [library:config]
// The original game does not save any data if no savepath is given. // The original game does not save any data if no savepath is given.
// Instead, we use SDLs prefPath as a default fallback and always save data. // Instead, we use SDLs prefPath as a default fallback and always save data.
#ifdef __EMSCRIPTEN__
const char* savePath = Emscripten_savePath;
#else
const char* savePath = iniparser_getstring(dict, "isle:savepath", prefPath); const char* savePath = iniparser_getstring(dict, "isle:savepath", prefPath);
#endif
m_savePath = new char[strlen(savePath) + 1]; m_savePath = new char[strlen(savePath) + 1];
strcpy(m_savePath, savePath); strcpy(m_savePath, savePath);