@@ -337,7 +337,7 @@ impl BufferInterface for BufferImpl<'_> {
337337 . expect ( "Must set size of surface before calling `present_with_damage()`" ) ;
338338
339339 let union_damage = if let Some ( rect) = util:: union_damage ( damage) {
340- rect
340+ util :: clamp_rect ( rect, buffer_width , buffer_height )
341341 } else {
342342 return Ok ( ( ) ) ;
343343 } ;
@@ -359,9 +359,7 @@ impl BufferInterface for BufferImpl<'_> {
359359
360360 debug_assert_eq ! (
361361 bitmap. len( ) ,
362- union_damage. width. get( ) . min( buffer_width. get( ) ) as usize
363- * union_damage. height. get( ) . min( buffer_height. get( ) ) as usize
364- * 4
362+ union_damage. width. get( ) as usize * union_damage. height. get( ) as usize * 4
365363 ) ;
366364
367365 #[ cfg( target_feature = "atomics" ) ]
@@ -384,29 +382,31 @@ impl BufferInterface for BufferImpl<'_> {
384382 let array = Uint8Array :: new_with_length ( bitmap. len ( ) as u32 ) ;
385383 array. copy_from ( & bitmap) ;
386384 let array = Uint8ClampedArray :: new ( & array) ;
387- ImageDataExt :: new ( array, union_damage. width . get ( ) . min ( buffer_width . get ( ) ) )
385+ ImageDataExt :: new ( array, union_damage. width . get ( ) )
388386 . map ( JsValue :: from)
389387 . map ( ImageData :: unchecked_from_js)
390388 } ;
391389 #[ cfg( not( target_feature = "atomics" ) ) ]
392390 let result = ImageData :: new_with_u8_clamped_array (
393391 wasm_bindgen:: Clamped ( & bitmap) ,
394- union_damage. width . get ( ) . min ( buffer_width . get ( ) ) ,
392+ union_damage. width . get ( ) ,
395393 ) ;
396394 // This should only throw an error if the buffer we pass's size is incorrect.
397395 let image_data = result. unwrap ( ) ;
398396
399397 for rect in damage {
398+ let rect = util:: clamp_rect ( * rect, buffer_width, buffer_height) ;
399+
400400 // This can only throw an error if `data` is detached, which is impossible.
401401 self . canvas
402402 . put_image_data (
403403 & image_data,
404- union_damage. x . min ( buffer_width . get ( ) ) . into ( ) ,
405- union_damage. y . min ( buffer_height . get ( ) ) . into ( ) ,
404+ union_damage. x . into ( ) ,
405+ union_damage. y . into ( ) ,
406406 ( rect. x - union_damage. x ) . into ( ) ,
407407 ( rect. y - union_damage. y ) . into ( ) ,
408- rect. width . get ( ) . min ( buffer_width . get ( ) ) . into ( ) ,
409- rect. height . get ( ) . min ( buffer_height . get ( ) ) . into ( ) ,
408+ rect. width . get ( ) . into ( ) ,
409+ rect. height . get ( ) . into ( ) ,
410410 )
411411 . unwrap ( ) ;
412412 }
0 commit comments