Check if we exhausted the instance buffer prior to copying underlines

This fixes another potential segfault.
This commit is contained in:
Antonio Scandurra 2024-01-17 09:50:55 +01:00
parent 97bd3e1fde
commit 9c33790809

View File

@ -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,