chdir to exe path (#345)
* using OS_Basename to get root directory from argv[0] * remove call to old GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS since opengl guarantees at least 16
This commit is contained in:
parent
dc135e46ec
commit
511d827e7e
|
|
@ -174,15 +174,17 @@ void Harness_Init(int* argc, char* argv[]) {
|
|||
}
|
||||
|
||||
char* root_dir = getenv("DETHRACE_ROOT_DIR");
|
||||
if (root_dir == NULL) {
|
||||
LOG_INFO("DETHRACE_ROOT_DIR is not set, assuming '.'");
|
||||
if (root_dir != NULL) {
|
||||
LOG_INFO("DETHRACE_ROOT_DIR is set to '%s'", root_dir);
|
||||
} else {
|
||||
printf("Data directory: %s\n", root_dir);
|
||||
result = chdir(root_dir);
|
||||
if (result != 0) {
|
||||
LOG_PANIC("Failed to chdir. Error is %s", strerror(errno));
|
||||
}
|
||||
root_dir = OS_Dirname(argv[0]);
|
||||
}
|
||||
printf("Using root directory: %s\n", root_dir);
|
||||
result = chdir(root_dir);
|
||||
if (result != 0) {
|
||||
LOG_PANIC("Failed to chdir. Error is %s", strerror(errno));
|
||||
}
|
||||
|
||||
if (harness_game_info.mode == eGame_none) {
|
||||
Harness_DetectGameMode();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,4 +30,8 @@ FILE* OS_fopen(const char* pathname, const char* mode);
|
|||
|
||||
size_t OS_ConsoleReadPassword(char* pBuffer, size_t pBufferLen);
|
||||
|
||||
char* OS_Dirname(const char* path);
|
||||
|
||||
char* OS_Basename(const char* path);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -25,12 +25,14 @@
|
|||
#include <unistd.h>
|
||||
|
||||
#define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
|
||||
#define MAX_STACK_FRAMES 64
|
||||
#define TRACER_PID_STRING "TracerPid:"
|
||||
|
||||
static int stack_nbr = 0;
|
||||
static char _program_name[1024];
|
||||
#define MAX_STACK_FRAMES 64
|
||||
|
||||
static void* stack_traces[MAX_STACK_FRAMES];
|
||||
#define TRACER_PID_STRING "TracerPid:"
|
||||
static char name_buf[4096];
|
||||
|
||||
struct dl_iterate_callback_data {
|
||||
int initialized;
|
||||
|
|
@ -176,7 +178,7 @@ static void signal_handler(int sig, siginfo_t* siginfo, void* context) {
|
|||
void resolve_full_path(char* path, const char* argv0) {
|
||||
if (argv0[0] == '/') { // run with absolute path
|
||||
strcpy(path, argv0);
|
||||
} else { // run with relative path
|
||||
} else { // run with relative path
|
||||
if (NULL == getcwd(path, PATH_MAX)) {
|
||||
perror("getcwd error");
|
||||
return;
|
||||
|
|
@ -301,3 +303,13 @@ size_t OS_ConsoleReadPassword(char* pBuffer, size_t pBufferLen) {
|
|||
tcsetattr(STDIN_FILENO, TCSANOW, &old);
|
||||
return len;
|
||||
}
|
||||
|
||||
char* OS_Dirname(const char* path) {
|
||||
strcpy(name_buf, path);
|
||||
return dirname(name_buf);
|
||||
}
|
||||
|
||||
char* OS_Basename(const char* path) {
|
||||
strcpy(name_buf, path);
|
||||
return basename(name_buf);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ static int stack_nbr = 0;
|
|||
static char _program_name[1024];
|
||||
#define MAX_STACK_FRAMES 64
|
||||
static void* stack_traces[MAX_STACK_FRAMES];
|
||||
static char name_buf[4096];
|
||||
|
||||
// Resolve symbol name and source location given the path to the executable and an address
|
||||
int addr2line(char const* const program_name, intptr_t slide, void const* const addr) {
|
||||
|
|
@ -228,3 +229,13 @@ size_t OS_ConsoleReadPassword(char* pBuffer, size_t pBufferLen) {
|
|||
fgets(pBuffer, pBufferLen, stdin);
|
||||
return strlen(pBuffer);
|
||||
}
|
||||
|
||||
char* OS_Dirname(const char* path) {
|
||||
strcpy(name_buf, path);
|
||||
return dirname(name_buf);
|
||||
}
|
||||
|
||||
char* OS_Basename(const char* path) {
|
||||
strcpy(name_buf, path);
|
||||
return basename(name_buf);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,9 @@ void dr_dprintf(char* fmt_string, ...);
|
|||
static int stack_nbr = 0;
|
||||
static char _program_name[1024];
|
||||
|
||||
static char dirname_buf[_MAX_DIR];
|
||||
static char fname_buf[_MAX_FNAME];
|
||||
|
||||
int addr2line(char const* const program_name, void const* const addr) {
|
||||
char addr2line_cmd[512] = { 0 };
|
||||
|
||||
|
|
@ -169,3 +172,13 @@ size_t OS_ConsoleReadPassword(char* pBuffer, size_t pBufferLen) {
|
|||
fgets(pBuffer, pBufferLen, stdin);
|
||||
return strlen(pBuffer);
|
||||
}
|
||||
|
||||
char* OS_Dirname(const char* path) {
|
||||
_splitpath(path, NULL, dirname_buf, NULL, NULL);
|
||||
return dirname_buf;
|
||||
}
|
||||
|
||||
char* OS_Basename(const char* path) {
|
||||
_splitpath(path, NULL, NULL, fname_buf, NULL);
|
||||
return fname_buf;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -220,12 +220,6 @@ void GLRenderer_Init(int pRender_width, int pRender_height) {
|
|||
LOG_INFO("OpenGL version string: %s", glGetString(GL_VERSION));
|
||||
LOG_INFO("OpenGL shading language version string: %s", glGetString(GL_SHADING_LANGUAGE_VERSION));
|
||||
|
||||
int maxTextureImageUnits;
|
||||
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTextureImageUnits);
|
||||
if (maxTextureImageUnits < 3) {
|
||||
LOG_PANIC("GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS is %d. Need at least 3", maxTextureImageUnits);
|
||||
}
|
||||
|
||||
LoadShaders();
|
||||
SetupFullScreenRectGeometry();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
|
||||
#include "harness/hooks.h"
|
||||
#include "harness/os.h"
|
||||
#include "harness/win95_polyfill.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
|
@ -237,12 +238,11 @@ void DirectDrawDevice_SetPaletteEntries(PALETTEENTRY_* palette, int pFirst_colou
|
|||
}
|
||||
|
||||
void _splitpath_(char* path, char* drive, char* dir, char* fname, char* ext) {
|
||||
#ifdef _WIN32
|
||||
_splitpath(path, NULL, NULL, fname, NULL);
|
||||
#else
|
||||
char* base = basename(path);
|
||||
strcpy(fname, base);
|
||||
#endif
|
||||
assert(dir == NULL);
|
||||
assert(fname != NULL);
|
||||
|
||||
char* result = OS_Basename(path);
|
||||
strcpy(fname, result);
|
||||
}
|
||||
|
||||
int _CrtDbgReport_(int reportType, const char* filename, int linenumber, const char* moduleName, const char* format, ...) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue