File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -105,9 +105,15 @@ impl EventLoop {
105105 pub fn create_window ( init : WindowInitializer ) -> PlatformResult < Self > {
106106 let parent_id = init. settings . parent . as_ref ( ) . map ( |p| p. inner . window_id ) ;
107107 let host = HostHandle :: new ( init. host ) ;
108- // TODO: check deinit runs on initialization error
108+
109109 let shared = WindowShared :: create ( init. settings , Rc :: clone ( & host) ) ?;
110- let handler = init. builder . build ( WindowContext :: new ( Rc :: clone ( & shared) ) ) ?;
110+ let handler = match init. builder . build ( WindowContext :: new ( Rc :: clone ( & shared) ) ) {
111+ Ok ( handler) => handler,
112+ Err ( e) => {
113+ shared. deinit_all_host ( ) ;
114+ return Err ( e) ;
115+ }
116+ } ;
111117
112118 let this = Self {
113119 handler : Handler :: new ( handler) ,
@@ -333,8 +339,7 @@ impl Drop for EventLoop {
333339 self . handler . on_event ( Event :: Window ( WindowEvent :: WillClose ) ) ;
334340
335341 // Deinit timers & FD watchers
336- self . shared . timer_manager . destroy_all ( & self . host ) ;
337- self . shared . present_state . destroy_redraw_timers ( & self . host ) ;
342+ self . shared . deinit_all_host ( ) ;
338343
339344 if self . fd_registered . get ( ) {
340345 let _ = self . host . unregister_fd ( self . shared . connection . conn . as_raw_fd ( ) ) ;
Original file line number Diff line number Diff line change @@ -148,4 +148,10 @@ impl WindowShared {
148148 pub fn raw_id ( & self ) -> xproto:: Window {
149149 self . xcb_window . id ( ) . get ( )
150150 }
151+
152+ // Deinit host-registered timers and FD watchers
153+ pub fn deinit_all_host ( & self ) {
154+ self . timer_manager . destroy_all ( & self . host ) ;
155+ self . present_state . destroy_redraw_timers ( & self . host ) ;
156+ }
151157}
You can’t perform that action at this time.
0 commit comments