Java LibGDX errno 12内存不足

Java LibGDX errno 12内存不足,java,memory,libgdx,out-of-memory,Java,Memory,Libgdx,Out Of Memory,所以我对lib比较陌生,我在确定是什么导致我的内存不足错误时遇到了一些问题: 该程序将运行约45秒,然后由于以下错误而崩溃: <sharedmem_gpumem_alloc_id:1431>: sharedmem_gpumem_alloc: mmap failed errno 12 Out of memory <ioctl_kgsl_sharedmem_alloc:1532>: ioctl_kgsl_sharedmem_alloc: FATAL ERROR :

所以我对lib比较陌生,我在确定是什么导致我的内存不足错误时遇到了一些问题: 该程序将运行约45秒,然后由于以下错误而崩溃:

 <sharedmem_gpumem_alloc_id:1431>: sharedmem_gpumem_alloc: mmap failed
 errno 12 Out of memory

 <ioctl_kgsl_sharedmem_alloc:1532>: ioctl_kgsl_sharedmem_alloc: FATAL
 ERROR : (null)
:sharedmem\u gpumem\u alloc:mmap失败
错误12内存不足
:ioctl_kgsl_sharedmem_alloc:致命
错误:(空)
主要类别代码:

package com.mygdx.game;

import java.util.Random;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g3d.Environment;
import com.badlogic.gdx.graphics.g3d.Material;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.graphics.g3d.ModelInstance;
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
import com.badlogic.gdx.graphics.g3d.utils.CameraInputController;
import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder;
import com.badlogic.gdx.input.GestureDetector;
import com.badlogic.gdx.input.GestureDetector.GestureListener;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;

public class GDXGame extends ApplicationAdapter implements GestureListener {

    public CameraInputController camController;
    public Environment environment;
    public static PerspectiveCamera cam;
    public ModelBatch modelBatch;

    public Model cube;
    public ModelInstance cube1;
    public Model camCube;
    public ModelInstance camCubeInst;

    public float xPos,yPos,zPos;
    public Vector3 camPos;
    public Vector3 forward;
    public Vector3 side;
    public ModelBuilder modelBuilder;
    public static SpriteBatch batch;

    private button button1;

