-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed segfault and potential leak when frames failed to load
- Loading branch information
1 parent
4fb7866
commit b6bb3f4
Showing
2 changed files
with
9 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: tsuchen <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/08/15 00:19:44 by tsuchen #+# #+# */ | ||
/* Updated: 2024/09/04 12:28:56 by tsuchen ### ########.fr */ | ||
/* Updated: 2024/09/04 13:37:03 by tsuchen ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -59,6 +59,7 @@ | |
# define MOUSE_PRESS 4 | ||
# define MOUSE_MOVE 6 | ||
# define FILE_EXTENSION ".cub" | ||
# define FRAME_SCRIPT "./assets/animations/door_frame.txt" | ||
|
||
typedef enum e_texture t_texture; | ||
typedef struct s_textdata t_textdata; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: tsuchen <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/08/27 17:03:43 by jteissie #+# #+# */ | ||
/* Updated: 2024/09/03 18:58:48 by tsuchen ### ########.fr */ | ||
/* Updated: 2024/09/04 13:36:40 by tsuchen ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -31,8 +31,10 @@ static int init_frame(char *line, t_data *data, t_frame *f) | |
|
||
path = ft_strtrim(line, "\n"); | ||
if (!path) | ||
return (1); | ||
return (PANIC); | ||
f->img = mlx_xpm_file_to_image(data->mlx, path, &f->frm_w, &f->frm_h); | ||
if (!f->img) | ||
return (free(path), PANIC); | ||
f->addr = mlx_get_data_addr(f->img, &f->bpp, &f->ll, &f->endian); | ||
lst_add_back(&data->frames, f); | ||
free(path); | ||
|
@@ -45,9 +47,9 @@ static int load_frames(t_data *data) | |
int frame_fd; | ||
char *line; | ||
|
||
frame_fd = open("./assets/animations/door_frame.txt", O_RDONLY); | ||
frame_fd = open(FRAME_SCRIPT, O_RDONLY); | ||
if (frame_fd == -1) | ||
return (SUCCESS); | ||
return (PANIC); | ||
line = get_next_line(frame_fd); | ||
if (!line) | ||
return (PANIC); | ||
|
@@ -57,7 +59,7 @@ static int load_frames(t_data *data) | |
if (!f) | ||
return (close(frame_fd), PANIC); | ||
if (init_frame(line, data, f)) | ||
return (free(line), close(frame_fd), PANIC); | ||
return (free(line), close(frame_fd), free(f), PANIC); | ||
free(line); | ||
line = get_next_line(frame_fd); | ||
} | ||
|