Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix windows chdir behavior #365

Merged
merged 6 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/harness/harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,13 @@ void Harness_Init(int* argc, char* argv[]) {
} else {
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 root_dir is empty or ".", no need to chdir
dethrace-labs marked this conversation as resolved.
Show resolved Hide resolved
if (root_dir != NULL && root_dir[0] != '\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) {
Expand Down
24 changes: 24 additions & 0 deletions src/harness/harness_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,30 @@ void debug_printf(const char* fmt, const char* fn, const char* fmt2, ...) {
puts("\033[0m");
}

void panic_printf(const char* fmt, const char* fn, const char* fmt2, ...) {
va_list ap;

FILE* fp = fopen("dethrace.log", "w");

puts("\033[0;31m");
printf(fmt, fn);

if (fp != NULL) {
fprintf(fp, fmt, fn);
}

va_start(ap, fmt2);
vprintf(fmt2, ap);
if (fp != NULL) {
vfprintf(fp, fmt2, ap);
}
va_end(ap);
if (fp != NULL) {
fclose(fp);
}
puts("\033[0m");
}

void debug_print_vector3(const char* fmt, const char* fn, char* msg, br_vector3* v) {
printf(fmt, fn);
printf("%s %f, %f, %f\n", msg, v->v[0], v->v[1], v->v[2]);
Expand Down
6 changes: 3 additions & 3 deletions src/harness/include/harness/trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#include <stdlib.h>

extern int harness_debug_level;
extern int OS_IsDebuggerPresent(void);

void debug_printf(const char* fmt, const char* fn, const char* fmt2, ...);
void debug_printf(const char* fmt, const char* fn, const char* fmt2, ...);
void panic_printf(const char* fmt, const char* fn, const char* fmt2, ...);
void debug_print_vector3(const char* fmt, const char* fn, char* msg, br_vector3* v);
void debug_print_matrix34(const char* fmt, const char* fn, char* name, br_matrix34* m);
void debug_print_matrix4(const char* fmt, const char* fn, char* name, br_matrix4* m);
Expand Down Expand Up @@ -41,7 +41,7 @@ void debug_print_matrix4(const char* fmt, const char* fn, char* name, br_matrix4
#define LOG_WARN(...) debug_printf("\033[0;33m[WARN] %s ", __FUNCTION__, __VA_ARGS__)
#define LOG_PANIC(...) \
do { \
debug_printf("\033[0;31m[PANIC] %s ", __FUNCTION__, __VA_ARGS__); \
panic_printf("[PANIC] %s ", __FUNCTION__, __VA_ARGS__); \
abort(); \
} while (0)

Expand Down
4 changes: 4 additions & 0 deletions src/harness/renderers/gl/gl_renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ 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));

if (glGetString(GL_SHADING_LANGUAGE_VERSION) == NULL) {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this resolves a null pointer error inside glCreateProgram later on inside my windows VM which doesn't expose gl shaders

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What OpenGL version does the vm expose?

But you're probably correct to test capabilities instead of requiring a minimum OpenGL version.

LOG_PANIC("GL_SHADING_LANGUAGE_VERSION is null");
}

LoadShaders();
SetupFullScreenRectGeometry();

Expand Down