Skip to content

Commit 485f2e2

Browse files
committed
Merge: bulletproof close + light theme demo
2 parents 4fefcf9 + 090adb9 commit 485f2e2

2 files changed

Lines changed: 47 additions & 17 deletions

File tree

demo/industrial_plant/private/buildCompanion.m

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
% - TagRegistry singleton has been populated by registerPlantTags so
1212
% the companion's catalog reflects every plant tag.
1313
%
14-
% Theme is hardcoded to 'dark' -- matching the existing dashboard's
15-
% visual register and avoiding a parameterization ahead of need. If the
16-
% demo gains a theme option in a later phase, lift this through ctx.
14+
% Theme is hardcoded to 'light' -- matching buildDashboard.m which also
15+
% renders the demo dashboard in 'light' theme. Keeping the two windows
16+
% visually consistent. If the demo gains a theme option in a later
17+
% phase, lift this through ctx.
1718
%
1819
% Returns:
1920
% companion - live FastSenseCompanion handle (uifigure already visible).
@@ -22,5 +23,5 @@
2223

2324
companion = FastSenseCompanion( ...
2425
'Dashboards', {ctx.engine}, ...
25-
'Theme', 'dark');
26+
'Theme', 'light');
2627
end

libs/FastSenseCompanion/FastSenseCompanion.m

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -186,31 +186,60 @@
186186
function close(obj)
187187
%CLOSE Idempotent teardown — deletes listeners, owned timers, and the uifigure.
188188
% Does NOT affect any DashboardEngine figure or ad-hoc plot figures.
189+
%
190+
% Bulletproof: every cleanup step is wrapped in try/catch so a
191+
% single failure (e.g. a stale listener handle, a pane already
192+
% half-deleted) cannot prevent the uifigure itself from being
193+
% deleted. The X-button must always close the window.
189194
if ~isvalid(obj)
190195
return;
191196
end
192197
if isempty(obj.hFig_) || ~isvalid(obj.hFig_)
198+
obj.hFig_ = [];
199+
obj.IsOpen = false;
193200
return;
194201
end
195-
% Detach panes (releases their listeners)
196-
if ~isempty(obj.CatalogPane_) && isvalid(obj.CatalogPane_)
197-
obj.CatalogPane_.detach();
202+
% Diagnostic — confirms the X click reached close().
203+
fprintf('[FastSenseCompanion] close() invoked, tearing down...\n');
204+
% Detach panes (releases their listeners + debounce timers).
205+
try
206+
if ~isempty(obj.CatalogPane_) && isvalid(obj.CatalogPane_)
207+
obj.CatalogPane_.detach();
208+
end
209+
catch err
210+
fprintf(2, '[FastSenseCompanion] CatalogPane.detach failed: %s\n', err.message);
198211
end
199-
if ~isempty(obj.ListPane_) && isvalid(obj.ListPane_)
200-
obj.ListPane_.detach();
212+
try
213+
if ~isempty(obj.ListPane_) && isvalid(obj.ListPane_)
214+
obj.ListPane_.detach();
215+
end
216+
catch err
217+
fprintf(2, '[FastSenseCompanion] ListPane.detach failed: %s\n', err.message);
218+
end
219+
try
220+
if ~isempty(obj.InspectorPane_) && isvalid(obj.InspectorPane_)
221+
obj.InspectorPane_.detach();
222+
end
223+
catch err
224+
fprintf(2, '[FastSenseCompanion] InspectorPane.detach failed: %s\n', err.message);
201225
end
202-
if ~isempty(obj.InspectorPane_) && isvalid(obj.InspectorPane_)
203-
obj.InspectorPane_.detach();
226+
% Release orchestrator-level listeners.
227+
try
228+
delete(obj.Listeners_);
229+
catch err
230+
fprintf(2, '[FastSenseCompanion] Listeners delete failed: %s\n', err.message);
204231
end
205-
% Release orchestrator-level listeners
206-
delete(obj.Listeners_);
207232
obj.Listeners_ = {};
208-
% No companion-owned timers in Phase 1018 — pattern established for Phases 1019+:
209-
% stop(t); delete(t); (always in this order)
210-
% Close the uifigure
211-
delete(obj.hFig_);
233+
% Always delete the uifigure last and unconditionally — this is
234+
% what makes the X click actually close the window.
235+
try
236+
delete(obj.hFig_);
237+
catch err
238+
fprintf(2, '[FastSenseCompanion] hFig delete failed: %s\n', err.message);
239+
end
212240
obj.hFig_ = [];
213241
obj.IsOpen = false;
242+
fprintf('[FastSenseCompanion] close() complete.\n');
214243
end
215244

216245
function delete(obj)

0 commit comments

Comments
 (0)