From 8c4b834f7719046e67dec0d1a54c23c230bc3848 Mon Sep 17 00:00:00 2001 From: Lyude Paul Date: Fri, 4 Oct 2024 11:27:54 -0400 Subject: [PATCH] Fix crash from invalid nvim_ui_pum_set_bounds args Fixes #112, hopefully. My assumption here now is that because of the GTK+ bug causing the popup menu to close pre-emptively due to popup menu ownership changes - we may also be getting invalid coordinates when this happens, resulting in nvim being upset. So, let's try fixing this. --- src/popup_menu/mod.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/popup_menu/mod.rs b/src/popup_menu/mod.rs index 34d05d8..9fda9f3 100644 --- a/src/popup_menu/mod.rs +++ b/src/popup_menu/mod.rs @@ -407,6 +407,13 @@ impl PopupMenu { (x as f64, y as f64, w as f64, h as f64) ); + // Double check that we're not sending it bogus coordinates, nvim will get very + // upset if we do + if w <= 0.0 || h <= 0.0 { + debug!("popupmenu bounds are bogus ({w}x{h}), ignoring"); + return; + } + if x < 0.0 { w += x; x = 0.0;