From 78c519cce0ec09a067a10f91e57280ef43168300 Mon Sep 17 00:00:00 2001 From: David Wendt Date: Wed, 3 Mar 2021 21:11:23 -0500 Subject: [PATCH] avm2: Don't except when creating a dynamic TextField. --- core/src/avm2/globals/flash/text/textfield.rs | 16 ++++++---------- core/src/library.rs | 9 +++++++++ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/core/src/avm2/globals/flash/text/textfield.rs b/core/src/avm2/globals/flash/text/textfield.rs index 0646618dc..d1f9b7408 100644 --- a/core/src/avm2/globals/flash/text/textfield.rs +++ b/core/src/avm2/globals/flash/text/textfield.rs @@ -27,17 +27,13 @@ pub fn instance_init<'gc>( if this.as_display_object().is_none() { let movie = Arc::new(SwfMovie::empty(activation.context.swf.version())); - let new_do = EditText::new( - &mut activation.context, - movie.clone(), - 0.0, - 0.0, - 100.0, - 100.0, - ); + let movie_library = activation + .context + .library + .library_for_movie_mut(movie.clone()); + movie_library.force_avm_type(AvmType::Avm2); - let movie_library = activation.context.library.library_for_movie_mut(movie); - movie_library.check_avm_type(AvmType::Avm2).unwrap(); + let new_do = EditText::new(&mut activation.context, movie, 0.0, 0.0, 100.0, 100.0); this.init_display_object(activation.context.gc_context, new_do.into()); } diff --git a/core/src/library.rs b/core/src/library.rs index ba2c02cfc..a42f9dcac 100644 --- a/core/src/library.rs +++ b/core/src/library.rs @@ -263,6 +263,15 @@ impl<'gc> MovieLibrary<'gc> { self.avm_type } + /// Forcibly set the AVM type of this movie. + /// + /// This is intended for display object types which can be created + /// dynamically but need a placeholder movie. You should *not* attempt to + /// change the AVM type of an actual SWF. + pub fn force_avm_type(&mut self, new_type: AvmType) { + self.avm_type = new_type; + } + pub fn set_avm2_domain(&mut self, avm2_domain: Avm2Domain<'gc>) { self.avm2_domain = Some(avm2_domain); }