From a9e7a05b84470257637c97d65f6562aa832c66ef Mon Sep 17 00:00:00 2001 From: Jason Sams Date: Fri, 25 Sep 2009 14:51:22 -0700 Subject: Improve renderscript context teardown. Track object in the system and then force their cleanup by releasing all user references once destroy context is called. Java layer will no longer send destroy notifications for objects garbage collected once a context is destroyed. --- .../src/com/android/fountain/Fountain.java | 8 ++++++- .../src/com/android/fountain/FountainView.java | 26 ++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) (limited to 'libs/rs/java') diff --git a/libs/rs/java/Fountain/src/com/android/fountain/Fountain.java b/libs/rs/java/Fountain/src/com/android/fountain/Fountain.java index 58c78fa..9ae3e67 100644 --- a/libs/rs/java/Fountain/src/com/android/fountain/Fountain.java +++ b/libs/rs/java/Fountain/src/com/android/fountain/Fountain.java @@ -62,6 +62,8 @@ public class Fountain extends Activity { @Override protected void onResume() { + Log.e("rs", "onResume"); + // Ideally a game should implement onResume() and onPause() // to take appropriate action when the activity looses focus super.onResume(); @@ -70,12 +72,16 @@ public class Fountain extends Activity { @Override protected void onPause() { + Log.e("rs", "onPause"); + // Ideally a game should implement onResume() and onPause() // to take appropriate action when the activity looses focus super.onPause(); mView.onPause(); - Runtime.getRuntime().exit(0); + + + //Runtime.getRuntime().exit(0); } diff --git a/libs/rs/java/Fountain/src/com/android/fountain/FountainView.java b/libs/rs/java/Fountain/src/com/android/fountain/FountainView.java index 1b07f98..116afd0 100644 --- a/libs/rs/java/Fountain/src/com/android/fountain/FountainView.java +++ b/libs/rs/java/Fountain/src/com/android/fountain/FountainView.java @@ -49,14 +49,40 @@ public class FountainView extends RSSurfaceView { private RenderScript mRS; private FountainRS mRender; + private void destroyRS() { + if(mRS != null) { + mRS = null; + destroyRenderScript(); + } + java.lang.System.gc(); + } + public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { super.surfaceChanged(holder, format, w, h); + Log.e("rs", "surfaceChanged"); + destroyRS(); + + mRS = createRenderScript(false, true); mRender = new FountainRS(); mRender.init(mRS, getResources(), w, h); } + public void surfaceDestroyed(SurfaceHolder holder) { + // Surface will be destroyed when we return + Log.v("rs", "surfaceDestroyed"); + destroyRS(); + + try { + java.lang.Thread.sleep(5000); + } catch(InterruptedException e) { + + } + Runtime.getRuntime().exit(0); + } + + @Override public boolean onTouchEvent(MotionEvent ev) -- cgit v1.1