File 0585-observer-Handling-unexpected-wx-event-regarding-port.patch of Package erlang

From b0ccea807a68e8d528c430466eb28165996672ee Mon Sep 17 00:00:00 2001
From: Micael Karlberg <bmk@erlang.org>
Date: Fri, 25 Nov 2022 12:17:42 +0100
Subject: [PATCH 2/3] [observer] Handling unexpected wx event regarding ports

OTP-18339
---
 lib/observer/src/observer_port_wx.erl | 28 +++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/lib/observer/src/observer_port_wx.erl b/lib/observer/src/observer_port_wx.erl
index a11ae4175a..847633da6b 100644
--- a/lib/observer/src/observer_port_wx.erl
+++ b/lib/observer/src/observer_port_wx.erl
@@ -147,12 +147,28 @@ handle_event(#wx{event=#wxSize{size={W,_}}},  State=#state{grid=Grid}) ->
     observer_lib:set_listctrl_col_size(Grid, W),
     {noreply, State};
 
-handle_event(#wx{event=#wxList{type=command_list_item_activated,
-			       itemIndex=Index}},
-	     State=#state{grid=Grid, ports=Ports, open_wins=Opened}) ->
-    Port = lists:nth(Index+1, Ports),
-    NewOpened = display_port_info(Grid, Port, Opened),
-    {noreply, State#state{open_wins=NewOpened}};
+%% handle_event(#wx{event = #wxList{type      = command_list_item_activated,
+%%                                  itemIndex = Index}},
+%% 	     State = #state{grid      = Grid,
+%%                             ports     = Ports,
+%%                             open_wins = Opened})
+%%   when is_list(Ports) andalso (length(Ports) >= (Index+1)) ->
+%%     Port      = lists:nth(Index+1, Ports),
+%%     NewOpened = display_port_info(Grid, Port, Opened),
+%%     {noreply, State#state{open_wins=NewOpened}};
+handle_event(#wx{event = #wxList{type      = command_list_item_activated,
+                                 itemIndex = Index}},
+	     State = #state{grid      = Grid,
+                            ports     = Ports,
+                            open_wins = Opened}) when is_list(Ports) ->
+    if
+        length(Ports) >= (Index+1) ->
+            Port      = lists:nth(Index+1, Ports),
+            NewOpened = display_port_info(Grid, Port, Opened),
+            {noreply, State#state{open_wins=NewOpened}};
+        true -> % Race - should we do somthing here?
+            {noreply, State}
+    end;
 
 handle_event(#wx{event=#wxList{type=command_list_item_right_click,
 			       itemIndex=Index}},
-- 
2.35.3

openSUSE Build Service is sponsored by