@@ -13,6 +13,13 @@ pub const std_options: std.Options = .{
13
13
.log_level = std .log .default_level ,
14
14
};
15
15
16
+ pub fn panic (msg : []const u8 , st : ? * std.builtin.StackTrace , addr : ? usize ) noreturn {
17
+ _ = st ;
18
+ _ = addr ;
19
+ std .log .err ("panic: {s}" , .{msg });
20
+ @trap ();
21
+ }
22
+
16
23
/// These landmarks correspond to the closest to dlib's 5 alignment landmarks.
17
24
/// For more information check dlib's blog.
18
25
/// https://blog.dlib.net/2017/09/fast-multiclass-object-detection-in.html
@@ -94,18 +101,25 @@ pub export fn extract_aligned_face(
94
101
blurring : i32 ,
95
102
landmarks_ptr : [* ]const Point2d ,
96
103
landmarks_len : usize ,
97
- extra_ptr : [* ]u8 ,
98
- extra_size : usize ,
104
+ extra_ptr : ? [* ]u8 ,
105
+ extra_len : usize ,
99
106
) void {
100
- const allocator = blk : {
101
- if (builtin .cpu .arch == .wasm32 ) {
102
- var fba = std .heap .FixedBufferAllocator .init (extra_ptr [0.. extra_size ]);
103
- break :blk fba .allocator ();
107
+ var arena = std .heap .ArenaAllocator .init (blk : {
108
+ if (builtin .cpu .arch .isWasm () and builtin .os .tag == .freestanding ) {
109
+ // We need at least one Image(Rgba) for blurring and one Image(f32) for the integral image.
110
+ assert (extra_len >= 8 * rows * cols );
111
+ if (extra_ptr ) | ptr | {
112
+ var fba = std .heap .FixedBufferAllocator .init (ptr [0.. extra_len ]);
113
+ break :blk fba .allocator ();
114
+ } else {
115
+ @panic ("ERROR: extra_ptr can't be null when running in WebAssembly." );
116
+ }
104
117
} else {
105
- var gpa = std .heap .GeneralPurposeAllocator (.{}){};
106
- break :blk gpa .allocator ();
118
+ break :blk std .heap .page_allocator ;
107
119
}
108
- };
120
+ });
121
+ defer arena .deinit ();
122
+ const allocator = arena .allocator ();
109
123
110
124
const image : Image (Rgba ) = .{
111
125
.rows = rows ,
0 commit comments