Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/avm2/globals/flash/system/System.as
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package flash.system {
import __ruffle__.stub_method;
import __ruffle__.stub_getter;

public static function gc():void {}
public static native function gc():void;

public static function pauseForGCIfCollectionImminent(imminence:Number = 0.75):void {
stub_method("flash.system.System", "pauseForGCIfCollectionImminent");
Expand Down
10 changes: 10 additions & 0 deletions core/src/avm2/globals/flash/system/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ use crate::avm2::activation::Activation;
use crate::avm2::parameters::ParametersExt;
use crate::avm2::value::Value;

/// Implements `flash.system.System.setClipboard` method
pub fn gc<'gc>(
activation: &mut Activation<'_, 'gc>,
_this: Value<'gc>,
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> {
*activation.context.needs_gc = true;
Ok(Value::Undefined)
}

/// Implements `flash.system.System.setClipboard` method
pub fn set_clipboard<'gc>(
activation: &mut Activation<'_, 'gc>,
Expand Down
3 changes: 3 additions & 0 deletions core/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ pub struct UpdateContext<'gc> {
/// Requests that the player re-renders after this execution (e.g. due to `updateAfterEvent`).
pub needs_render: &'gc mut bool,

// Requests that the gc finishes it's cycle this execution (e.g. due to 'flash.system.System.gc()')
pub needs_gc: &'gc mut bool,

/// The root SWF file.
pub root_swf: &'gc mut Arc<SwfMovie>,

Expand Down
7 changes: 7 additions & 0 deletions core/src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ pub struct Player {

run_state: RunState,
needs_render: bool,
needs_gc: bool,

renderer: Box<dyn RenderBackend>,
audio: Box<dyn AudioBackend>,
Expand Down Expand Up @@ -2290,6 +2291,7 @@ impl Player {
timers,
current_context_menu,
needs_render: &mut this.needs_render,
needs_gc: &mut this.needs_gc,
avm1,
avm2,
external_interface,
Expand Down Expand Up @@ -2382,6 +2384,10 @@ impl Player {

// GC
self.gc_arena.borrow_mut().collect_debt();
if self.needs_gc {
self.gc_arena.borrow_mut().finish_cycle();
}
self.needs_gc = false;

rval
}
Expand Down Expand Up @@ -3038,6 +3044,7 @@ impl PlayerBuilder {
RunState::Suspended
},
needs_render: true,
needs_gc: false,
self_reference: self_ref.clone(),
load_behavior: self.load_behavior,
spoofed_url: self.spoofed_url.clone(),
Expand Down
Loading