diff --git a/Makefile b/Makefile index a3f9e7e..fb5cf0c 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,8 @@ ARCH ?= $(shell uname -m || echo unknown) ifeq ($(shell uname -s),Darwin) PLATFORM := macOS PLATFORM_DIR := mac - THREADS := $(shell sysctl -n hw.ncpu || echo 1) + THREADS := 1 +# THREADS := $(shell sysctl -n hw.ncpu || echo 1) OS_LIBFT := libft/mac MLX_DIR := $(MLX)_macos MLX_A := $(MLX_DIR)/libmlx.a @@ -38,7 +39,8 @@ ifeq ($(shell uname -s),Darwin) else PLATFORM := $(shell uname -s || echo unknown) PLATFORM_DIR := linux - THREADS := $(shell getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1) + THREADS := 1 +# THREADS := $(shell getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1) OS_LIBFT := libft/linux MLX_DIR := $(MLX)-linux MLX_A := $(MLX_DIR)/libmlx_Linux.a diff --git a/includes/config.h b/includes/config.h index fb87720..e5abc6a 100644 --- a/includes/config.h +++ b/includes/config.h @@ -19,6 +19,7 @@ # define PROGRAM "miniRT" # define EXECUTION "./miniRT" # define EPSILON 1e-6 +# define NORM_EPSILON 1e-3 # define DBL_MAX __DBL_MAX__ # if defined(__APPLE__) @@ -77,13 +78,6 @@ # define MOUSE_SCROLL_UP 4 # define MOUSE_SCROLL_DOWN 5 -# if defined(__APPLE__) -# define ESC_KEY 53 -# else -# include -# define ESC_KEY XK_Escape -# endif - # define VALID 1 # define INVALID 0 diff --git a/includes/miniRT.h b/includes/miniRT.h index b382043..af549e8 100644 --- a/includes/miniRT.h +++ b/includes/miniRT.h @@ -60,7 +60,7 @@ int clamp_color(double value); void print_error(char *msg, ...); // free -void free_scene(t_scene *scene); +void free_scene(t_scene **scene); void free_ctx(t_ctx *ctx); #endif diff --git a/srcs/free.c b/srcs/free.c index aa53e96..087ffe6 100644 --- a/srcs/free.c +++ b/srcs/free.c @@ -12,27 +12,26 @@ #include "miniRT.h" -void free_scene(t_scene *scene) +void free_scene(t_scene **scene) { t_obj *current; t_obj *next; - if (scene) + if (!scene || !*scene) + return ; + if ((*scene)->objects) { - if (scene->objects) + current = (*scene)->objects; + while (current) { - current = scene->objects; - while (current) - { - next = current->next; - free(current->obj_data); - free(current); - current = next; - } + next = current->next; + free(current->obj_data); + free(current); + current = next; } - free(scene); } - scene = NULL; + free(*scene); + *scene = NULL; } void free_ctx(t_ctx *ctx) @@ -42,6 +41,6 @@ void free_ctx(t_ctx *ctx) if (ctx->img) free(ctx->img); if (ctx->scene) - free_scene(ctx->scene); + free_scene(&ctx->scene); free(ctx); } diff --git a/srcs/parsing/object_list.c b/srcs/parsing/object_list.c index ab8abdc..7728139 100644 --- a/srcs/parsing/object_list.c +++ b/srcs/parsing/object_list.c @@ -19,7 +19,7 @@ t_obj *create_object_node(t_obj_type type, void *obj) node = (t_obj *)malloc(sizeof(t_obj)); if (!node) { - perror(""); + print_error(ERR_MSG_MALLOC); return (NULL); } node->type = type; diff --git a/srcs/parsing/parse.c b/srcs/parsing/parse.c index 9622f01..b2c117c 100644 --- a/srcs/parsing/parse.c +++ b/srcs/parsing/parse.c @@ -110,12 +110,12 @@ t_scene *parse_scene(char *filename) read_flags = 0; if (parse_file(filename, scene, &read_flags) < 0) { - free_scene(scene); + free_scene(&scene); return (NULL); } if (!validate_scene(read_flags)) { - free_scene(scene); + free_scene(&scene); return (NULL); } return (scene); diff --git a/srcs/parsing/validate_values.c b/srcs/parsing/validate_values.c index f64caff..b4f8b30 100644 --- a/srcs/parsing/validate_values.c +++ b/srcs/parsing/validate_values.c @@ -42,7 +42,7 @@ int validate_normalized_vec3(t_vec3 vec) double len_squared; len_squared = vec3_dot(vec, vec); - if (fabs(len_squared - 1.0) > EPSILON) + if (fabs(len_squared - 1.0) > NORM_EPSILON) return (INVALID); return (VALID); }