diff --git a/vlib/gg/gg.v b/vlib/gg/gg.v index dbc4dff641..a371d4eecc 100644 --- a/vlib/gg/gg.v +++ b/vlib/gg/gg.v @@ -416,19 +416,23 @@ pub fn (ctx &GG) draw_line(x, y, x2, y2 f32, color gx.Color) { } pub fn (ctx &GG) draw_arc(x, y, r, start_angle, end_angle f32, segments int, color gx.Color) { - ctx.use_color_shader(color) - mut vertices := arc_vertices(x, y, r, start_angle, end_angle, segments) + ctx.use_color_shader(color) + vertices := arc_vertices(x, y, r, start_angle, end_angle, segments) ctx.bind_vertices(vertices) gl.draw_arrays(C.GL_LINE_STRIP, 0, segments + 1) + unsafe { vertices.free() } } pub fn (ctx &GG) draw_filled_arc(x, y, r, start_angle, end_angle f32, segments int, color gx.Color) { ctx.use_color_shader(color) + + mut vertices := []f32 - vertices << [x, y] + vertices << [x, y] ! vertices << arc_vertices(x, y, r, start_angle, end_angle, segments) ctx.bind_vertices(vertices) gl.draw_arrays(C.GL_TRIANGLE_FAN, 0, segments + 2) + unsafe { vertices.free() } } pub fn (ctx &GG) draw_circle(x, y, r f32, color gx.Color) { @@ -441,16 +445,17 @@ pub fn (ctx &GG) draw_rounded_rect(x, y, w, h, r f32, color gx.Color) { segments := 6 + int(r / 8) // Create a rounded rectangle using a triangle fan mesh. - vertices << [x + (w/2.0), y + (h/2.0)] + vertices << [x + (w/2.0), y + (h/2.0)] ! vertices << arc_vertices(x + w - r, y + h - r, r, 0, 90, segments) vertices << arc_vertices(x + r, y + h - r, r, 90, 180, segments) vertices << arc_vertices(x + r, y + r, r, 180, 270, segments) vertices << arc_vertices(x + w - r, y + r, r, 270, 360, segments) // Finish the loop by going back to the first vertex - vertices << [vertices[2], vertices[3]] + vertices << [vertices[2], vertices[3]] ! ctx.bind_vertices(vertices) gl.draw_arrays(C.GL_TRIANGLE_FAN, 0, segments * 4 + 6) + unsafe { vertices.free() } } pub fn (ctx &GG) draw_empty_rounded_rect(x, y, w, h, r f32, color gx.Color) { @@ -465,6 +470,7 @@ pub fn (ctx &GG) draw_empty_rounded_rect(x, y, w, h, r f32, color gx.Color) { ctx.bind_vertices(vertices) gl.draw_arrays(C.GL_LINE_STRIP, 0, segments * 4 + 1) + unsafe { vertices.free() } } /* @@ -539,4 +545,4 @@ pub fn (c &GG) draw_empty_rect(x, y, w, h f32, color gx.Color) { pub fn scissor(x, y, w, h f32) { C.glScissor(x, y, w, h) -} \ No newline at end of file +} diff --git a/vlib/gg/utils.v b/vlib/gg/utils.v index 044d8d0030..0ae41096f2 100644 --- a/vlib/gg/utils.v +++ b/vlib/gg/utils.v @@ -11,14 +11,14 @@ fn arc_vertices(x, y, r, start_angle, end_angle f32, segments int) []f32 { start_rads := start_angle * 0.0174533 // deg -> rad approx end_rads := end_angle * 0.0174533 increment := (end_rads - start_rads) / segments - vertices << [x + f32(math.cos(start_rads)) * r, y + f32(math.sin(start_rads)) * r] + vertices << [x + f32(math.cos(start_rads)) * r, y + f32(math.sin(start_rads)) * r] ! mut i := 1 for i < segments { theta := f32(i) * increment + start_rads - vertices << [x + f32(math.cos(theta)) * r, y + f32(math.sin(theta)) * r] + vertices << [x + f32(math.cos(theta)) * r, y + f32(math.sin(theta)) * r] ! i++ } - vertices << [x + f32(math.cos(end_rads)) * r, y + f32(math.sin(end_rads)) * r] + vertices << [x + f32(math.cos(end_rads)) * r, y + f32(math.sin(end_rads)) * r] ! return vertices } diff --git a/vlib/os/os_nix.v b/vlib/os/os_nix.v index 1171399b39..7d5b17399d 100644 --- a/vlib/os/os_nix.v +++ b/vlib/os/os_nix.v @@ -1,5 +1,7 @@ module os +import strings + #include #include #include @@ -198,18 +200,19 @@ pub fn exec(cmd string) ?Result { if isnil(f) { return error('exec("$cmd") failed') } - buf := [1000]byte - mut res := '' - for C.fgets(charptr(buf), 1000, f) != 0 { - res += tos(buf, vstrlen(buf)) + buf := [4096]byte + mut res := strings.new_builder(1024) + for C.fgets(charptr(buf), 4096, f) != 0 { + res.write_bytes( buf, vstrlen(buf) ) } - res = res.trim_space() + soutput := res.str().trim_space() + res.free() exit_code := vpclose(f) // if exit_code != 0 { // return error(res) // } return Result{ - output: res + output: soutput exit_code: exit_code } } diff --git a/vlib/os/os_windows.v b/vlib/os/os_windows.v index afc4bb1fc6..4ba30cf9d6 100644 --- a/vlib/os/os_windows.v +++ b/vlib/os/os_windows.v @@ -1,5 +1,7 @@ module os +import strings + #flag -lws2_32 #include @@ -309,24 +311,25 @@ pub fn exec(cmd string) ?Result { } C.CloseHandle(child_stdin) C.CloseHandle(child_stdout_write) - buf := [1000]byte + buf := [4096]byte mut bytes_read := u32(0) - mut read_data := '' + mut read_data := strings.new_builder(1024) for { readfile_result := C.ReadFile(child_stdout_read, buf, 1000, voidptr(&bytes_read), 0) - read_data += tos(buf, int(bytes_read)) + read_data.write_bytes(buf, int(bytes_read)) if readfile_result == false || int(bytes_read) == 0 { break } } - read_data = read_data.trim_space() + soutput := read_data.str().trim_space() + read_data.free() exit_code := u32(0) C.WaitForSingleObject(proc_info.hProcess, C.INFINITE) C.GetExitCodeProcess(proc_info.hProcess, voidptr(&exit_code)) C.CloseHandle(proc_info.hProcess) C.CloseHandle(proc_info.hThread) return Result { - output: read_data + output: soutput exit_code: int(exit_code) } }