afegits logs peer a la carrega de musica i sons

This commit is contained in:
2025-08-19 13:46:07 +02:00
parent 52d76b7338
commit e03c798000

View File

@@ -31,10 +31,16 @@ namespace {
// Crear archivo temporal
std::string temp_path = "/tmp/ccae_audio_" + std::to_string(std::hash<std::string>{}(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<const char*>(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