所以我对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)
主要课程代码:
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());
}
}
}
非常感谢任何帮助!