Skip to content

core: Add avm_warning for simulating traced FP warnings #20757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 20, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions core/src/backend/log.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
pub trait LogBackend {
fn avm_trace(&self, message: &str);

fn avm_warning(&self, message: &str);
}

/// Logging backend that just reroutes traces to the log crate
Expand All @@ -15,6 +17,10 @@ impl LogBackend for NullLogBackend {
fn avm_trace(&self, message: &str) {
tracing::info!(target: "avm_trace", "{}", message);
}

fn avm_warning(&self, message: &str) {
tracing::info!(target: "avm_warning", "{}", message);
}
}

impl Default for NullLogBackend {
Expand Down
4 changes: 4 additions & 0 deletions core/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,10 @@ impl<'gc> UpdateContext<'gc> {
pub fn avm_trace(&self, message: &str) {
self.log.avm_trace(&message.replace('\r', "\n"));
}

pub fn avm_warning(&self, message: &str) {
self.log.avm_warning(message);
}
}

/// A queued ActionScript call.
Expand Down
3 changes: 1 addition & 2 deletions core/src/display_object/movie_clip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1267,8 +1267,7 @@ impl<'gc> MovieClip<'gc> {
place_object: &swf::PlaceObject,
) -> Option<DisplayObject<'gc>> {
if self.has_child_at_depth(depth) {
// Flash Player traces
// Warning: Failed to place object at depth X.
context.avm_warning(&format!("Failed to place object at depth {depth}."));
return None;
}

Expand Down
1 change: 1 addition & 0 deletions scanner/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ impl ScanLogBackend {

impl LogBackend for ScanLogBackend {
fn avm_trace(&self, _message: &str) {}
fn avm_warning(&self, _message: &str) {}
}

thread_local! {
Expand Down
7 changes: 7 additions & 0 deletions tests/framework/src/backends/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,11 @@ impl LogBackend for TestLogBackend {
self.trace_output.borrow_mut().push_str(message);
self.trace_output.borrow_mut().push('\n');
}

fn avm_warning(&self, message: &str) {
// Match the format used by Flash Player
self.trace_output.borrow_mut().push_str("Warning: ");
self.trace_output.borrow_mut().push_str(message);
self.trace_output.borrow_mut().push('\n');
}
}
2 changes: 2 additions & 0 deletions tests/tests/swfs/avm1/placeobject_occupied_depth/output.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Warning: Failed to place object at depth 1.
Warning: Failed to place object at depth 1.
Instantiated ID 3
Frame 2
Instantiated ID 4
Expand Down
4 changes: 4 additions & 0 deletions web/src/log_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ impl LogBackend for WebLogBackend {
let _ = function.call1(function, &JsValue::from_str(message));
}
}

fn avm_warning(&self, message: &str) {
tracing::info!(target: "avm_warning", "{}", message);
}
}
Loading