fix: no carregava correctament data/shapes/jailgames.png si s'executava desde fora del directori de l'executable

This commit is contained in:
2026-03-08 22:24:41 +01:00
parent fa285519b2
commit b9264c96a1
3 changed files with 5 additions and 2 deletions

View File

@@ -1829,7 +1829,7 @@ void Engine::activateShapeInternal(ShapeType type) {
active_shape_ = std::make_unique<AtomShape>();
break;
case ShapeType::PNG_SHAPE:
active_shape_ = std::make_unique<PNGShape>("data/shapes/jailgames.png");
active_shape_ = std::make_unique<PNGShape>((getResourcesDirectory() + "/data/shapes/jailgames.png").c_str());
break;
default:
active_shape_ = std::make_unique<SphereShape>(); // Fallback

View File

@@ -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;
}

View File

@@ -269,7 +269,7 @@ void ShapeManager::activateShapeInternal(ShapeType type) {
active_shape_ = std::make_unique<AtomShape>();
break;
case ShapeType::PNG_SHAPE:
active_shape_ = std::make_unique<PNGShape>("data/shapes/jailgames.png");
active_shape_ = std::make_unique<PNGShape>((getResourcesDirectory() + "/data/shapes/jailgames.png").c_str());
break;
default:
active_shape_ = std::make_unique<SphereShape>(); // Fallback