Fix: Buscar resources.pack relativo al ejecutable, no al working directory
- Movido getExecutableDirectory() a defines.h como función inline - Actualizado main.cpp para construir path absoluto a resources.pack - Eliminadas definiciones duplicadas en engine.cpp y main.cpp - Ahora funciona correctamente ejecutando desde cualquier carpeta (ej. build/) TEST confirmado: - Ejecutar desde raíz: ✅ Carga resources.pack - Ejecutar desde build/: ✅ Carga resources.pack 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -225,4 +225,31 @@ constexpr float LOGO_CONVERGENCE_DISTANCE = 20.0f; // Distancia (px) para con
|
||||
constexpr int LOGO_JUMP_PROBABILITY_FROM_DEMO = 5; // 5% probabilidad en DEMO normal (más raro)
|
||||
constexpr int LOGO_JUMP_PROBABILITY_FROM_DEMO_LITE = 3; // 3% probabilidad en DEMO LITE (aún más raro)
|
||||
|
||||
constexpr float PI = 3.14159265358979323846f; // Constante PI
|
||||
constexpr float PI = 3.14159265358979323846f; // Constante PI
|
||||
|
||||
// Función auxiliar para obtener la ruta del directorio del ejecutable
|
||||
#include <filesystem>
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
#endif
|
||||
|
||||
inline std::string getExecutableDirectory() {
|
||||
#ifdef _WIN32
|
||||
char buffer[MAX_PATH];
|
||||
GetModuleFileNameA(NULL, buffer, MAX_PATH);
|
||||
std::filesystem::path exe_path(buffer);
|
||||
return exe_path.parent_path().string();
|
||||
#else
|
||||
char buffer[PATH_MAX];
|
||||
ssize_t len = readlink("/proc/self/exe", buffer, sizeof(buffer) - 1);
|
||||
if (len != -1) {
|
||||
buffer[len] = '\0';
|
||||
std::filesystem::path exe_path(buffer);
|
||||
return exe_path.parent_path().string();
|
||||
}
|
||||
return ".";
|
||||
#endif
|
||||
}
|
||||
@@ -35,18 +35,7 @@
|
||||
#include "shapes/torus_shape.h" // for TorusShape
|
||||
#include "shapes/wave_grid_shape.h" // for WaveGridShape
|
||||
|
||||
// Función auxiliar para obtener la ruta del directorio del ejecutable
|
||||
std::string getExecutableDirectory() {
|
||||
#ifdef _WIN32
|
||||
char buffer[MAX_PATH];
|
||||
GetModuleFileNameA(NULL, buffer, MAX_PATH);
|
||||
std::filesystem::path exe_path(buffer);
|
||||
return exe_path.parent_path().string();
|
||||
#else
|
||||
// Para Linux/macOS se podría usar readlink("/proc/self/exe") o dladdr
|
||||
return "."; // Fallback para otros sistemas
|
||||
#endif
|
||||
}
|
||||
// getExecutableDirectory() ya está definido en defines.h como inline
|
||||
|
||||
// Implementación de métodos públicos
|
||||
bool Engine::initialize(int width, int height, int zoom, bool fullscreen) {
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
#include <cstring>
|
||||
#include "engine.h"
|
||||
|
||||
// getExecutableDirectory() ya está definido en defines.h como inline
|
||||
|
||||
void printHelp() {
|
||||
std::cout << "ViBe3 Physics - Simulador de físicas avanzadas\n";
|
||||
std::cout << "\nUso: vibe3_physics [opciones]\n\n";
|
||||
@@ -73,7 +75,9 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
|
||||
// Inicializar sistema de recursos empaquetados (intentar cargar resources.pack)
|
||||
Texture::initResourceSystem("resources.pack");
|
||||
std::string exe_dir = getExecutableDirectory();
|
||||
std::string pack_path = exe_dir + "/resources.pack";
|
||||
Texture::initResourceSystem(pack_path);
|
||||
|
||||
Engine engine;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user