v0.4.3: fixed a bunch of crash bugs

This commit is contained in:
Evan Debenham 2016-10-01 02:38:24 -04:00
parent 794648fa21
commit e3b0720de9
4 changed files with 45 additions and 22 deletions

View File

@ -32,18 +32,20 @@ public class Vertexbuffer {
private FloatBuffer vertices; private FloatBuffer vertices;
private int updateStart, updateEnd; private int updateStart, updateEnd;
private static ArrayList<Vertexbuffer> buffers = new ArrayList<>(); private static final ArrayList<Vertexbuffer> buffers = new ArrayList<>();
public Vertexbuffer( FloatBuffer vertices ) { public Vertexbuffer( FloatBuffer vertices ) {
int[] ptr = new int[1]; synchronized (buffers) {
GLES20.glGenBuffers( 1, ptr, 0 ); int[] ptr = new int[1];
id = ptr[0]; GLES20.glGenBuffers(1, ptr, 0);
id = ptr[0];
this.vertices = vertices; this.vertices = vertices;
buffers.add(this); buffers.add(this);
updateStart = 0; updateStart = 0;
updateEnd = vertices.limit(); updateEnd = vertices.limit();
}
} }
//For flagging the buffer for a full update without changing anything //For flagging the buffer for a full update without changing anything
@ -96,14 +98,18 @@ public class Vertexbuffer {
} }
public void delete(){ public void delete(){
GLES20.glDeleteBuffers(1, new int[]{id}, 0); synchronized (buffers) {
buffers.remove(this); GLES20.glDeleteBuffers(1, new int[]{id}, 0);
buffers.remove(this);
}
} }
public static void refreshAllBuffers(){ public static void refreshAllBuffers(){
for (Vertexbuffer buf : buffers) { synchronized (buffers) {
buf.updateVertices(); for (Vertexbuffer buf : buffers) {
buf.updateGLData(); buf.updateVertices();
buf.updateGLData();
}
} }
} }

View File

@ -245,7 +245,10 @@ public class Tilemap extends Visual {
while(bottomRight >= topLeft && bufferPositions[bottomRight] == -1) while(bottomRight >= topLeft && bufferPositions[bottomRight] == -1)
bottomRight--; bottomRight--;
length = bufferPositions[bottomRight] - bufferPositions[topLeft] + 1; if (topLeft >= bufferPositions.length || bottomRight <= 0)
length = 0;
else
length = bufferPositions[bottomRight] - bufferPositions[topLeft] + 1;
} }
if (camX >= mapWidth if (camX >= mapWidth

View File

@ -336,7 +336,8 @@ public class Hero extends Char {
} }
if (dmg < 0) dmg = 0; if (dmg < 0) dmg = 0;
if (subClass == HeroSubClass.BERSERKER){ if (subClass == HeroSubClass.BERSERKER){
dmg = Buff.affect(this, Berserk.class).damageFactor(dmg); berserk = Buff.affect(this, Berserk.class);
dmg = berserk.damageFactor(dmg);
} }
return buff( Fury.class ) != null ? (int)(dmg * 1.5f) : dmg; return buff( Fury.class ) != null ? (int)(dmg * 1.5f) : dmg;
} }
@ -1168,7 +1169,10 @@ public class Hero extends Char {
HornOfPlenty.hornRecharge horn = buff(HornOfPlenty.hornRecharge.class); HornOfPlenty.hornRecharge horn = buff(HornOfPlenty.hornRecharge.class);
if (horn != null) horn.gainCharge(percent); if (horn != null) horn.gainCharge(percent);
if (subClass == HeroSubClass.BERSERKER) Buff.affect(this, Berserk.class).recover(percent); if (subClass == HeroSubClass.BERSERKER){
berserk = Buff.affect(this, Berserk.class);
berserk.recover(percent);
}
boolean levelUp = false; boolean levelUp = false;
while (this.exp >= maxExp()) { while (this.exp >= maxExp()) {
@ -1370,13 +1374,17 @@ public class Hero extends Char {
Dungeon.deleteGame( Dungeon.hero.heroClass, true ); Dungeon.deleteGame( Dungeon.hero.heroClass, true );
} }
//effectively cache this buff to prevent having to call buff(Berserk.class) a bunch.
//This is relevant because we call isAlive during drawing, which has both performance
//and concurrent modification implications if that method calls buff(Berserk.class)
private Berserk berserk;
@Override @Override
public boolean isAlive() { public boolean isAlive() {
if (subClass == HeroSubClass.BERSERKER){ if (subClass == HeroSubClass.BERSERKER
Berserk berserk = buff(Berserk.class); && berserk != null
if (berserk != null && berserk.berserking()){ && berserk.berserking()){
return true; return true;
}
} }
return super.isAlive(); return super.isAlive();
} }

View File

@ -145,6 +145,11 @@ public class BuffIndicator extends Component {
super.updateValues( progress ); super.updateValues( progress );
image.scale.set( 1 + 5 * progress ); image.scale.set( 1 + 5 * progress );
}; };
@Override
protected void onComplete() {
image.killAndErase();
}
} ); } );
} }
} }
@ -176,7 +181,8 @@ public class BuffIndicator extends Component {
@Override @Override
protected void onClick() { protected void onClick() {
GameScene.show(new WndInfoBuff(buff)); if (buff.icon() != NONE)
GameScene.show(new WndInfoBuff(buff));
} }
} }