v0.6.4: various bugfixes:

- fixed corrupted mimics causing save/load crashes
- fixed crashes when destroy is called on the same group twice
- syncronized texture cache methods
- added safety checks to
  - SummoningTrap
  - WaterOfHealth
  - WndAlchemy
  - WndBag
This commit is contained in:
Evan Debenham 2018-03-20 21:13:10 -04:00
parent 4c3709a9d9
commit 8ff3db2088
7 changed files with 28 additions and 20 deletions

View File

@ -44,7 +44,7 @@ public class TextureCache {
bitmapOptions.inPreferredConfig = Bitmap.Config.ARGB_8888; bitmapOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;
} }
public static SmartTexture createSolid( int color ) { public synchronized static SmartTexture createSolid( int color ) {
final String key = "1x1:" + color; final String key = "1x1:" + color;
if (all.containsKey( key )) { if (all.containsKey( key )) {
@ -63,7 +63,7 @@ public class TextureCache {
} }
} }
public static SmartTexture createGradient( int... colors ) { public synchronized static SmartTexture createGradient( int... colors ) {
final String key = "" + colors; final String key = "" + colors;
@ -88,11 +88,11 @@ public class TextureCache {
} }
public static void add( Object key, SmartTexture tx ) { public synchronized static void add( Object key, SmartTexture tx ) {
all.put( key, tx ); all.put( key, tx );
} }
public static void remove( Object key ){ public synchronized static void remove( Object key ){
SmartTexture tx = all.get( key ); SmartTexture tx = all.get( key );
if (tx != null){ if (tx != null){
all.remove(key); all.remove(key);
@ -100,7 +100,7 @@ public class TextureCache {
} }
} }
public static SmartTexture get( Object src ) { public synchronized static SmartTexture get( Object src ) {
if (all.containsKey( src )) { if (all.containsKey( src )) {
@ -119,17 +119,17 @@ public class TextureCache {
} }
public static void clear() { public synchronized static void clear() {
for (Texture txt:all.values()) { for (Texture txt : all.values()) {
txt.delete(); txt.delete();
} }
all.clear(); all.clear();
} }
public static void reload() { public synchronized static void reload() {
for (SmartTexture tx:all.values()) { for (SmartTexture tx : all.values()) {
tx.reload(); tx.reload();
} }
} }
@ -164,7 +164,7 @@ public class TextureCache {
} }
} }
public static boolean contains( Object key ) { public synchronized static boolean contains( Object key ) {
return all.containsKey( key ); return all.containsKey( key );
} }

View File

@ -51,8 +51,10 @@ public class Group extends Gizmo {
} }
} }
members.clear(); if (members != null) {
members = null; members.clear();
members = null;
}
length = 0; length = 0;
} }

View File

@ -42,6 +42,8 @@ public class WaterOfHealth extends WellWater {
@Override @Override
protected boolean affectHero( Hero hero ) { protected boolean affectHero( Hero hero ) {
if (!hero.isAlive()) return false;
Sample.INSTANCE.play( Assets.SND_DRINK ); Sample.INSTANCE.play( Assets.SND_DRINK );
hero.HP = hero.HT; hero.HP = hero.HT;

View File

@ -62,14 +62,16 @@ public class Mimic extends Mob {
@Override @Override
public void storeInBundle( Bundle bundle ) { public void storeInBundle( Bundle bundle ) {
super.storeInBundle( bundle ); super.storeInBundle( bundle );
bundle.put( ITEMS, items ); if (items != null) bundle.put( ITEMS, items );
bundle.put( LEVEL, level ); bundle.put( LEVEL, level );
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public void restoreFromBundle( Bundle bundle ) { public void restoreFromBundle( Bundle bundle ) {
items = new ArrayList<>( (Collection<Item>) ((Collection<?>) bundle.getCollection( ITEMS ) )); if (bundle.contains( ITEMS )) {
items = new ArrayList<>((Collection<Item>) ((Collection<?>) bundle.getCollection(ITEMS)));
}
adjustStats( bundle.getInt( LEVEL ) ); adjustStats( bundle.getInt( LEVEL ) );
super.restoreFromBundle(bundle); super.restoreFromBundle(bundle);
} }

View File

@ -77,10 +77,12 @@ public class SummoningTrap extends Trap {
for (Integer point : respawnPoints) { for (Integer point : respawnPoints) {
Mob mob = Dungeon.level.createMob(); Mob mob = Dungeon.level.createMob();
mob.state = mob.WANDERING; if (mob != null) {
mob.pos = point; mob.state = mob.WANDERING;
GameScene.add( mob, DELAY ); mob.pos = point;
mobs.add( mob ); GameScene.add(mob, DELAY);
mobs.add(mob);
}
} }
//important to process the visuals and pressing of cells last, so spawned mobs have a chance to occupy cells first //important to process the visuals and pressing of cells last, so spawned mobs have a chance to occupy cells first

View File

@ -302,7 +302,7 @@ public class WndAlchemy extends Window {
public void destroy() { public void destroy() {
synchronized ( inputs ) { synchronized ( inputs ) {
for (int i = 0; i < inputs.length; i++) { for (int i = 0; i < inputs.length; i++) {
if (inputs[i].item != null) { if (inputs[i] != null && inputs[i].item != null) {
if (!inputs[i].item.collect()) { if (!inputs[i].item.collect()) {
Dungeon.level.drop(inputs[i].item, Dungeon.hero.pos); Dungeon.level.drop(inputs[i].item, Dungeon.hero.pos);
} }

View File

@ -213,7 +213,7 @@ public class WndBag extends WndTabbed {
} }
// Items in the bag // Items in the bag
for (Item item : container.items) { for (Item item : container.items.toArray(new Item[0])) {
placeItem( item ); placeItem( item );
} }