deallocation fix
This commit is contained in:
parent
656c10d4ef
commit
cba71f4a60
1 changed files with 20 additions and 9 deletions
|
|
@ -16,6 +16,8 @@ const prnt = utility.prnt;
|
||||||
|
|
||||||
pub const SoundNode = struct {
|
pub const SoundNode = struct {
|
||||||
|
|
||||||
|
allocator: Allocator,
|
||||||
|
|
||||||
name: []const u8 = "soundnode",
|
name: []const u8 = "soundnode",
|
||||||
location: Pnt = Pnt{.x = 0, .y = 0, .z = 0},
|
location: Pnt = Pnt{.x = 0, .y = 0, .z = 0},
|
||||||
|
|
||||||
|
|
@ -26,23 +28,28 @@ pub const SoundNode = struct {
|
||||||
|
|
||||||
pub fn init(allocator: Allocator, name: []const u8) !SoundNode {
|
pub fn init(allocator: Allocator, name: []const u8) !SoundNode {
|
||||||
|
|
||||||
var air_in = ArrayList(*SoundNode).init(allocator);
|
const air_in = ArrayList(*SoundNode).init(allocator);
|
||||||
defer air_in.deinit();
|
const wire_in = ArrayList(*SoundNode).init(allocator);
|
||||||
|
const freqmap = AutoHashMap(u64, f16).init(allocator);
|
||||||
var wire_in = ArrayList(*SoundNode).init(allocator);
|
|
||||||
defer wire_in.deinit();
|
|
||||||
|
|
||||||
var freqmap = AutoHashMap(u64, f16).init(allocator);
|
|
||||||
defer freqmap.deinit();
|
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
|
.allocator = allocator,
|
||||||
|
.name = name,
|
||||||
.air_in = air_in,
|
.air_in = air_in,
|
||||||
.wire_in = wire_in,
|
.wire_in = wire_in,
|
||||||
.name = name,
|
|
||||||
.freqmap = freqmap,
|
.freqmap = freqmap,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn deinit(self: *SoundNode) void {
|
||||||
|
|
||||||
|
self.air_in.deinit();
|
||||||
|
self.wire_in.deinit();
|
||||||
|
self.freqmap.deinit();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn singleSineTick(st: *SoundSettings, freq: f16, t: u64) f64 {
|
pub fn singleSineTick(st: *SoundSettings, freq: f16, t: u64) f64 {
|
||||||
|
|
@ -56,7 +63,11 @@ pub fn main() !void {
|
||||||
const allocator = gpa.allocator();
|
const allocator = gpa.allocator();
|
||||||
|
|
||||||
var sn1: SoundNode = try SoundNode.init(allocator, "left_sink");
|
var sn1: SoundNode = try SoundNode.init(allocator, "left_sink");
|
||||||
|
defer sn1.deinit();
|
||||||
|
|
||||||
var sn2: SoundNode = try SoundNode.init(allocator, "right_sink");
|
var sn2: SoundNode = try SoundNode.init(allocator, "right_sink");
|
||||||
|
defer sn2.deinit();
|
||||||
|
|
||||||
sn2.location.x = -5;
|
sn2.location.x = -5;
|
||||||
sn1.location.x = 4;
|
sn1.location.x = 4;
|
||||||
try sn1.air_in.append(&sn2);
|
try sn1.air_in.append(&sn2);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue