diff --git a/core/src/avm2/globals/flash/display/display_object.rs b/core/src/avm2/globals/flash/display/display_object.rs index b3798557d..948f65986 100644 --- a/core/src/avm2/globals/flash/display/display_object.rs +++ b/core/src/avm2/globals/flash/display/display_object.rs @@ -960,7 +960,7 @@ pub fn get_bounds<'gc>( .and_then(|o| o.as_display_object()) .unwrap_or(dobj); let bounds = dobj.bounds(); - let out_bounds = if DisplayObject::ptr_eq(dobj, target) { + let mut out_bounds = if DisplayObject::ptr_eq(dobj, target) { // Getting the clips bounds in its own coordinate space; no AABB transform needed. bounds } else { @@ -972,6 +972,9 @@ pub fn get_bounds<'gc>( let to_target_matrix = target.global_to_local_matrix().unwrap_or_default(); to_target_matrix * to_global_matrix * bounds }; + if !out_bounds.is_valid() { + out_bounds = Rectangle::ZERO; + } return Ok(new_rectangle(activation, out_bounds)?.into()); } diff --git a/swf/src/types/rectangle.rs b/swf/src/types/rectangle.rs index afcc33d32..edd5b11db 100644 --- a/swf/src/types/rectangle.rs +++ b/swf/src/types/rectangle.rs @@ -65,6 +65,13 @@ impl Rectangle { y_max: T::INVALID, }; + pub const ZERO: Self = Self { + x_min: T::ZERO, + x_max: T::ZERO, + y_min: T::ZERO, + y_max: T::ZERO, + }; + #[inline] #[must_use] pub fn is_valid(&self) -> bool { diff --git a/tests/tests/swfs/avm2/empty_bounds/Test.as b/tests/tests/swfs/avm2/empty_bounds/Test.as new file mode 100755 index 000000000..87404f3ab --- /dev/null +++ b/tests/tests/swfs/avm2/empty_bounds/Test.as @@ -0,0 +1,14 @@ +package { + + import flash.display.MovieClip; + + + public class Test extends MovieClip { + + + public function Test() { + trace("Bounds: " + this.getBounds(this)); + } + } + +} diff --git a/tests/tests/swfs/avm2/empty_bounds/output.txt b/tests/tests/swfs/avm2/empty_bounds/output.txt new file mode 100644 index 000000000..9a591de18 --- /dev/null +++ b/tests/tests/swfs/avm2/empty_bounds/output.txt @@ -0,0 +1 @@ +Bounds: (x=0, y=0, w=0, h=0) diff --git a/tests/tests/swfs/avm2/empty_bounds/test.fla b/tests/tests/swfs/avm2/empty_bounds/test.fla new file mode 100755 index 000000000..995d5e872 Binary files /dev/null and b/tests/tests/swfs/avm2/empty_bounds/test.fla differ diff --git a/tests/tests/swfs/avm2/empty_bounds/test.swf b/tests/tests/swfs/avm2/empty_bounds/test.swf new file mode 100755 index 000000000..5fdda0a36 Binary files /dev/null and b/tests/tests/swfs/avm2/empty_bounds/test.swf differ diff --git a/tests/tests/swfs/avm2/empty_bounds/test.toml b/tests/tests/swfs/avm2/empty_bounds/test.toml new file mode 100644 index 000000000..67f15e863 --- /dev/null +++ b/tests/tests/swfs/avm2/empty_bounds/test.toml @@ -0,0 +1 @@ +num_ticks = 1 \ No newline at end of file