mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 01:48:08 +01:00
fix(sprite caster): Fixed crash when sprites overlap
Actually I'm not that sure it's the sprite overlap but it happened when the sprites overlapped too close to the player, but basically the program tried to render pixels out of bounds from the images, tex_x or tex_y were able to go < 0. I forcefully set them to 0 if it was the case, and I didn't see really much of visual glitches or something. Anyways I'll stop rambling in this commit, just to say I stopped a real weird crash because when I tried using valgrind or sanitizers, the program would behave well and not crash. Might be tied to how fast the program renders frames ?
This commit is contained in:
parent
0ac7c27445
commit
b138fe8100
1 changed files with 5 additions and 2 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/08/05 15:51:01 by tchampio #+# #+# */
|
||||
/* Updated: 2025/08/18 13:39:26 by tchampio ### ########.fr */
|
||||
/* Updated: 2025/08/19 19:42:43 by tchampio ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,7 +15,6 @@
|
|||
#include "../renderer/render.h"
|
||||
#include "sort_sprites.h"
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include "../../libft/includes/libft.h"
|
||||
|
||||
static void calculate_pos_and_transform(t_cub3d_data *data, t_sprite *sprite,
|
||||
|
|
@ -73,6 +72,8 @@ static void render_sprite_col(t_cub3d_data *data, int i, int tex_x, int stripe)
|
|||
d = (j) * 256 - HEIGHT * 128
|
||||
+ data->sprite_list[i]->sprite_height * 128;
|
||||
tex_y = ((d * SIZE) / data->sprite_list[i]->sprite_height) / 256;
|
||||
if (tex_y < 0)
|
||||
tex_y = 0;
|
||||
color = my_mlx_pixel_get(
|
||||
data->sprite_list[data->sprite_order[i]]->image,
|
||||
tex_x, tex_y);
|
||||
|
|
@ -94,6 +95,8 @@ static void render_sprites(t_cub3d_data *data, int i)
|
|||
- (-data->sprite_list[i]->sprite_width / 2
|
||||
+ data->sprite_list[i]->sprite_screen_x))
|
||||
* SIZE / data->sprite_list[i]->sprite_width) / 256;
|
||||
if (tex_x < 0)
|
||||
tex_x = 0;
|
||||
if (data->sprite_list[i]->transform_y > 0 && stripe > 0
|
||||
&& stripe < WIDTH
|
||||
&& data->sprite_list[i]->transform_y < data->zbuffer[stripe])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue