Project

General

Profile

« Previous | Next » 

Revision b0ebdf5e

Added by Leszek Koltunski about 7 years ago

Major:

1) in the Library, fix the fact that some applications (those that were creating their DistortedSurface objects outside of onSurfaceCreated or onSurfaceChanged) would not render after the activity went to background (press POWER to see that).
2) in the Apps, call the new 'Distorted.onPause()' API to fix the above problem

The above fixes the problem, but it still leaks memory if an App creates its Surface in onSurfaceCreated/Changed (precisely: it leaves the old Surface in the DistortedSurface Map). Thus

3) Fix the first 15 Apps to avoid the memory leak. Next Apps coming.

View differences:

src/main/java/org/distorted/examples/monalisa/MonaLisaRenderer.java
39 39

  
40 40
import android.graphics.Bitmap;
41 41
import android.graphics.BitmapFactory;
42
import android.opengl.GLES30;
43 42
import android.opengl.GLSurfaceView;
44 43

  
45 44
///////////////////////////////////////////////////////////////////////////////////////////////////
......
48 47
{
49 48
    private GLSurfaceView mView;
50 49
    private DistortedEffects mEffects;
50
    private DistortedTexture mTexture;
51 51
    private DistortedScreen mScreen;
52 52
    private int bmpHeight, bmpWidth;
53 53

  
......
130 130
      bmpHeight = bitmap.getHeight();
131 131
      bmpWidth  = bitmap.getWidth();
132 132

  
133
      MeshFlat mesh = new MeshFlat(9,9*bmpHeight/bmpWidth);
134
      DistortedTexture texture = new DistortedTexture(bmpWidth,bmpHeight);
135
      texture.setTexture(bitmap);
133
      // We could have gotten here after the activity went to the background
134
      // for a brief amount of time; in this case mTexture is already created.
135
      // Do not leak memory by creating it the second time around.
136
      if( mTexture==null ) mTexture = new DistortedTexture(bmpWidth,bmpHeight);
137

  
138
      // even if mTexture wasn't null, we still need to call setTexture() on it
139
      // because every time activity goes to background, its OpenGL resources
140
      // - including Textures - get deleted. We always need to call setTexture()
141
      // to recreate the internal OpenGL textures.
142
      mTexture.setTexture(bitmap);
136 143

  
137 144
      mScreen.detachAll();
138
      mScreen.attach(texture,mEffects,mesh);
145
      mScreen.attach(mTexture,mEffects,new MeshFlat(9,9*bmpHeight/bmpWidth));
139 146

  
140 147
      DistortedEffects.enableEffect(EffectNames.DISTORT);
141 148

  

Also available in: Unified diff