@@ -90,6 +90,12 @@ struct Dimensions {
9090 height : i32 ,
9191}
9292
93+ #[ inline]
94+ fn non_zero_size ( value : i32 ) -> NonZeroU32 {
95+ let clamped = value. max ( 1 ) as u32 ;
96+ NonZeroU32 :: new ( clamped) . expect ( "clamped dimension must be non-zero" )
97+ }
98+
9399#[ derive( Default ) ]
94100pub ( crate ) struct GLContextInner {
95101 surface : Option < SurfaceHelper > ,
@@ -366,8 +372,8 @@ impl GLContext {
366372 glutin:: surface:: SurfaceAttributesBuilder :: < WindowSurface > :: new ( )
367373 . build (
368374 window,
369- NonZeroU32 :: try_from ( width as u32 ) . unwrap ( ) ,
370- NonZeroU32 :: try_from ( height as u32 ) . unwrap ( ) ,
375+ non_zero_size ( width) ,
376+ non_zero_size ( height) ,
371377 ) ;
372378
373379 let surface = display
@@ -542,8 +548,8 @@ impl GLContext {
542548 glutin:: surface:: SurfaceAttributesBuilder :: < WindowSurface > :: new ( )
543549 . build (
544550 window,
545- NonZeroU32 :: try_from ( width as u32 ) . unwrap ( ) ,
546- NonZeroU32 :: try_from ( height as u32 ) . unwrap ( ) ,
551+ non_zero_size ( width) ,
552+ non_zero_size ( height) ,
547553 ) ;
548554
549555 let surface = display
@@ -730,8 +736,8 @@ impl GLContext {
730736 glutin:: surface:: SurfaceAttributesBuilder :: < WindowSurface > :: new ( )
731737 . build (
732738 window,
733- NonZeroU32 :: try_from ( width as u32 ) . unwrap ( ) ,
734- NonZeroU32 :: try_from ( height as u32 ) . unwrap ( ) ,
739+ non_zero_size ( width) ,
740+ non_zero_size ( height) ,
735741 ) ;
736742
737743 let surface = display
@@ -790,8 +796,8 @@ impl GLContext {
790796 let cfg = cfg
791797 . with_surface_type ( ConfigSurfaceTypes :: PBUFFER )
792798 . with_pbuffer_sizes (
793- ( width as u32 ) . try_into ( ) . unwrap ( ) ,
794- ( height as u32 ) . try_into ( ) . unwrap ( ) ,
799+ non_zero_size ( width) ,
800+ non_zero_size ( height) ,
795801 )
796802 . build ( ) ;
797803
@@ -829,8 +835,8 @@ impl GLContext {
829835
830836 let surface_attr =
831837 glutin:: surface:: SurfaceAttributesBuilder :: < PbufferSurface > :: new ( ) . build (
832- NonZeroU32 :: try_from ( width as u32 ) . unwrap ( ) ,
833- NonZeroU32 :: try_from ( height as u32 ) . unwrap ( ) ,
838+ non_zero_size ( width) ,
839+ non_zero_size ( height) ,
834840 ) ;
835841
836842 let surface = display
@@ -871,8 +877,8 @@ impl GLContext {
871877 let cfg = cfg
872878 . with_surface_type ( ConfigSurfaceTypes :: PBUFFER )
873879 . with_pbuffer_sizes (
874- ( width as u32 ) . try_into ( ) . unwrap ( ) ,
875- ( height as u32 ) . try_into ( ) . unwrap ( ) ,
880+ non_zero_size ( width) ,
881+ non_zero_size ( height) ,
876882 )
877883 . build ( ) ;
878884
@@ -946,8 +952,8 @@ impl GLContext {
946952 let cfg = cfg
947953 . with_surface_type ( ConfigSurfaceTypes :: PBUFFER )
948954 . with_pbuffer_sizes (
949- ( width as u32 ) . try_into ( ) . unwrap ( ) ,
950- ( height as u32 ) . try_into ( ) . unwrap ( ) ,
955+ non_zero_size ( width) ,
956+ non_zero_size ( height) ,
951957 )
952958 . build ( ) ;
953959
@@ -988,8 +994,8 @@ impl GLContext {
988994 let surface_attr =
989995 glutin:: surface:: SurfaceAttributesBuilder :: < PbufferSurface > :: new ( )
990996 . build (
991- NonZeroU32 :: try_from ( width as u32 ) . unwrap ( ) ,
992- NonZeroU32 :: try_from ( height as u32 ) . unwrap ( ) ,
997+ non_zero_size ( width) ,
998+ non_zero_size ( height) ,
993999 ) ;
9941000
9951001 let surface = display
0 commit comments