v0.9.1b: added various safety checks to prevent crashes

This commit is contained in:
Evan Debenham 2020-12-31 22:20:27 -05:00
parent 90721786a2
commit 4f4174c7b9
3 changed files with 23 additions and 11 deletions

View File

@ -39,20 +39,20 @@ public class Random {
resetGenerators(); resetGenerators();
} }
public static void resetGenerators(){ public static synchronized void resetGenerators(){
generators = new ArrayDeque<>(); generators = new ArrayDeque<>();
generators.push(new java.util.Random()); generators.push(new java.util.Random());
} }
public static void pushGenerator(){ public static synchronized void pushGenerator(){
generators.push( new java.util.Random() ); generators.push( new java.util.Random() );
} }
public static void pushGenerator( long seed ){ public static synchronized void pushGenerator( long seed ){
generators.push( new java.util.Random( seed ) ); generators.push( new java.util.Random( seed ) );
} }
public static void popGenerator(){ public static synchronized void popGenerator(){
if (generators.size() == 1){ if (generators.size() == 1){
Game.reportException( new RuntimeException("tried to pop the last random number generator!")); Game.reportException( new RuntimeException("tried to pop the last random number generator!"));
} else { } else {
@ -61,7 +61,7 @@ public class Random {
} }
//returns a uniformly distributed float in the range [0, 1) //returns a uniformly distributed float in the range [0, 1)
public static float Float() { public static synchronized float Float() {
return generators.peek().nextFloat(); return generators.peek().nextFloat();
} }
@ -81,7 +81,7 @@ public class Random {
} }
//returns a uniformly distributed int in the range [0, max) //returns a uniformly distributed int in the range [0, max)
public static int Int( int max ) { public static synchronized int Int( int max ) {
return max > 0 ? generators.peek().nextInt(max) : 0; return max > 0 ? generators.peek().nextInt(max) : 0;
} }
@ -101,7 +101,7 @@ public class Random {
} }
//returns a uniformly distributed long in the range [-2^63, 2^63) //returns a uniformly distributed long in the range [-2^63, 2^63)
public static long Long() { public static synchronized long Long() {
return generators.peek().nextLong(); return generators.peek().nextLong();
} }
@ -190,7 +190,7 @@ public class Random {
null; null;
} }
public static<T> void shuffle( List<?extends T> list){ public synchronized static<T> void shuffle( List<?extends T> list){
Collections.shuffle(list, generators.peek()); Collections.shuffle(list, generators.peek());
} }

View File

@ -570,7 +570,8 @@ public class Item implements Bundlable {
@Override @Override
public void call() { public void call() {
curUser = user; curUser = user;
Item.this.detach(user.belongings.backpack).onThrow(cell); Item i = Item.this.detach(user.belongings.backpack);
if (i != null) i.onThrow(cell);
if (curUser.hasTalent(Talent.IMPROVISED_PROJECTILES) if (curUser.hasTalent(Talent.IMPROVISED_PROJECTILES)
&& !(Item.this instanceof MissileWeapon) && !(Item.this instanceof MissileWeapon)
&& curUser.buff(Talent.ImprovisedProjectileCooldown.class) == null){ && curUser.buff(Talent.ImprovisedProjectileCooldown.class) == null){

View File

@ -22,6 +22,7 @@
package com.shatteredpixel.shatteredpixeldungeon.sprites; package com.shatteredpixel.shatteredpixeldungeon.sprites;
import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.watabou.noosa.Game;
import com.watabou.noosa.TextureFilm; import com.watabou.noosa.TextureFilm;
public class GhoulSprite extends MobSprite { public class GhoulSprite extends MobSprite {
@ -44,10 +45,10 @@ public class GhoulSprite extends MobSprite {
attack = new Animation( 12, false ); attack = new Animation( 12, false );
attack.frames( frames, 0, 8, 9 ); attack.frames( frames, 0, 8, 9 );
crumple = new Animation( 15, false); crumple = new Animation( 1, false);
crumple.frames( frames, 0, 10, 11, 12 ); crumple.frames( frames, 0, 10, 11, 12 );
die = new Animation( 15, false ); die = new Animation( 1, false );
die.frames( frames, 0, 10, 11, 12, 13 ); die.frames( frames, 0, 10, 11, 12, 13 );
play( idle ); play( idle );
@ -58,6 +59,16 @@ public class GhoulSprite extends MobSprite {
play(crumple); play(crumple);
} }
@Override
public void move(int from, int to) {
if (parent == null){
//fixme this happens rarely, likely due to ghoul like link?
Game.reportException(new RuntimeException("ghoul sprite tried to move with null parent! ghoul HP: " + ch.HP));
return;
}
super.move(from, to);
}
@Override @Override
public void die() { public void die() {
if (curAnim == crumple){ if (curAnim == crumple){