arreglat el cuelgue de la precàrrega en wasm i afegit nom del recurs en curs

- CMakeLists.txt (Emscripten): afegit -fexceptions (compile + link) perquè
  fkyaml i altres throws ara es capturen pels try/catch enlloc de cridar
  abort(). També -sASSERTIONS=1 per veure missatges clars d'error en el
  runtime de Emscripten.
- resource_cache: abans de carregar cada recurs, desa el seu nom en
  current_loading_name_ i (en wasm/debug) el repinta immediatament sobre la
  barra de progrés. Ara, si la càrrega es penja en un fitxer concret, el
  nom queda visible en pantalla i ajuda a diagnosticar el problema.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-13 09:52:28 +02:00
parent 70cfe5245d
commit 023bbb224b
3 changed files with 35 additions and 0 deletions

View File

@@ -266,13 +266,17 @@ elseif(APPLE)
endif() endif()
elseif(EMSCRIPTEN) elseif(EMSCRIPTEN)
target_compile_definitions(${PROJECT_NAME} PRIVATE EMSCRIPTEN_BUILD) target_compile_definitions(${PROJECT_NAME} PRIVATE EMSCRIPTEN_BUILD)
# -fexceptions: habilita excepcions C++ (fkyaml, std::runtime_error...) — sense això qualsevol throw crida abort()
target_compile_options(${PROJECT_NAME} PRIVATE -fexceptions)
target_link_options(${PROJECT_NAME} PRIVATE target_link_options(${PROJECT_NAME} PRIVATE
"SHELL:--preload-file ${CMAKE_SOURCE_DIR}/data@/data" "SHELL:--preload-file ${CMAKE_SOURCE_DIR}/data@/data"
"SHELL:--preload-file ${CMAKE_SOURCE_DIR}/config@/config" "SHELL:--preload-file ${CMAKE_SOURCE_DIR}/config@/config"
"SHELL:--preload-file ${CMAKE_SOURCE_DIR}/gamecontrollerdb.txt@/gamecontrollerdb.txt" "SHELL:--preload-file ${CMAKE_SOURCE_DIR}/gamecontrollerdb.txt@/gamecontrollerdb.txt"
-fexceptions
-sALLOW_MEMORY_GROWTH=1 -sALLOW_MEMORY_GROWTH=1
-sMAX_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2
-sINITIAL_MEMORY=67108864 -sINITIAL_MEMORY=67108864
-sASSERTIONS=1
) )
set_target_properties(${PROJECT_NAME} PROPERTIES SUFFIX ".html") set_target_properties(${PROJECT_NAME} PROPERTIES SUFFIX ".html")
elseif(UNIX AND NOT APPLE) elseif(UNIX AND NOT APPLE)

View File

