ruffle-rs / ruffle

A Flash Player emulator written in Rust
https://ruffle.rs
Other
15.59k stars 809 forks source link

Add a memory limit #8416

Open n0samu opened 1 year ago

n0samu commented 1 year ago

Describe the feature Attempting to use too much memory can cause system instability, crashes and other extreme unpleasantness, especially in the desktop app. Right now Ruffle has nothing in place to mitigate these problems. Ruffle should have some configurable memory usage limit, and automatically terminate if it exceeds the limit.

Here is an example SWF that uses extremely excessive memory and causes my computer to crash: homesheephome2.zip

ActionWavele commented 1 year ago

FFDEC sets it own memory limit in the .bat file Maybe Ruffle can do the same thing

n0samu commented 1 year ago

That actually gave me an idea. I've created a .bat file that runs Ruffle and automatically terminates it if it uses more than 4GB of memory. Here's the code:

@ECHO off
SET RUST_LOG=warn,ruffle_core=debug,avm_trace=trace
START ruffle-win64\ruffle.exe %*
:MemCheck
taskkill /f /fi "memusage gt 4000000" /im ruffle.exe > NUL
timeout 1 > NUL
GOTO MemCheck

As a bonus, the command window also shows the Ruffle warnings/errors and the trace statements from the SWF.

n0samu commented 1 year ago

As for the original enhancement request, maybe the simple-process-stats crate could be used for this? https://crates.io/crates/simple-process-stats

n0samu commented 1 year ago

Stunt Pilot 2 has a similar memory issue.