Open road0001 opened 12 months ago
Hi, please try removing the polyfillWindow();
call here: https://github.com/ruffle-rs/ruffle/blob/master/web/packages/core/src/js-polyfills.ts#L164
Then recompile Ruffle and let us know if the problem is fixed. Or share a link to the page affected by this issue so we can test it ourselves. Thanks!
Hi, please try removing the
polyfillWindow();
call here: https://github.com/ruffle-rs/ruffle/blob/master/web/packages/core/src/js-polyfills.ts#L164 Then recompile Ruffle and let us know if the problem is fixed. Or share a link to the page affected by this issue so we can test it ourselves. Thanks!
I uploaded a demo to present this bug. In this page, there are two buttons. If you click Window button first, it will alert your cilck count. If you click SWF button first, the swf will be loaded and play, but now click Window button will error. swftest.zip
Thanks for the sample. Ruffle's Window polyfill was introduced in #2156, and according to Toad06's comments, Ruffle would crash during initialization if we did not restore the value of Window
to native window constructor. I just tested it myself and confirmed this. So if possible, you need to modify your content to use a different name for its Window function, for example "MyWindow". Otherwise you will need to isolate Ruffle and your HTML5 game in separate frames to prevent this conflict from occurring.
Thanks for the sample. Ruffle's Window polyfill was introduced in #2156, and according to Toad06's comments, Ruffle would crash during initialization if we did not restore the value of
Window
to native window constructor. I just tested it myself and confirmed this. So if possible, you need to modify your content to use a different name for its Window function, for example "MyWindow". Otherwise you will need to isolate Ruffle and your HTML5 game in separate frames to prevent this conflict from occurring.
Thank you for giving the solution! But to use a different name for Window function is a hard working, not only the game scripts, but a lot of 3rd plugins writting for this game engine. The Window function with its prototypes in game is for many of important feature, it’s hard to imagine how difficult it would be to modify them.
I tried to modify Ruffle, re-name Window to WindowRuffle in ruffle.js and the two core.xxx.js, like this:
modify in ruffle.js:
"function"==typeof Window&&l(Window) >>> "function"==typeof WindowRuffle&&l(WindowRuffle) window.Window=window.constructor >>> window.WindowRuffle=window.constructor e.Window="window" >>> e.WindowRuffle="window" wmode:Tn.Window >>> wmode:Tn.WindowRuffle
modify in two core.xxx.js
n=f(e)instanceof Window >>> n=f(e)instanceof WindowRuffle n=e instanceof Window >>> n=e instanceof WindowRuffle
After I modified Ruffle's scripts, my flash works good in game, and never cause game errors. But I don't know what will happen if I modify it like this, maybe everything is ok, maybe a lot of errors in other environment.
That sounds like a fine solution - I'm glad to hear that you got it working. I believe the code you modified is generated by wasm-bindgen, so a proper fix along these lines would need to be done by them. Perhaps we should make an issue for it as Mike suggested in https://github.com/ruffle-rs/ruffle/issues/2156#issuecomment-752297118.
Describe the bug
I use ruffle in RPGMaker MV, it a html5 game engine. My swf load success and playing good, but the game throws error. After analyzing the error log, I found that Window function in the game script was overwritten to a native code, therefore the game error. The original Window function like this:
If I load swf, the function Window will be overwritten by Ruffle, it becomes native code.
Expected behavior
Ruffle use independent function name substitute Window, like "WindowRuffle", avoid duplicate name conflicts. I try to change ruffle's "Window" to "WindowRuffle", it works good and game never throw errors. But I don't know if there are any potential problems after this.
Content Location
-
Affected platform
Self-hosted version
Operating system
Windows 10
Browser
NW.JS 0.72.0 Chromium 109
Additional information
No response