Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Check if we exhausted the instance buffer prior to copying underlines

Antonio Scandurra9c337908099e
diff --git a/crates/gpui/src/platform/mac/metal_renderer.rs b/crates/gpui/src/platform/mac/metal_renderer.rs
index d3a32cc41d2..1589757d935 100644
--- a/crates/gpui/src/platform/mac/metal_renderer.rs
+++ b/crates/gpui/src/platform/mac/metal_renderer.rs
@@ -658,6 +658,12 @@ impl MetalRenderer {
let underline_bytes_len = mem::size_of_val(underlines);
let buffer_contents = unsafe { (self.instances.contents() as *mut u8).add(*offset) };
+
+ let next_offset = *offset + underline_bytes_len;
+ if next_offset > INSTANCE_BUFFER_SIZE {
+ return false;
+ }
+
unsafe {
ptr::copy_nonoverlapping(
underlines.as_ptr() as *const u8,
@@ -666,11 +672,6 @@ impl MetalRenderer {
);
}
- let next_offset = *offset + underline_bytes_len;
- if next_offset > INSTANCE_BUFFER_SIZE {
- return false;
- }
-
command_encoder.draw_primitives_instanced(
metal::MTLPrimitiveType::Triangle,
0,