@@ -226,6 +226,7 @@ namespace Resource {
for (const auto& l : list) { for (const auto& l : list) {
try { try {
auto name = getFileName(l); auto name = getFileName(l);
setCurrentLoading(name);
JA_Sound_t* sound = nullptr; JA_Sound_t* sound = nullptr;
// Try loading from resource pack first // Try loading from resource pack first
@@ -261,6 +262,7 @@ namespace Resource {
for (const auto& l : list) { for (const auto& l : list) {
try { try {
auto name = getFileName(l); auto name = getFileName(l);
setCurrentLoading(name);
JA_Music_t* music = nullptr; JA_Music_t* music = nullptr;
// Try loading from resource pack first // Try loading from resource pack first
@@ -296,6 +298,7 @@ namespace Resource {
for (const auto& l : list) { for (const auto& l : list) {
try { try {
auto name = getFileName(l); auto name = getFileName(l);
setCurrentLoading(name);
surfaces_.emplace_back(SurfaceResource{.name = name, .surface = std::make_shared<Surface>(l)}); surfaces_.emplace_back(SurfaceResource{.name = name, .surface = std::make_shared<Surface>(l)});
surfaces_.back().surface->setTransparentColor(0); surfaces_.back().surface->setTransparentColor(0);
updateLoadingProgress(); updateLoadingProgress();
@@ -323,6 +326,7 @@ namespace Resource {
for (const auto& l : list) { for (const auto& l : list) {
try { try {
auto name = getFileName(l); auto name = getFileName(l);
setCurrentLoading(name);
palettes_.emplace_back(ResourcePalette{.name = name, .palette = readPalFile(l)}); palettes_.emplace_back(ResourcePalette{.name = name, .palette = readPalFile(l)});
updateLoadingProgress(); updateLoadingProgress();
} catch (const std::exception& e) { } catch (const std::exception& e) {
@@ -340,6 +344,7 @@ namespace Resource {
for (const auto& l : list) { for (const auto& l : list) {
try { try {
auto name = getFileName(l); auto name = getFileName(l);
setCurrentLoading(name);
text_files_.emplace_back(TextFileResource{.name = name, .text_file = Text::loadTextFile(l)}); text_files_.emplace_back(TextFileResource{.name = name, .text_file = Text::loadTextFile(l)});
updateLoadingProgress(); updateLoadingProgress();
} catch (const std::exception& e) { } catch (const std::exception& e) {
@@ -357,6 +362,7 @@ namespace Resource {
for (const auto& l : list) { for (const auto& l : list) {
try { try {
auto name = getFileName(l); auto name = getFileName(l);
setCurrentLoading(name);
// Cargar bytes del archivo YAML sin parsear (carga lazy) // Cargar bytes del archivo YAML sin parsear (carga lazy)
auto yaml_bytes = Helper::loadFile(l); auto yaml_bytes = Helper::loadFile(l);
@@ -383,6 +389,7 @@ namespace Resource {
for (const auto& l : list) { for (const auto& l : list) {
try { try {
auto name = getFileName(l); auto name = getFileName(l);
setCurrentLoading(name);
rooms_.emplace_back(RoomResource{.name = name, .room = std::make_shared<Room::Data>(Room::loadYAML(l))}); rooms_.emplace_back(RoomResource{.name = name, .room = std::make_shared<Room::Data>(Room::loadYAML(l))});
printWithDots("Room : ", name, "[ LOADED ]"); printWithDots("Room : ", name, "[ LOADED ]");
updateLoadingProgress(); updateLoadingProgress();
@@ -501,9 +508,31 @@ namespace Resource {
SDL_FRect rect_full = {.x = X_PADDING, .y = BAR_POSITION, .w = FULL_BAR_WIDTH, .h = BAR_HEIGHT}; SDL_FRect rect_full = {.x = X_PADDING, .y = BAR_POSITION, .w = FULL_BAR_WIDTH, .h = BAR_HEIGHT};
surface->fillRect(&rect_full, BAR_COLOR); surface->fillRect(&rect_full, BAR_COLOR);
#if defined(__EMSCRIPTEN__) || defined(_DEBUG)
// Mostra el nom del recurs que està a punt de carregar-se, centrat sobre la barra
if (!current_loading_name_.empty()) {
const float TEXT_Y = BAR_POSITION - static_cast<float>(TEXT_HEIGHT) - 2.0F;
loading_text_->writeColored(
CENTER_X - (loading_text_->length(current_loading_name_) / 2),
static_cast<int>(TEXT_Y),
current_loading_name_,
LOADING_TEXT_COLOR);
}
#endif
Screen::get()->render(); Screen::get()->render();
} }
// Desa el nom del recurs que s'està a punt de carregar i repinta immediatament.
// A wasm/debug serveix per veure exactament en quin fitxer es penja la càrrega.
void Cache::setCurrentLoading(const std::string& name) {
current_loading_name_ = name;
#if defined(__EMSCRIPTEN__) || defined(_DEBUG)
renderProgress();
checkEvents();
#endif
}
// Comprueba los eventos de la pantalla de carga // Comprueba los eventos de la pantalla de carga
void Cache::checkEvents() { void Cache::checkEvents() {
SDL_Event event; SDL_Event event;

View File

@@ -68,6 +68,7 @@ namespace Resource {
void renderProgress(); void renderProgress();
static void checkEvents(); static void checkEvents();
void updateLoadingProgress(int steps = 5); void updateLoadingProgress(int steps = 5);
void setCurrentLoading(const std::string& name); // Desa el nom del recurs en curs i repinta (wasm/debug)
// Helper para mensajes de error de carga // Helper para mensajes de error de carga
[[noreturn]] static void throwLoadError(const std::string& asset_type, const std::string& file_path, const std::exception& e); [[noreturn]] static void throwLoadError(const std::string& asset_type, const std::string& file_path, const std::exception& e);
@@ -91,6 +92,7 @@ namespace Resource {
ResourceCount count_{}; // Contador de recursos ResourceCount count_{}; // Contador de recursos
std::shared_ptr<Text> loading_text_; // Texto para la pantalla de carga std::shared_ptr<Text> loading_text_; // Texto para la pantalla de carga
std::string current_loading_name_; // Nom del recurs que s'està a punt de carregar (debug/wasm)
}; };
} // namespace Resource } // namespace Resource