Skip to content

[BUG] Depth issue with mlx_delete_image() #52

Closed as not planned
Closed as not planned
@MyNameIsTrez

Description

@MyNameIsTrez

Describe the bug
There is an issue with depth, see the code below.

To Reproduce

void	loop(void *param)
{
	t_data				*data;
	static mlx_image_t	*image = NULL;
	int32_t				instance_1_id;
	int32_t				instance_2_id;

	data = param;

	// WHEN THIS IS COMMENTED IN, THE SECOND SQUARE DOESN'T GET DRAWN
	if (image != NULL)
	{
		mlx_delete_image(data->mlx, image);
		image = NULL;
	}

	if (image == NULL)
	{
		image = mlx_new_image(data->mlx, 100, 100);
		ft_memset(image->pixels, 255, image->width * image->height * sizeof(int));

		instance_1_id = mlx_image_to_window(data->mlx, image, 0, 0);
		instance_2_id = mlx_image_to_window(data->mlx, image, 100, 100);
	}
}

t_i32	main(void)
{
	t_data	data;

	ft_bzero(&data, sizeof(t_data));
	data.mlx = mlx_init(200, 200, "", false);
	mlx_loop_hook(data.mlx, loop, &data);
	mlx_loop(data.mlx);
	return (EXIT_SUCCESS);
}

Expected behavior
The second square to be drawn, see the comment in the code.

Additional context
If you replace the const float depth = mlxctx->zdepth; with const float depth = 1000000; inside of mlx_update_matrix() you'll see that everything works as expected, though hardcoding it to such a low value is obviously problematic when you create more than a million instances during the lifetime of the program. Ideally you also wouldn't set it to a huge ass constant since it'd still be technically reachable if you ran the program long enough, though how you resolve this issue is up to you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working or should get fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions