From b9264c96a1d8090c3b521dc7c78792afe3361dd0 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sun, 8 Mar 2026 22:24:41 +0100 Subject: [PATCH] fix: no carregava correctament data/shapes/jailgames.png si s'executava desde fora del directori de l'executable --- source/engine.cpp | 2 +- source/shapes/png_shape.cpp | 3 +++ source/shapes_mgr/shape_manager.cpp | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/source/engine.cpp b/source/engine.cpp index c9c71c7..c406400 100644 --- a/source/engine.cpp +++ b/source/engine.cpp @@ -1829,7 +1829,7 @@ void Engine::activateShapeInternal(ShapeType type) { active_shape_ = std::make_unique(); break; case ShapeType::PNG_SHAPE: - active_shape_ = std::make_unique("data/shapes/jailgames.png"); + active_shape_ = std::make_unique((getResourcesDirectory() + "/data/shapes/jailgames.png").c_str()); break; default: active_shape_ = std::make_unique(); // Fallback diff --git a/source/shapes/png_shape.cpp b/source/shapes/png_shape.cpp index 632ff62..d337d0a 100644 --- a/source/shapes/png_shape.cpp +++ b/source/shapes/png_shape.cpp @@ -9,6 +9,7 @@ PNGShape::PNGShape(const char* png_path) { // Cargar PNG desde path if (!loadPNG(png_path)) { + std::cerr << "[PNGShape] Usando fallback 10x10" << std::endl; // Fallback: generar un cuadrado simple si falla la carga image_width_ = 10; image_height_ = 10; @@ -20,10 +21,12 @@ PNGShape::PNGShape(const char* png_path) { } bool PNGShape::loadPNG(const char* path) { + std::cout << "[PNGShape] Intentando cargar: " << path << std::endl; int width, height, channels; unsigned char* data = stbi_load(path, &width, &height, &channels, 1); // Forzar 1 canal (grayscale) if (!data) { + std::cerr << "[PNGShape] ERROR al cargar PNG: " << stbi_failure_reason() << std::endl; return false; } diff --git a/source/shapes_mgr/shape_manager.cpp b/source/shapes_mgr/shape_manager.cpp index edbb84a..507ab87 100644 --- a/source/shapes_mgr/shape_manager.cpp +++ b/source/shapes_mgr/shape_manager.cpp @@ -269,7 +269,7 @@ void ShapeManager::activateShapeInternal(ShapeType type) { active_shape_ = std::make_unique(); break; case ShapeType::PNG_SHAPE: - active_shape_ = std::make_unique("data/shapes/jailgames.png"); + active_shape_ = std::make_unique((getResourcesDirectory() + "/data/shapes/jailgames.png").c_str()); break; default: active_shape_ = std::make_unique(); // Fallback