位图被回收......?

时间:2016-06-19 03:31:04

标签: android

我正在制作游戏的用户界面系统。但我注意到一个奇怪的问题:Bitmap似乎被回收了

我还没有回收任何位图(我将在稍后做)。 但logcat说:

AWS.config(
            :s3_endpoint => '...',
            :access_key_id => '....',
            :secret_access_key => '....'
           )

我从未想过系统可以回收位图。也许我在创建位图时做错了。

E/AndroidRuntime: FATAL EXCEPTION: GLThread 1050
Process: gippeumi.youckma, PID: 19044
java.lang.IllegalArgumentException: bitmap is recycled
  at android.opengl.GLUtils.texImage2D(GLUtils.java:160)
  at gippeumi.youckma.graphics.util.GLTextureManager.Set(GLTextureManager.java:53)
  at gippeumi.youckma.graphics.ui.element.UIElement.UpdateTexture(UIElement.java:64)
  at gippeumi.youckma.graphics.ui.element.TextLabel.OnRender(TextLabel.java:42)
  at gippeumi.youckma.graphics.ui.element.UIElement.Render(UIElement.java:71)
  at gippeumi.youckma.graphics.ui.Screen.Render(Screen.java:50)
  at gippeumi.youckma.graphics.GameRenderer.onDrawFrame(GameRenderer.java:52)
  at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1531)
  at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248)

注意:这就是GLTextureManager.Set的作用(稍后我会将GL10编辑为GLES20。):

public abstract class UIElement {
    private static final String TAG = "UI Element";
    private static final int WH_SCALER = 100;

    private String name;
    private CoreRect rect;
    private int tex;
    private float x, y;
    private float w, h;
    private Bitmap bmp;

    protected UIElement(String Name, float X, float Y, float Width, float Height) {
        name = Name;
        x = X;
        y = Y;
        w = Width;
        h = Height;
        rect = new CoreRect(Width, Height, false);
        bmp = Bitmap.createBitmap((int)(Width * WH_SCALER), (int)(Height * WH_SCALER), Bitmap.Config.ARGB_8888);
        onCreate(bmp);
    }

    public float GetX() {
        return x;
    }

    public float GetY() {
        return y;
    }

    public float GetWidth() {
        return w;
    }

    public float GetHeight() {
        return h;
    }

    public String GetName() {
        return name;
    }

    protected abstract void OnCreate(Bitmap Bmp);
    private void onCreate(Bitmap Bmp) {
        GLTextureManager.Lock();
        OnCreate(Bmp);
        tex = GLTextureManager.Add(Bmp);
        GLTextureManager.Unlock();
    }

    protected void UpdateTexture() {
        Log.d(TAG, "Texture updated");
        GLTextureManager.Set(tex, bmp);
    }

    protected abstract void OnRender(Bitmap Bmp);
    public void Render() {
        //Log.d(TAG, "Render()");
        GLTextureManager.Lock();
        OnRender(bmp);
        rect.Render(x, y, GLTextureManager.Get(tex));
        GLTextureManager.Unlock();
    }
}

0 个答案:

没有答案