android - calling batch.dispose() gives the fatal signal 11(SIGSEGV) while trying to switch screen -


public class picasso extends game {    	public static final string tag = "debug";    	private texture blackbar;  	private texture blackplayer, redplayer,greenplayer, redbar, greenbar;  	private sound dropsound;  	private music rainmusic;  	public spritebatch batch;  	private orthographiccamera camera;  	private rectangle bucket;  	private array<rectangle> blackplayerlist,greenplayerlist,redplayerlist;  	private long lastblacktime,lastredtime,lastgreentime;  	private boolean isblack,isred,isgreen;    	@override  	public void create() {  		gdx.app.setloglevel(application.log_debug);  		// load images droplet , bucket, 64x64 pixels each  		batch = new spritebatch();  		isblack = true;  		isgreen = false;  		isred = false;  		blackbar = new texture(gdx.files.internal("bar.png"));  		blackplayer = new texture(gdx.files.internal("player.png"));  		redbar = new texture(gdx.files.internal("redbar.png"));  		greenbar = new texture(gdx.files.internal("greenbar.png"));  		greenplayer = new texture(gdx.files.internal("greenplayer.png"));  		redplayer = new texture(gdx.files.internal("redplayer.png"));    		// create camera , spritebatch  		camera = new orthographiccamera();  		camera.settoortho(false, gdx.graphics.getwidth(), gdx.graphics.getheight());      		// create rectangle logically represent bucket  		bucket = new rectangle();  		bucket.x = gdx.graphics.getwidth() / 2 - 64 / 2; // center bucket horizontally  		bucket.y = 20; // bottom left corner of bucket 20 pixels above bottom screen edge  		bucket.width = 6;  		bucket.height = 6;    		// create blackplayerlist array , spawn first bar  		blackplayerlist = new array<rectangle>();  		redplayerlist = new array<rectangle>();  		greenplayerlist = new array<rectangle>();  		spawnbar(0);  		spawnred(150);  		spawngreen(300);  	}    	private void spawnbar(int gap) {  		rectangle bar = new rectangle();  		bar.x = mathutils.random(0, gdx.graphics.getwidth()-400);  		bar.y = gdx.graphics.getheight()+gap;  		bar.width = 64;  		bar.height = 64;  		blackplayerlist.add(bar);  		lastblacktime = timeutils.millis();  	}    	private void spawngreen(int gap) {  		rectangle bar = new rectangle();  		bar.x = mathutils.random(0, gdx.graphics.getwidth()-400);  		bar.y = gdx.graphics.getheight()+gap;  		bar.width = 64;  		bar.height = 64;  		greenplayerlist.add(bar);  		lastgreentime = timeutils.millis();  	}    	private void spawnred(int gap) {  		rectangle bar = new rectangle();  		bar.x = mathutils.random(0, gdx.graphics.getwidth()-400);  		bar.y = gdx.graphics.getheight()+gap;  		bar.width = 64;  		bar.height = 64;  		redplayerlist.add(bar);  		lastredtime = timeutils.millis();  	}    	@override  	public void render() {  		gdx.gl.glclearcolor(1, 1, 1, 1);  		gdx.gl.glclear(gl20.gl_color_buffer_bit);  		super.render();  		dispose();  		setscreen(new gameover(picasso.this));    		camera.update();    		batch.setprojectionmatrix(camera.combined);    		gdx.input.setinputprocessor(new inputadapter(){  			@override  			public boolean touchdown(int screenx, int screeny, int pointer, int button) {  				if(isblack){  					isred = true;  					isblack = false;  					isgreen = false;  				} else if(isred){  					isgreen = true;  					isred = false;  					isblack = false;  				} else {  					isblack = true;  					isred = false;  					isgreen = false;  				}  				return super.touchdown(screenx, screeny, pointer, button);  			}  		});    		// begin new batch , draw bucket ,  		// drops  		batch.begin();  		batch.draw(blackplayer, bucket.x, bucket.y,50,50);  		for(rectangle bar: blackplayerlist) {  			batch.draw(blackbar, bar.x, bar.y,400,500);  		}  		for(rectangle bar: redplayerlist) {  			batch.draw(redbar, bar.x, bar.y,400,500);  		}  		for(rectangle bar: greenplayerlist) {  			batch.draw(greenbar, bar.x, bar.y,400,500);  		}  		if(isblack){  			batch.draw(blackplayer, bucket.x, bucket.y,50,50);  		}else if(isgreen){  			batch.draw(greenplayer, bucket.x, bucket.y,50,50);  		} else{  			batch.draw(redplayer, bucket.x, bucket.y,50,50);  		}  		batch.end();    		if(gdx.input.iskeypressed(keys.left)) bucket.x -= 200 * gdx.graphics.getdeltatime();  		if(gdx.input.iskeypressed(keys.right)) bucket.x += 200 * gdx.graphics.getdeltatime();    		// make sure bucket stays within screen bounds  //		if(bucket.x < 0) bucket.x = 0;  //		if(bucket.x > 800 - 64) bucket.x = 800 - 64;  		int rand1=mathutils.random(1,3);  		int rand2=mathutils.random(1,3);  		int rand3=mathutils.random(1,3);  		// check if need create new bar  		if(rand1 == 1){  			if(timeutils.millis() - lastblacktime > 2500) spawnbar(0);  			if(timeutils.millis() - lastredtime > 2500) spawnred(150);  			if(timeutils.millis() - lastgreentime > 2500) spawngreen(300);  		} else if(rand1 == 2){  			if(timeutils.millis() - lastgreentime > 2500) spawngreen(0);  			if(timeutils.millis() - lastredtime > 2500) spawnred(150);  			if(timeutils.millis() - lastblacktime > 2500) spawnbar(300);  		} else{  			if(timeutils.millis() - lastblacktime > 2500) spawnbar(0);  			if(timeutils.millis() - lastgreentime > 2500) spawngreen(150);  			if(timeutils.millis() - lastredtime > 2500) spawnred(300);  		}    		if(rand2 == 1){  			if(timeutils.millis() - lastblacktime > 2500) spawnbar(0);  			if(timeutils.millis() - lastgreentime > 2500) spawngreen(150);  			if(timeutils.millis() - lastredtime > 2500) spawnred(300);  		} else if(rand2 == 2){  			if(timeutils.millis() - lastblacktime > 2500) spawnbar(0);  			if(timeutils.millis() - lastgreentime > 2500) spawngreen(150);  			if(timeutils.millis() - lastredtime > 2500) spawnred(300);  		} else{  			if(timeutils.millis() - lastblacktime > 2500) spawnbar(0);  			if(timeutils.millis() - lastredtime > 2500) spawnred(150);  			if(timeutils.millis() - lastgreentime > 2500) spawngreen(300);  		}    		if(rand3 == 1){  			if(timeutils.millis() - lastgreentime > 2500) spawngreen(0);  			if(timeutils.millis() - lastblacktime > 2500) spawnbar(150);  			if(timeutils.millis() - lastredtime > 2500) spawnred(300);  		} else if(rand3 == 2){  			if(timeutils.millis() - lastblacktime > 2500) spawnbar(0);  			if(timeutils.millis() - lastredtime > 2500) spawnred(150);  			if(timeutils.millis() - lastgreentime > 2500) spawngreen(300);  		} else{  			if(timeutils.millis() - lastgreentime > 2500) spawngreen(0);  			if(timeutils.millis() - lastblacktime > 2500) spawnbar(150);  			if(timeutils.millis() - lastgreentime > 2500) spawngreen(300);  		}    		iterator<rectangle> iter = blackplayerlist.iterator();  		while(iter.hasnext()) {  			rectangle bar = iter.next();  			bar.y -= 200 * gdx.graphics.getdeltatime();  			if(bar.y + 210 < 0) iter.remove();  		}    		iterator<rectangle> iter2 = redplayerlist.iterator();  		while(iter2.hasnext()) {  			rectangle bar = iter2.next();  			bar.y -= 200 * gdx.graphics.getdeltatime();  			if(bar.y + 210 < 0) iter2.remove();  		}    		iterator<rectangle> iter3 = greenplayerlist.iterator();  		while(iter3.hasnext()) {  			rectangle bar = iter3.next();  			bar.y -= 200 * gdx.graphics.getdeltatime();  			if(bar.y + 210 < 0) iter3.remove();  		}  	}    	@override  	public void dispose() {  		// dispose of native resources  		blackbar.dispose();  		greenbar.dispose();  		redbar.dispose();    		blackplayer.dispose();  		redplayer.dispose();  		greenplayer.dispose();    		dropsound.dispose();  		rainmusic.dispose();  		batch.dispose();  	}  }

above code, trying move screen in beginning of render method try switch screen need call later in render method giving me fatal signal 11 when run app , application stops , have realized problem being caused batch.dispose() in dispose().

if remove batch.dispose() code application runs happens both screen runs simultaneously i.e. current screen not go away , screen comes play, thereby both displaying own content.

any idea , how officially switch screen?

game application origin class.

dispose() of game should called when you're exiting game. doesn't matter on screen arerender() method of game called .

so try in way :

create screen(let's assume playscreen) gameover screen , put render method code in render method of screen , of required stuff of picasso class.

from create method of picasso set playscreen setscreen(new playscreen()) method of game class.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -