File tree 2 files changed +24
-13
lines changed 2 files changed +24
-13
lines changed Original file line number Diff line number Diff line change @@ -3606,10 +3606,15 @@ impl<'gc, 'a> MovieClipShared<'gc> {
3606
3606
num_frames,
3607
3607
) ;
3608
3608
3609
- self . library_mut ( context)
3610
- . register_character ( id, Character :: MovieClip ( movie_clip) ) ;
3611
-
3612
- self . preload_progress . cur_preload_symbol . set ( Some ( id) ) ;
3609
+ if self . library_mut ( context)
3610
+ . register_character ( id, Character :: MovieClip ( movie_clip) )
3611
+ {
3612
+ self . preload_progress . cur_preload_symbol . set ( Some ( id) ) ;
3613
+ } else {
3614
+ // This character was already defined, so we can skip preloading it, as the
3615
+ // character ID refers to the pre-existing character, and not this one.
3616
+ return Ok ( ControlFlow :: Exit ) ;
3617
+ }
3613
3618
3614
3619
let should_exit = chunk_limit. did_ops_breach_limit ( context, 4 ) ;
3615
3620
if should_exit {
Original file line number Diff line number Diff line change @@ -142,16 +142,22 @@ impl<'gc> MovieLibrary<'gc> {
142
142
}
143
143
}
144
144
145
- pub fn register_character ( & mut self , id : CharacterId , character : Character < ' gc > ) {
146
- // TODO(Herschel): What is the behavior if id already exists?
147
- if !self . contains_character ( id) {
148
- if let Character :: Font ( font) = character {
149
- self . fonts . register ( font) ;
145
+ /// Registers a character; returns `true` if successful, or `false` if a character with
146
+ /// the given ID already exists.
147
+ pub fn register_character ( & mut self , id : CharacterId , character : Character < ' gc > ) -> bool {
148
+ use std:: collections:: hash_map:: Entry ;
149
+ match self . characters . entry ( id) {
150
+ Entry :: Vacant ( e) => {
151
+ if let Character :: Font ( font) = character {
152
+ self . fonts . register ( font) ;
153
+ }
154
+ e. insert ( character) ;
155
+ true
156
+ }
157
+ Entry :: Occupied ( _) => {
158
+ tracing:: error!( "Character ID collision: Tried to register ID {} twice" , id) ;
159
+ false
150
160
}
151
-
152
- self . characters . insert ( id, character) ;
153
- } else {
154
- tracing:: error!( "Character ID collision: Tried to register ID {} twice" , id) ;
155
161
}
156
162
}
157
163
You can’t perform that action at this time.
0 commit comments