From e03c7980008ec4fca447a68e9515de589805ea8b Mon Sep 17 00:00:00 2001 From: Sergio Date: Tue, 19 Aug 2025 13:46:07 +0200 Subject: [PATCH] afegits logs peer a la carrega de musica i sons --- source/resource.cpp | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/source/resource.cpp b/source/resource.cpp index a7f3dbd..1ee6426 100644 --- a/source/resource.cpp +++ b/source/resource.cpp @@ -31,10 +31,16 @@ namespace { // Crear archivo temporal std::string temp_path = "/tmp/ccae_audio_" + std::to_string(std::hash{}(file_path)); std::ofstream temp_file(temp_path, std::ios::binary); + if (!temp_file) { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: Cannot create temp file %s", temp_path.c_str()); + return file_path; + } temp_file.write(reinterpret_cast(resource_data.data()), resource_data.size()); temp_file.close(); + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Created temp audio file: %s (%zu bytes)", temp_path.c_str(), resource_data.size()); return temp_path; } + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Using filesystem audio file: %s", file_path.c_str()); return file_path; // Usar ruta original si no está en pack } } @@ -312,7 +318,11 @@ auto Resource::loadSoundLazy(const std::string &name) -> JA_Sound_t * { for (const auto &file : sound_list) { if (getFileName(file) == name) { std::string audio_path = createTempAudioFile(file); - return JA_LoadSound(audio_path.c_str()); + JA_Sound_t* loaded_sound = JA_LoadSound(audio_path.c_str()); + if (!loaded_sound) { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: JA_LoadSound failed for %s (path: %s)", name.c_str(), audio_path.c_str()); + } + return loaded_sound; } } #endif @@ -326,7 +336,11 @@ auto Resource::loadMusicLazy(const std::string &name) -> JA_Music_t * { for (const auto &file : music_list) { if (getFileName(file) == name) { std::string audio_path = createTempAudioFile(file); - return JA_LoadMusic(audio_path.c_str()); + JA_Music_t* loaded_music = JA_LoadMusic(audio_path.c_str()); + if (!loaded_music) { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: JA_LoadMusic failed for %s (path: %s)", name.c_str(), audio_path.c_str()); + } + return loaded_music; } } #endif @@ -469,7 +483,11 @@ void Resource::loadSounds() { updateLoadingProgress(name); #ifndef NO_AUDIO std::string audio_path = createTempAudioFile(l); - sounds_.emplace_back(name, JA_LoadSound(audio_path.c_str())); + JA_Sound_t* loaded_sound = JA_LoadSound(audio_path.c_str()); + if (!loaded_sound) { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: JA_LoadSound failed for %s (path: %s)", name.c_str(), audio_path.c_str()); + } + sounds_.emplace_back(name, loaded_sound); #else sounds_.emplace_back(name, nullptr); #endif @@ -488,7 +506,11 @@ void Resource::loadMusics() { updateLoadingProgress(name); #ifndef NO_AUDIO std::string audio_path = createTempAudioFile(l); - musics_.emplace_back(name, JA_LoadMusic(audio_path.c_str())); + JA_Music_t* loaded_music = JA_LoadMusic(audio_path.c_str()); + if (!loaded_music) { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: JA_LoadMusic failed for %s (path: %s)", name.c_str(), audio_path.c_str()); + } + musics_.emplace_back(name, loaded_music); #else musics_.emplace_back(name, nullptr); #endif