Fix segfault on "Can't open jpeg"
authorLukas Jiriste <ljiriste@student.42prague.com>
Thu, 4 Apr 2024 08:48:54 +0000 (10:48 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Thu, 4 Apr 2024 08:48:54 +0000 (10:48 +0200)
Segfault was caused by trying to destroy image that was not initialized

solution/main.c
solution/mlx_addition.c

index 94434653143445ba65365541425e86a295a29ef4..d71e07db73a852b31304d8713fcafbe69a6f1442 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/04/02 08:44:53 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/04/04 10:38:20 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/04/04 10:47:06 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -18,6 +18,7 @@
 int    init_state(t_state *state)
 {
        state->graph.mlx_ses.mlx = mlx_init();
+       state->graph.mlx_ses.mlx_win = NULL;
        state->pos.x = 0;
        state->pos.y = 0;
        return (ft_vec_init(&state->found, sizeof(t_position)) != success
index 2642c250d960c341596489e2617771dc4578b48f..4c4868833a4a01da87068ada3dafd00f2f260578 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/04/04 10:27:01 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/04/04 10:37:03 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/04/04 10:48:19 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -54,7 +54,8 @@ int   display_trans_img(t_mlx_session *s, t_mlx_data *img,
 
        if (!s->mlx_win)
        {
-               mlx_destroy_image(s->mlx, to_print.img);
+               if (to_print.img)
+                       mlx_destroy_image(s->mlx, to_print.img);
                return (0);
        }
        if (!to_print.img)