1
1
use std:: f64:: consts:: PI ;
2
2
3
+ use crate :: avm2:: error:: argument_error;
3
4
use crate :: avm2:: globals:: slots:: flash_geom_perspective_projection as pp_slots;
4
5
use crate :: avm2:: { Activation , Error , Object , TObject , Value } ;
5
6
use crate :: display_object:: TDisplayObject ;
@@ -35,9 +36,10 @@ pub fn get_focal_length<'gc>(
35
36
) ;
36
37
37
38
let this = this. as_object ( ) . unwrap ( ) ;
38
- let width = get_width ( activation, this) ;
39
39
40
40
let fov = this. get_slot ( pp_slots:: FOV ) . coerce_to_number ( activation) ?;
41
+
42
+ let width = get_width ( activation, this) ;
41
43
let focal_length = ( width / 2.0 ) / f64:: tan ( fov / 2.0 * DEG2RAD ) ;
42
44
43
45
Ok ( focal_length. into ( ) )
@@ -55,9 +57,18 @@ pub fn set_focal_length<'gc>(
55
57
"focalLength"
56
58
) ;
57
59
let this = this. as_object ( ) . unwrap ( ) ;
58
- let width = get_width ( activation, this) ;
59
60
60
61
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) ;
61
72
let fov = f64:: atan ( ( width / 2.0 ) / focal_length) / DEG2RAD * 2.0 ;
62
73
63
74
this. set_slot ( pp_slots:: FOV , fov. into ( ) , activation) ?;
0 commit comments