    @Override
    public void create () {     
        environment = new Environment();
        environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f,0.4f,0.4f,1f));
        environment.add(new DirectionalLight().set(0.8f,0.8f,0.8f,
                                                    1f,-5f,-2f));
        batch = new SpriteBatch();    

        GestureDetector gd = new GestureDetector(this);
        Gdx.input.setInputProcessor(gd);

        modelBatch = new ModelBatch();

        cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        xPos = 6f;
        yPos = 5f;
        zPos = 6f;

        camPos = new Vector3(xPos,yPos,zPos);
        cam.rotate(45,0,45,0);
        cam.position.set(camPos);
        cam.rotate(45,cam.direction.x,0,-cam.direction.z);

        cam.near = 1f;
        cam.far = 300f;
        cam.update();

        modelBuilder = new ModelBuilder();
        cube = modelBuilder.createBox(5f,5f,5f,
                new Material(ColorAttribute.createDiffuse(Color.GREEN)),
                Usage.Position | Usage.Normal);
        cube1 = new ModelInstance(cube);
        camCube = modelBuilder.createBox(1f,1f,1f,
                new Material(ColorAttribute.createDiffuse(Color.RED)),
                Usage.Position | Usage.Normal);
        camCubeInst = new ModelInstance(camCube);
        camCubeInst.transform.translate(5,3,5);
        camCubeInst.transform.rotate(new Vector3(0,1,0),45);

        button1 = new button(Gdx.graphics.getWidth()/2,Gdx.graphics.getHeight()/2,0,0);
    }

    @Override
    public void render () {     
        Gdx.gl.glViewport(0,0,Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);        

        cam.update();   

        modelBatch.begin(cam);
        modelBatch.render(cube1, environment);
        modelBatch.render(camCubeInst, environment);
        modelBatch.end();

        batch.begin();
        button1.render();
        batch.end();

    }     
    @Override
    public void resume () {
    }

    @Override
    public void resize (int width, int height) {
    }

    @Override
    public void pause () {
    }

    @Override
    public boolean touchDown(float x, float y, int pointer, int button) {
        return false;
    }

    @Override
    public boolean tap(float x, float y, int count, int button) {
        Gdx.app.log("DEBUG","TAP x: " + x + "  y: " + y);
        if(x <= (button1.x+button1.image.getWidth()) && x >= button1.x){
            if(y <= (button1.y+button1.image.getHeight()) && y >= button1.y){
                    if(!Gdx.input.isTouched()){
                            button1.bool = true;
                            Random rand = new Random();
                            float r = rand.nextFloat();
                            float g = rand.nextFloat();
                            float b = rand.nextFloat();
                            Color random = new Color(r,g,b,255);
                            cube = modelBuilder.createBox(5f,5f,5f,
                                    new Material(ColorAttribute.createDiffuse(random)),
                                    Usage.Position | Usage.Normal);
                            cube1 = new ModelInstance(cube);  
                    }
               }
        }
        return false;
    }

    @Override
    public boolean longPress(float x, float y) {
        return false;
    }

    @Override
    public boolean fling(float velocityX, float velocityY, int button) {
        return false;
    }

    @Override
    public boolean pan(float x, float y, float deltaX, float deltaY) {
        cam.rotate(-45,cam.direction.x,0,-cam.direction.z);
        forward = new Vector3(cam.direction.x,cam.direction.y,cam.direction.z);
        side = new Vector3(cam.direction.cpy().crs(cam.up).nor());
        cam.translate(side.scl(-deltaX/60));
        cam.translate(forward.scl(deltaY/60));
        cam.rotate(45,cam.direction.x,0,-cam.direction.z);
        return true;
    }

    @Override
    public boolean panStop(float x, float y, int pointer, int button) {
        Gdx.app.log("DEBUG","TAP x: " + x + "  y: " + y);
        if(x <= (button1.x+button1.image.getWidth()) && x >= button1.x){
            if(y <= (button1.y+button1.image.getHeight()) && y >= button1.y){
                    if(!Gdx.input.isTouched()){
                            button1.bool = true;
                            Random rand = new Random();
                            float r = rand.nextFloat()+100;
                            float g = rand.nextFloat()+100;
                            float b = rand.nextFloat()+100;
                            Color random = new Color(r,g,b,255);
                            cube = modelBuilder.createBox(5f,5f,5f,
                                    new Material(ColorAttribute.createDiffuse(random)),
                                    Usage.Position | Usage.Normal);
                            cube1 = new ModelInstance(cube);  
                    }
               }
        }
        return false;
    }

    @Override
    public boolean zoom(float initialDistance, float distance) {
        return false;
    }

    @Override
    public boolean pinch(Vector2 initialPointer1, Vector2 initialPointer2,
            Vector2 pointer1, Vector2 pointer2) {
        return false;
    }
    @Override
    public void dispose () {
        batch.dispose();
        modelBatch.dispose();
        cube.dispose();
        button1.image.dispose();
        camCube.dispose();
    }
}
package com.mygdx.game;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;

