Skip to content

Commit ae95842

Browse files
cookie-sadrian17
authored andcommitted
avm2: Validate and throw ArgumentError in PerspectiveProjection setters
1 parent 0210bee commit ae95842

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

core/src/avm2/globals/flash/geom/PerspectiveProjection.as

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ package flash.geom {
2828
// TODO: This setter should update the associated displayObject when there is.
2929
stub_setter("flash.geom.PerspectiveProjection", "fieldOfView");
3030

31+
if (value <= 0 || 180 <= value) {
32+
throw new ArgumentError("Error #2182: Invalid fieldOfView value. The value must be greater than 0 and less than 180.", 2182);
33+
}
34+
3135
this.fov = value;
3236
}
3337

core/src/avm2/globals/flash/geom/perspective_projection.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::f64::consts::PI;
22

3+
use crate::avm2::error::argument_error;
34
use crate::avm2::globals::slots::flash_geom_perspective_projection as pp_slots;
45
use crate::avm2::{Activation, Error, Object, TObject, Value};
56
use crate::display_object::TDisplayObject;
@@ -35,9 +36,10 @@ pub fn get_focal_length<'gc>(
3536
);
3637

3738
let this = this.as_object().unwrap();
38-
let width = get_width(activation, this);
3939

4040
let fov = this.get_slot(pp_slots::FOV).coerce_to_number(activation)?;
41+
42+
let width = get_width(activation, this);
4143
let focal_length = (width / 2.0) / f64::tan(fov / 2.0 * DEG2RAD);
4244

4345
Ok(focal_length.into())
@@ -55,9 +57,18 @@ pub fn set_focal_length<'gc>(
5557
"focalLength"
5658
);
5759
let this = this.as_object().unwrap();
58-
let width = get_width(activation, this);
5960

6061
let focal_length = args.get(0).unwrap().coerce_to_number(activation)?;
62+
63+
if focal_length <= 0.0 {
64+
return Err(Error::AvmError(argument_error(
65+
activation,
66+
&format!("Error #2186: Invalid focalLength {focal_length}."),
67+
2186,
68+
)?));
69+
}
70+
71+
let width = get_width(activation, this);
6172
let fov = f64::atan((width / 2.0) / focal_length) / DEG2RAD * 2.0;
6273

6374
this.set_slot(pp_slots::FOV, fov.into(), activation)?;

0 commit comments

Comments
 (0)