]> isoptera.lcsc.edu Git - engine26/.git/commitdiff
Added error handling for get_source
authorSeth Long <sslong@lcsc.edu>
Wed, 11 Nov 2026 23:54:47 +0000 (15:54 -0800)
committerSeth Long <sslong@lcsc.edu>
Wed, 11 Nov 2026 23:54:47 +0000 (15:54 -0800)
gameobject.cpp
main.cpp

index 623e9b8160e9c519b529cc1a70f82686602989ce..898be14ca1ad086e26c4088bb255ffee28aa190e 100644 (file)
@@ -2,9 +2,20 @@
 
 /* Remember to free the result! */
 char* get_source(const char *filename){
-       FILE *source_file = fopen(filename, "r");
-       fseek(source_file, 0, SEEK_END);
+       FILE *source_file = fopen(filename, "rb");
+       if(!source_file){
+               perror("fopen");
+               return 0;
+       }
+       if(fseek(source_file, 0, SEEK_END)){
+               perror("fseek");
+               return 0;
+       }
        long length = ftell(source_file);
+       if(!length){
+               printf("Error:  Source file %s has length 0\n", filename);
+               return 0;
+       }
        char *source = (char*)malloc(length + 1);
        rewind(source_file);
        fread(source, 1, length, source_file);
@@ -68,6 +79,10 @@ unsigned int load_shader(string shader_filename, unsigned int type){
        } else {
 
                char *source = get_source(shader_filename.c_str());
+               if(!source){
+                       printf("Shader %s failed to load\n", shader_filename.c_str());
+                       exit(1);
+               }
                puts(source);
                unsigned int vs_reference = glCreateShader(type);
                glShaderSource(vs_reference, 1, (const char**)&source, 0);
@@ -79,7 +94,7 @@ unsigned int load_shader(string shader_filename, unsigned int type){
                glGetShaderiv(vs_reference, GL_COMPILE_STATUS, &compile_ok);
                if(!compile_ok){
                        printf("Shader %s failed to compile\n", shader_filename.c_str());
-                       return false;
+                       exit(1);
                }
                gl_resources[shader_filename] = vs_reference;
                return vs_reference;
@@ -121,7 +136,7 @@ unsigned int make_program(const char* v_file, const char* tcs_file, const char*
                glGetProgramInfoLog(program, 2048, NULL, log_buffer);
                puts(log_buffer);
                puts("Link Failed");
-               return 0;
+               exit(1);
        }
 
        return program;
index 1ea8243a4abf6e341001d72fa3e0fd204d04d266..910d916e82625ff8e29d9aafa565387daf7a2057 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -229,10 +229,10 @@ void movement_function() {
                        o->movement(1000 * (start_time - last_start));
                last_start = start_time;
 
-               double end_time = glfwGetTime();
+//             double end_time = glfwGetTime();
                movement_count++;
-               double sleep_seconds = 0.001 - (end_time - start_time);
-               unsigned long sleep_microseconds = sleep_seconds * 1000000.0;
+//             double sleep_seconds = 0.001 - (end_time - start_time);
+//             unsigned long sleep_microseconds = sleep_seconds * 1000000.0;
 
 // Windows can sleep for a minimum of about 15ms by this method, it seems
 //             this_thread::sleep_for(chrono::microseconds(sleep_microseconds));