change to dynamic allocation as array gets stack overflow

This commit is contained in:
jonathan santis 2024-11-25 11:50:16 +01:00
parent bca4b26dd7
commit a1694c8209
2 changed files with 4 additions and 3 deletions

View File

@ -2,6 +2,7 @@ const std = @import("std");
const rl = @import("raylib"); const rl = @import("raylib");
const rg = @import("raygui"); const rg = @import("raygui");
const pr = @import("primitives.zig"); const pr = @import("primitives.zig");
const allocator = std.heap.page_allocator;
var prng = std.rand.DefaultPrng.init(124346556); var prng = std.rand.DefaultPrng.init(124346556);
@ -85,8 +86,8 @@ pub fn main() anyerror!void {
var posx : i32 = 0; var posx : i32 = 0;
var posy : i32 = 0; var posy : i32 = 0;
var p1 : [5000]Particle = undefined; const p1 = try allocator.alloc(Particle,5000);
for (&p1) |*p| { for (p1) |*p| {
xrnr = rand.float(f32); xrnr = rand.float(f32);
yrnr = rand.float(f32); yrnr = rand.float(f32);
p.* = Particle{.velocity = .{.a = .{.x = 1,.y = -3}},.acceleration = .{.a = .{.x=xrnr,.y=yrnr}}}; p.* = Particle{.velocity = .{.a = .{.x = 1,.y = -3}},.acceleration = .{.a = .{.x=xrnr,.y=yrnr}}};
@ -125,7 +126,7 @@ pub fn main() anyerror!void {
else =>{}, else =>{},
} }
} }
for (&p1) |*p| { for (p1) |*p| {
p.update(); p.update();
p.applyGravity(2); p.applyGravity(2);
if(p.position.a.x >= -(screenWidth/2)){ if(p.position.a.x >= -(screenWidth/2)){

Binary file not shown.