public class button{
        float x;
        float y;
        @SuppressWarnings("unused")
        private float w;
        @SuppressWarnings("unused")
        private float h;
        Texture image;
        Texture image2;
        Texture drawImage;
        private float touchX,touchY;
        boolean bool;
        public button(float x, float y, float w, float h){
                this.x = x;
                this.y = y;
                this.w = w;
                this.h = h;
                drawImage = new Texture("badlogic.jpg");
                image2 = new Texture("badlogic2.jpg");
                image = new Texture("badlogic.jpg");

        }
        public void render(){
                touchX = Gdx.input.getX();
                touchY = Gdx.input.getY();
                if(Gdx.input.isTouched() && touchX <= (x+image.getWidth()) && touchX >= x && touchY <= (y+image.getHeight()) && touchY >= y){
                    drawImage = image2;
                }
                else{
                    drawImage = image;
                }
                if(bool){
                    drawImage = image;
                    GDXGame.batch.draw(drawImage, x, Gdx.graphics.getHeight() - y - image.getHeight());
                    bool = false;
                    Gdx.app.log("DEBUG","Button pressed");

                }
                else{
                    GDXGame.batch.draw(drawImage, x, Gdx.graphics.getHeight() - y - image.getHeight());
                }
        }
}
package com.mygdx.game;
导入java.util.Random;
导入com.badlogic.gdx.ApplicationAdapter;
导入com.badlogic.gdx.gdx;
导入com.badlogic.gdx.graphics.Color;
导入com.badlogic.gdx.graphics.GL20;
导入com.badlogic.gdx.graphics.PerspectiveCamera;
导入com.badlogic.gdx.graphics.VertexAttributes.Usage;
导入com.badlogic.gdx.graphics.g2d.SpriteBatch;
导入com.badlogic.gdx.graphics.g3d.Environment;
导入com.badlogic.gdx.graphics.g3d.Material;
导入com.badlogic.gdx.graphics.g3d.Model;
导入com.badlogic.gdx.graphics.g3d.ModelBatch;
导入com.badlogic.gdx.graphics.g3d.ModelInstance;
导入com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
导入com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
导入com.badlogic.gdx.graphics.g3d.utils.CameraInputController;
导入com.badlogic.gdx.graphics.g3d.utils.ModelBuilder;
导入com.badlogic.gdx.input.GestureDetector;
导入com.badlogic.gdx.input.GestureDetector.GestureListener;
导入com.badlogic.gdx.math.Vector2;
导入com.badlogic.gdx.math.Vector3;
公共类GDXGame扩展了ApplicationAdapter实现了GestureListener{
公共摄像机控制器;
公共环境;
公共静态透视摄像机;
公共模型批处理模型批处理;
公共模型立方体;
公共模型实例cube1;
公共模型camCube;
公共模型实例camCubeInst;
公共浮动XPO、YPO、ZPO;
公共矢量3坎波斯;
公共矢量3前进;
公共矢量3侧;
公共模型生成器模型生成器;
公共静态SpriteBatch批处理;
私人按钮1;
@凌驾
public void create(){
环境=新环境();
set(新的ColorAttribute(ColorAttribute.AmbientLight,0.4f,0.4f,0.4f,1f));
environment.add(新建DirectionalLight().set(0.8f、0.8f、0.8f、,
1f,-5f,-2f));
批次=新的SpriteBatch();
GestureDetector gd=新的GestureDetector(本);
Gdx.input.setInputProcessor(gd);
modelBatch=新modelBatch();
cam=新透视照相机(67,Gdx.graphics.getWidth(),Gdx.graphics.getHeight());
xPos=6f;
yPos=5f;
zPos=6f;
camPos=新矢量3(xPos、YPO、zPos);
凸轮旋转(45,0,45,0);
凸轮位置设置(camPos);
凸轮旋转(45,凸轮方向x,0,-凸轮方向z);
cam.near=1f;
凸轮远=300f;
cam.update();
modelBuilder=新的modelBuilder();
cube=modelBuilder.createBox(5f,5f,5f,
新材质(ColorAttribute.createDiffuse(Color.GREEN)),
用法.位置|用法.正常);
cube1=新模型实例(多维数据集);
camCube=modelBuilder.createBox(1f、1f、1f、,
新材质(ColorAttribute.createDiffuse(Color.RED)),
用法.位置|用法.正常);
camCubeInst=新模型实例(camCube);
camCubeInst.变换.平移(5,3,5);
camCubeInst.变换.旋转(新向量3(0,1,0),45);
button1=新按钮(Gdx.graphics.getWidth()/2,Gdx.graphics.getHeight()/2,0,0);
}
@凌驾
公共无效呈现(){
glViewport(0,0,Gdx.graphics.getWidth(),Gdx.graphics.getHeight());
Gdx.gl.glClear(GL20.gl_颜色_缓冲_位| GL20.gl_深度_缓冲_位);
cam.update();
modelBatch.begin(cam);
render(cube1,环境);
render(camCubeInst,环境);
modelBatch.end();
batch.begin();
按钮1.render();
batch.end();
}     
@凌驾
公开无效简历(){
}
@凌驾
公共空心调整大小(整型宽度、整型高度){
}
@凌驾
公共空白暂停(){
}
@凌驾
公共布尔接地(浮点x、浮点y、整数指针、整数按钮){
返回false;
}
@凌驾
公共布尔点击(浮点x、浮点y、整数计数、整数按钮){
Gdx.app.log(“调试”,“点击x:+x+”y:+y”);
如果(x=按钮1.x){
如果(y=按钮1.y){
如果(!Gdx.input.isTouched()){
button1.bool=true;
Random rand=新的Random();
float r=rand.nextFloat();
float g=rand.nextFloat();
float b=rand.nextFloat();
颜色随机=新颜色(r、g、b、255);
cube=modelBuilder.createBox(5f,5f,5f,
新材质(ColorAttribute.createDiffuse(随机)),
用法.位置|用法.正常);
cube1=新模型实例(多维数据集);
}
}
}
返回false;
}
@凌驾
公共布尔长按(浮点x,浮点y){
返回false;
}
@凌驾
公共布尔触发器(float-velocityX、float-velocityY、int按钮){
返回false;
}
@凌驾
公共布尔平移(浮点x、浮点y、浮点deltaX、浮点deltaY){
凸轮旋转(-45,凸轮方向x,0,-凸轮方向z);
前进=新矢量3(凸轮方向x,凸轮方向y,凸轮方向z);
side=新矢量3(cam.direction.cpy().crs(cam.up.nor());
凸轮平移(侧面scl(-deltaX/60));
凸轮平移(正向scl(deltaY/60));
凸轮旋转(45,凸轮方向x,0,-凸轮方向z);
返回true;
}
@凌驾
公共布尔泛顶(浮点x、浮点y、整型指针、,