~colbyhub/pocket_dust

2c2fead57ffdb3556aa57c187694e5d9d30e0b85 — colbyhub 3 months ago 22245de
Prevent crashes when using large pen sizes
1 files changed, 6 insertions(+), 2 deletions(-)

M src/main.c
M src/main.c => src/main.c +6 -2
@@ 579,9 579,13 @@ void update(void) {
    if (*selected_id){
      for (int i = 1; i <= pen_size; i++){
        for (int j = 1; j <= pen_size; j++){
          particle_t *particle = get_particle(1 + *MOUSE_X + (pen_size / 2) - i, 1 + *MOUSE_Y + (pen_size / 2) - j);
          int x = 1 + *MOUSE_X + (pen_size / 2) - i;
          int y = 1 + *MOUSE_Y + (pen_size / 2) - j;
          // Hacky fix to prevent out-of-bounds memory access
          particle_t *particle = get_particle(x, y >= 0 ? y : 0);

          if (*selected_id == MATERIAL_ERASE_ID){
              set_particle_material_id(particle, MATERIAL_AIR_ID); 
            set_particle_material_id(particle, MATERIAL_AIR_ID); 
          } else if (get_particle_material_id(particle) == MATERIAL_AIR_ID) {
            if (pen_size > 1 && *selected_id != MATERIAL_GLASS_ID){
              // Don't scatter the particles if the game is paused