@@ -479,68 +479,55 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
479
479
display_handle : raw_window_handle:: RawDisplayHandle ,
480
480
window_handle : raw_window_handle:: RawWindowHandle ,
481
481
id_in : Input < G , SurfaceId > ,
482
- ) -> SurfaceId {
482
+ ) -> Result < SurfaceId , hal :: InstanceError > {
483
483
profiling:: scope!( "Instance::create_surface" ) ;
484
484
485
485
fn init < A : HalApi > (
486
- any_surface : & mut Option < AnySurface > ,
487
486
inst : & Option < A :: Instance > ,
488
487
display_handle : raw_window_handle:: RawDisplayHandle ,
489
488
window_handle : raw_window_handle:: RawWindowHandle ,
490
- ) {
491
- if any_surface. is_none ( ) {
492
- if let Some ( surface) = inst. as_ref ( ) . and_then ( |inst| unsafe {
493
- match inst. create_surface ( display_handle, window_handle) {
494
- Ok ( raw) => Some ( HalSurface :: < A > { raw : Arc :: new ( raw) } ) ,
495
- Err ( e) => {
496
- log:: warn!( "Error: {:?}" , e) ;
497
- None
498
- }
499
- }
500
- } ) {
501
- * any_surface = Some ( AnySurface :: new ( surface) ) ;
489
+ ) -> Option < Result < AnySurface , hal:: InstanceError > > {
490
+ inst. as_ref ( ) . map ( |inst| unsafe {
491
+ match inst. create_surface ( display_handle, window_handle) {
492
+ Ok ( raw) => Ok ( AnySurface :: new ( HalSurface :: < A > { raw : Arc :: new ( raw) } ) ) ,
493
+ Err ( e) => Err ( e) ,
502
494
}
503
- }
495
+ } )
504
496
}
505
497
506
- let mut hal_surface = None ;
498
+ let mut hal_surface: Option < Result < AnySurface , hal:: InstanceError > > = None ;
499
+
507
500
#[ cfg( all( feature = "vulkan" , not( target_arch = "wasm32" ) ) ) ]
508
- init :: < hal:: api:: Vulkan > (
509
- & mut hal_surface,
510
- & self . instance . vulkan ,
511
- display_handle,
512
- window_handle,
513
- ) ;
501
+ if hal_surface. is_none ( ) {
502
+ hal_surface =
503
+ init :: < hal:: api:: Vulkan > ( & self . instance . vulkan , display_handle, window_handle) ;
504
+ }
514
505
#[ cfg( all( feature = "metal" , any( target_os = "macos" , target_os = "ios" ) ) ) ]
515
- init :: < hal:: api:: Metal > (
516
- & mut hal_surface,
517
- & self . instance . metal ,
518
- display_handle,
519
- window_handle,
520
- ) ;
506
+ if hal_surface. is_none ( ) {
507
+ hal_surface =
508
+ init :: < hal:: api:: Metal > ( & self . instance . metal , display_handle, window_handle) ;
509
+ }
521
510
#[ cfg( all( feature = "dx12" , windows) ) ]
522
- init :: < hal:: api:: Dx12 > (
523
- & mut hal_surface,
524
- & self . instance . dx12 ,
525
- display_handle,
526
- window_handle,
527
- ) ;
511
+ if hal_surface. is_none ( ) {
512
+ hal_surface =
513
+ init :: < hal:: api:: Dx12 > ( & self . instance . dx12 , display_handle, window_handle) ;
514
+ }
528
515
#[ cfg( feature = "gles" ) ]
529
- init :: < hal :: api :: Gles > (
530
- & mut hal_surface ,
531
- & self . instance . gl ,
532
- display_handle ,
533
- window_handle ,
534
- ) ;
516
+ if hal_surface . is_none ( ) {
517
+ hal_surface = init :: < hal :: api :: Gles > ( & self . instance . gl , display_handle , window_handle ) ;
518
+ }
519
+
520
+ // This is only None if there's no instance at all.
521
+ let hal_surface = hal_surface . unwrap ( ) ? ;
535
522
536
523
let surface = Surface {
537
524
presentation : Mutex :: new ( None ) ,
538
525
info : ResourceInfo :: new ( "<Surface>" ) ,
539
- raw : hal_surface. unwrap ( ) ,
526
+ raw : hal_surface,
540
527
} ;
541
528
542
529
let ( id, _) = self . surfaces . prepare :: < G > ( id_in) . assign ( surface) ;
543
- id
530
+ Ok ( id )
544
531
}
545
532
546
533
/// # Safety
0 commit comments