From fd702dabcc74f06e539b9cf5b8b2c6da84d8f2ea Mon Sep 17 00:00:00 2001 From: Nathan Adams Date: Fri, 31 Mar 2023 15:49:13 +0200 Subject: [PATCH] core: Remove disposed checks from operations, it's responsibility of avm1 and avm2 to handle it their own way --- core/src/avm1/globals/bitmap_data.rs | 42 ++++++++++--------- .../avm2/globals/flash/display/bitmap_data.rs | 5 +++ core/src/bitmap/operations.rs | 18 ++------ 3 files changed, 31 insertions(+), 34 deletions(-) diff --git a/core/src/avm1/globals/bitmap_data.rs b/core/src/avm1/globals/bitmap_data.rs index 76c016bbd..624dcf6b5 100644 --- a/core/src/avm1/globals/bitmap_data.rs +++ b/core/src/avm1/globals/bitmap_data.rs @@ -335,29 +335,31 @@ pub fn fill_rect<'gc>( .coerce_to_object(activation); if let Some(bitmap_data) = this.as_bitmap_data_object() { - if let Some(color_val) = args.get(1) { - let color = color_val.coerce_to_i32(activation)?; + if !bitmap_data.disposed() { + if let Some(color_val) = args.get(1) { + let color = color_val.coerce_to_i32(activation)?; - let x = rectangle.get("x", activation)?.coerce_to_i32(activation)?; - let y = rectangle.get("y", activation)?.coerce_to_i32(activation)?; - let width = rectangle - .get("width", activation)? - .coerce_to_i32(activation)?; - let height = rectangle - .get("height", activation)? - .coerce_to_i32(activation)?; + let x = rectangle.get("x", activation)?.coerce_to_i32(activation)?; + let y = rectangle.get("y", activation)?.coerce_to_i32(activation)?; + let width = rectangle + .get("width", activation)? + .coerce_to_i32(activation)?; + let height = rectangle + .get("height", activation)? + .coerce_to_i32(activation)?; - operations::fill_rect( - &mut activation.context, - bitmap_data.bitmap_data_wrapper(), - x, - y, - width, - height, - color, - ); + operations::fill_rect( + &mut activation.context, + bitmap_data.bitmap_data_wrapper(), + x, + y, + width, + height, + color, + ); + } + return Ok(Value::Undefined); } - return Ok(Value::Undefined); } Ok((-1).into()) diff --git a/core/src/avm2/globals/flash/display/bitmap_data.rs b/core/src/avm2/globals/flash/display/bitmap_data.rs index 3717dd799..4dda190b6 100644 --- a/core/src/avm2/globals/flash/display/bitmap_data.rs +++ b/core/src/avm2/globals/flash/display/bitmap_data.rs @@ -352,6 +352,7 @@ pub fn get_pixel32<'gc>( args: &[Value<'gc>], ) -> Result, Error<'gc>> { if let Some(bitmap_data) = this.and_then(|t| t.as_bitmap_data_wrapper()) { + bitmap_data.check_valid(activation)?; let x = args.get_u32(activation, 0)?; let y = args.get_u32(activation, 1)?; let pixel = operations::get_pixel32(bitmap_data, x, y); @@ -384,6 +385,8 @@ pub fn set_pixel32<'gc>( args: &[Value<'gc>], ) -> Result, Error<'gc>> { if let Some(bitmap_data) = this.and_then(|t| t.as_bitmap_data_wrapper()) { + bitmap_data.check_valid(activation)?; + let x = args.get_u32(activation, 0)?; let y = args.get_u32(activation, 1)?; let color = args.get_i32(activation, 2)?; @@ -541,6 +544,7 @@ pub fn noise<'gc>( let gray_scale = args.get_bool(4); if let Some(bitmap_data) = this.and_then(|t| t.as_bitmap_data_wrapper()) { + bitmap_data.check_valid(activation)?; let random_seed = args.get_i32(activation, 0)?; operations::noise( &mut activation.context, @@ -950,6 +954,7 @@ pub fn fill_rect<'gc>( let color = args.get_i32(activation, 1)?; if let Some(bitmap_data) = this.and_then(|this| this.as_bitmap_data_wrapper()) { + bitmap_data.check_valid(activation)?; let x = rectangle .get_public_property("x", activation)? .coerce_to_i32(activation)?; diff --git a/core/src/bitmap/operations.rs b/core/src/bitmap/operations.rs index f5838e5c3..1c3b6e87c 100644 --- a/core/src/bitmap/operations.rs +++ b/core/src/bitmap/operations.rs @@ -31,10 +31,6 @@ pub fn fill_rect<'gc>( height: i32, color: i32, ) { - if target.disposed() { - return; - } - let mut rect = PixelRegion::for_region_i32(x, y, width, height); rect.clamp(target.width(), target.height()); @@ -67,7 +63,7 @@ pub fn set_pixel32<'gc>( y: u32, color: i32, ) { - if target.disposed() || x >= target.width() || y >= target.height() { + if x >= target.width() || y >= target.height() { return; } let target = target.sync(); @@ -82,7 +78,7 @@ pub fn set_pixel32<'gc>( } pub fn get_pixel32(target: BitmapDataWrapper, x: u32, y: u32) -> i32 { - if target.disposed() || x >= target.width() || y >= target.height() { + if x >= target.width() || y >= target.height() { return 0; } let read = target.read_area(PixelRegion::for_pixel(x, y)); @@ -113,7 +109,7 @@ pub fn set_pixel<'gc>( } pub fn get_pixel(target: BitmapDataWrapper, x: u32, y: u32) -> i32 { - if target.disposed() || x >= target.width() || y >= target.height() { + if x >= target.width() || y >= target.height() { return 0; } let read = target.read_area(PixelRegion::for_pixel(x, y)); @@ -130,7 +126,7 @@ pub fn flood_fill<'gc>( y: u32, color: i32, ) { - if target.disposed() || x >= target.width() || y >= target.height() { + if x >= target.width() || y >= target.height() { return; } let target = target.sync(); @@ -174,9 +170,6 @@ pub fn noise<'gc>( channel_options: ChannelOptions, gray_scale: bool, ) { - if target.disposed() { - return; - } let (target, _) = target.overwrite_cpu_pixels_from_gpu(context); let mut write = target.write(context.gc_context); @@ -247,9 +240,6 @@ pub fn perlin_noise<'gc>( grayscale: bool, offsets: Vec<(f64, f64)>, // must contain `num_octaves` values ) { - if target.disposed() { - return; - } let (target, _) = target.overwrite_cpu_pixels_from_gpu(context); let mut write = target.write(context.gc_context);