avm2: Convert invalid rectangle to zero rectangle in getBounds

This commit is contained in:
Aaron Hill 2024-01-28 15:36:30 -05:00
parent f31d9bc491
commit 1cf669c75e
7 changed files with 27 additions and 1 deletions

View File

@ -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());
}

View File

@ -65,6 +65,13 @@ impl<T: Coordinate> Rectangle<T> {
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 {

View File

@ -0,0 +1,14 @@
package {
import flash.display.MovieClip;
public class Test extends MovieClip {
public function Test() {
trace("Bounds: " + this.getBounds(this));
}
}
}

View File

@ -0,0 +1 @@
Bounds: (x=0, y=0, w=0, h=0)

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1 @@
num_ticks = 1