File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed
Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -1084,10 +1084,23 @@ pub trait RaylibTexture2D: AsRef<ffi::Texture2D> + AsMut<ffi::Texture2D> {
10841084 rec : impl Into < ffi:: Rectangle > ,
10851085 pixels : & [ u8 ] ,
10861086 ) -> Result < ( ) , Error > {
1087+ let rec = rec. into ( ) ;
1088+
1089+ if ( rec. x < 0.0 ) || ( rec. y < 0.0 ) || ( ( rec. x as i32 + rec. width as i32 ) > ( self . as_ref ( ) . width ) ) || ( ( rec. y as i32 + rec. height as i32 ) > ( self . as_ref ( ) . height ) ) {
1090+ return Err ( error ! (
1091+ "update_texture: Destination rectangle cannot exceed texture bounds."
1092+ ) ) ;
1093+ }
1094+ if ( rec. width < 0.0 ) || ( rec. height < 0.0 ) {
1095+ return Err ( error ! (
1096+ "update_texture: Destination rectangle cannot have negative extents."
1097+ ) ) ;
1098+ }
1099+
10871100 let expected_len = unsafe {
10881101 get_pixel_data_size (
1089- self . as_ref ( ) . width ,
1090- self . as_ref ( ) . height ,
1102+ rec . width as i32 ,
1103+ rec . height as i32 ,
10911104 std:: mem:: transmute :: < i32 , ffi:: PixelFormat > ( self . as_ref ( ) . format ) ,
10921105 ) as usize
10931106 } ;
@@ -1101,7 +1114,7 @@ pub trait RaylibTexture2D: AsRef<ffi::Texture2D> + AsMut<ffi::Texture2D> {
11011114 unsafe {
11021115 ffi:: UpdateTextureRec (
11031116 * self . as_ref ( ) ,
1104- rec. into ( ) ,
1117+ rec,
11051118 pixels. as_ptr ( ) as * const std:: os:: raw:: c_void ,
11061119 )
11071120 }
You can’t perform that action at this time.
0 commit comments