Getting wierd crash

Forum for the book "Beginning Android Games", see http://www.apress.com/9781430230427

Getting wierd crash

Postby Tyler » Tue Nov 19, 2019 3:13 am

Please excuse my weird variable names



Can anyone figure out what the problem is here?



This program keeps crashing when I run it on my current test device (google pixel 3 xl). I have tried debugging it and I am certain that the part of the code causing the crashes is the assignment operation from the taco variables into the cVec Vector3 class, this much I know. I have moved and tested it a few ways by moving this portion of code around and removing it completely. At this point I am sure it is the problem because when I remove it the program runs fine. Does anyone have any ideas why this is crashing?

Code: Select all
package craigapps.com;

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.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Vector3;

public class MyGdxGame extends ApplicationAdapter {
    SpriteBatch batch;
    Texture img;
    private OrthographicCamera cam;
    private ShapeRenderer sr;
    private Vector3 pos;
    public int tacox = 0;
    int tacoy = 0;
    public Vector3 cVec;

    @Override
    public void create() {
        batch = new SpriteBatch();
        img = new Texture("badlogic.jpg");
        sr = new ShapeRenderer();
        cam = new OrthographicCamera();
        cam.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        pos = new Vector3(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2, 0);


    }
    public void addcamvalues(){
        cVec.x = (int) tacox;
        cVec.y = (int) tacoy;

    }

    @Override
    public void render() {
        addcamvalues();
        tacox++;
        tacoy++;


        Gdx.gl.glClearColor(1, 0, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        batch.begin();
        batch.draw(img, tacox, tacoy);
        batch.end();
        //render
        cam.update();
        if (Gdx.input.isTouched()) {
            pos.set(Gdx.input.getX(), Gdx.input.getY(), 0);
            cam.unproject(pos);
        }
        //draw
        sr.begin(ShapeRenderer.ShapeType.Filled);
        sr.setColor(Color.GREEN);
        sr.circle(pos.x, pos.y, 64);
        sr.end();



    }

    @Override
    public void dispose() {
        batch.dispose();
        img.dispose();
        sr.dispose();
    }
}
Tyler
 
Posts: 2
Joined: Tue Nov 19, 2019 3:08 am

Re: Getting wierd crash

Postby Tyler » Tue Nov 19, 2019 3:22 am

Tyler wrote:Please excuse my weird variable names



Can anyone figure out what the problem is here?



This program keeps crashing when I run it on my current test device (google pixel 3 xl). I have tried debugging it and I am certain that the part of the code causing the crashes is the assignment operation from the taco variables into the cVec Vector3 class, this much I know. I have moved and tested it a few ways by moving this portion of code around and removing it completely. At this point I am sure it is the problem because when I remove it the program runs fine. Does anyone have any ideas why this is crashing?

Code: Select all
package craigapps.com;

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.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Vector3;

public class MyGdxGame extends ApplicationAdapter {
    SpriteBatch batch;
    Texture img;
    private OrthographicCamera cam;
    private ShapeRenderer sr;
    private Vector3 pos;
    public int tacox = 0;
    int tacoy = 0;
    public Vector3 cVec;

    @Override
    public void create() {
        batch = new SpriteBatch();
        img = new Texture("badlogic.jpg");
        sr = new ShapeRenderer();
        cam = new OrthographicCamera();
        cam.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        pos = new Vector3(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2, 0);


    }
    public void addcamvalues(){
        cVec.x = (int) tacox;
        cVec.y = (int) tacoy;

    }

    @Override
    public void render() {
        addcamvalues();
        tacox++;
        tacoy++;


        Gdx.gl.glClearColor(1, 0, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        batch.begin();
        batch.draw(img, tacox, tacoy);
        batch.end();
        //render
        cam.update();
        if (Gdx.input.isTouched()) {
            pos.set(Gdx.input.getX(), Gdx.input.getY(), 0);
            cam.unproject(pos);
        }
        //draw
        sr.begin(ShapeRenderer.ShapeType.Filled);
        sr.setColor(Color.GREEN);
        sr.circle(pos.x, pos.y, 64);
        sr.end();



    }

    @Override
    public void dispose() {
        batch.dispose();
        img.dispose();
        sr.dispose();
    }
}


Ok so I fixed it, sorry I wasn't initializing the cVec I declared
Tyler
 
Posts: 2
Joined: Tue Nov 19, 2019 3:08 am


Return to Beginning Android Games

Who is online

Users browsing this forum: No registered users and 1 guest