Browse Source

added checks for invalid files (obj files & textures)

iver 7 months ago
parent
commit
15aa88ec16

BIN
builds/final binaries/librasteriver.so


BIN
builds/final binaries/main.bin


+ 46 - 0
objects/error_object.obj

@@ -0,0 +1,46 @@
+# Blender v2.76 (sub 0) OBJ File: ''
+# www.blender.org
+mtllib cube.mtl
+o Cube
+v 1.000000 -1.000000 -1.000000
+v 1.000000 -1.000000 1.000000
+v -1.000000 -1.000000 1.000000
+v -1.000000 -1.000000 -1.000000
+v 1.000000 1.000000 -0.999999
+v 0.999999 1.000000 1.000001
+v -1.000000 1.000000 1.000000
+v -1.000000 1.000000 -1.000000
+vt 1.000000 0.333333
+vt 1.000000 0.666667
+vt 0.666667 0.666667
+vt 0.666667 0.333333
+vt 0.666667 0.000000
+vt 0.000000 0.333333
+vt 0.000000 0.000000
+vt 0.333333 0.000000
+vt 0.333333 1.000000
+vt 0.000000 1.000000
+vt 0.000000 0.666667
+vt 0.333333 0.333333
+vt 0.333333 0.666667
+vt 1.000000 0.000000
+vn 0.000000 -1.000000 0.000000
+vn 0.000000 1.000000 0.000000
+vn 1.000000 0.000000 0.000000
+vn -0.000000 0.000000 1.000000
+vn -1.000000 -0.000000 -0.000000
+vn 0.000000 0.000000 -1.000000
+usemtl Material
+s off
+f 2/1/1 3/2/1 4/3/1
+f 8/1/2 7/4/2 6/5/2
+f 5/6/3 6/7/3 2/8/3
+f 6/8/4 7/5/4 3/4/4
+f 3/9/5 7/10/5 8/11/5
+f 1/12/6 4/13/6 8/11/6
+f 1/4/1 2/1/1 4/3/1
+f 5/14/2 8/1/2 6/5/2
+f 1/12/3 5/6/3 2/8/3
+f 2/12/4 6/8/4 3/4/4
+f 4/13/5 3/9/5 8/11/5
+f 5/6/6 1/12/6 8/11/6

+ 33 - 11
src/RasterIver/source code/rasteriver.c

@@ -398,8 +398,9 @@ void malloc_objects(int objects, char **file_names){
         FILE *file = fopen(file_names[i], "r");
 
         if(file == NULL){
-            debug(RI_DEBUG_LOW, "Error Opening Object File");
-            RI_Stop(0);
+            debug(RI_DEBUG_LOW, "Error Opening Object File \"%s\"", file_names[i]);
+            
+            file = fopen("objects/error_object.obj", "r");
         }
 
         char line[256];
@@ -469,8 +470,7 @@ load_object_return load_object(char *object_path, int object_offset, int base){
     FILE *file = fopen(object_path, "r");
 
     if(file == NULL){
-        debug(RI_DEBUG_LOW, "Error Opening Object File");
-        RI_Stop(0);
+        file = fopen("objects/error_object.obj", "r");
     }
 
     char line[256];
@@ -658,9 +658,20 @@ RI_objects RI_RequestObjects(RI_newObject *RI_ObjectBuffer, int RI_ObjectsToRequ
             texture_names[texture_count] = loading_object_current_object->texture;
             objects[base + 14] = texture_count; // texture offset
             texture_count++;
+
             int texture_width, texture_height, channels;
+
             stbi_load(loading_object_current_object->texture, &texture_width, &texture_height, &channels, 4);
-            debug(RI_DEBUG_MEDIUM, "Texture (%s) Loaded With Size %dx%d (%d channels)", loading_object_current_object->texture, texture_width, texture_height, channels);
+            if(stbi_failure_reason()){
+                texture_width = 1;
+                texture_height = 1;
+
+                debug(RI_DEBUG_LOW, "Error Loading Texture \"%s\"", loading_object_current_object->texture);
+            }
+            else{
+                debug(RI_DEBUG_MEDIUM, "Texture (%s) Loaded With Size %dx%d (%d channels)", loading_object_current_object->texture, texture_width, texture_height, channels);
+            }
+
             textures_size += texture_width * texture_height;
         }
 
@@ -719,16 +730,27 @@ RI_objects RI_RequestObjects(RI_newObject *RI_ObjectBuffer, int RI_ObjectsToRequ
         int temp_width, temp_height;
         RI_textures temp_texture = stbi_load(current_texture_name, &temp_width, &temp_height, NULL, 4);
 
+        if(stbi_failure_reason()){
+            temp_width = 1;
+            temp_height = 1;
+            
+            textures[0 + value_offset] = 255;
+            textures[1 + value_offset] = 0;
+            textures[2 + value_offset] = 255;
+            textures[3 + value_offset] = 128;
+        }
+        else {
+            debug(RI_DEBUG_HIGH, "Texture Info for Texture #%d: width: %d, height: %d, offset: %d", i_current_texture, texture_info[i_current_texture * tis], texture_info[i_current_texture * tis + 1], texture_info[i_current_texture * tis + 2]);
+
+            for (int i_current_value = 0; i_current_value < temp_width * temp_height * 4; i_current_value++){
+                textures[i_current_value + value_offset] = temp_texture[i_current_value];
+            }
+        }
+
         texture_info[i_current_texture * tis] = temp_width;
         texture_info[i_current_texture * tis + 1] = temp_height;
         texture_info[i_current_texture * tis + 2] = value_offset;
 
-        debug(RI_DEBUG_HIGH, "Texture Info for Texture #%d: width: %d, height: %d, offset: %d", i_current_texture, texture_info[i_current_texture * tis], texture_info[i_current_texture * tis + 1], texture_info[i_current_texture * tis + 2]);
-
-        for (int i_current_value = 0; i_current_value < temp_width * temp_height * 4; i_current_value++){
-            textures[i_current_value + value_offset] = temp_texture[i_current_value];
-        }
-
         value_offset += temp_width * temp_height * 4;
     }
 

+ 5 - 5
src/launch program/main.c

@@ -27,17 +27,17 @@ int main(){
     }
 
     RI_newObject object_buffer[3] = {
-        {0, 0, 1000,       0, 0, 0, -9999999,          100, 100, 100,  "objects/rotated_cube.obj", "textures/bill_mcdinner.png"},
+        {0, 0, 300,       0, 0, 0, -9999999,          100, 100, 100,  "objects/rsotated_cube.obj", "textures/thistexturedoesntexist.png"},
         {0, 0, 15,         0, 0, 0, -9999999,  1, 1, 1,     "objects/test_guy_hd.obj", "textures/test_guy_texture.png"},
         {0, 0, 300,      0, 0.0, 0, -9999999,          50, 50, 50,  "objects/rotated_cube.obj", "textures/bill_mcdinner.png"},
     };
 
-    //RI_objects objects = RI_RequestObjects(object_buffer, 1);
+    RI_objects objects = RI_RequestObjects(object_buffer, 1);
 
     while (RI_IsRunning() == RI_RUNNING){
-        // objects[3] += 0.3;
-        // objects[4] -= 0.4;
-        // objects[5] += 0.3;
+        objects[3] += 0.3;
+        objects[4] -= 0.4;
+        objects[5] += 0.3;
         
         RI_Tick();
     }