Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
633 views
in Technique[技术] by (71.8m points)

javascript - How do I clean up and unload a Unity WebGL canvas when changing page

I've got a problem on my web application when I am changing the current page after downloading and running a Unity WebGL game.

In fact, I know for sure that the game is running because I continuously hear the sounds when my player is dying.

Is there a way to delete all of the context when changing a web page? Could this be a kind of memory leak?

Edit 1: My web application is done with AngularJS / Material

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The solution is simple: load the WebGL unity in an iframe, this sandboxes the application.

When you're done with the unity app just remove the node of the iframe like:

var iframe=...;
iframe.parentNode.removeChild(iframe);

And it and all of it's resources should be instantly unloaded.

You can't communicate with the Unity player directly when you're in an iframe but you still can pass messages to and from it with postMessage.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...