Skip to content

Commit

Permalink
Fix NPE ticking weatherEffects for #845
Browse files Browse the repository at this point in the history
Signed-off-by: Ross Allan <rallanpcl@gmail.com>
  • Loading branch information
LunNova committed Jul 4, 2013
1 parent 2c711fd commit 17e901b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 31 deletions.
1 change: 1 addition & 0 deletions resources/patches.xml
Expand Up @@ -108,6 +108,7 @@
<public field="ambientTickCountdown"/>
<public field="forcedChunks"/>
<replaceInitializer field="playerEntities" class="java.util.concurrent.CopyOnWriteArrayList"/>
<replaceInitializer field="weatherEffects" class="nallar.collections.SynchronizedList"/>
<insertBefore code="if (preHandleSpawn($1)) { return false; }">spawnEntityInWorld</insertBefore>
<removeMethod>forceChunk,unforceChunk</removeMethod>
</class>
Expand Down
64 changes: 33 additions & 31 deletions src/common/nallar/patched/world/PatchWorld.java
Expand Up @@ -705,30 +705,32 @@ public void updateEntities() {
final Profiler theProfiler = this.theProfiler;
theProfiler.startSection("updateEntities");
int var1;
Entity var2;
Entity weatherEffect;
CrashReport var4;
CrashReportCategory var5;

theProfiler.startSection("global");
final List weatherEffects = this.weatherEffects;
for (var1 = 0; var1 < weatherEffects.size(); ++var1) {
var2 = (Entity) weatherEffects.get(var1);

try {
++var2.ticksExisted;
var2.onUpdate();
} catch (Throwable var6) {
var4 = CrashReport.makeCrashReport(var6, "Ticking entity");
var5 = var4.makeCategory("Entity being ticked");
if (var2 != null) {
var2.func_85029_a(var5);
final List<Entity> weatherEffects = this.weatherEffects;
synchronized (weatherEffects) {
Iterator<Entity> iterator = weatherEffects.iterator();
while (iterator.hasNext()) {
weatherEffect = iterator.next();

if (weatherEffect == null) {
iterator.remove();
continue;
}

throw new ReportedException(var4);
}
try {
++weatherEffect.ticksExisted;
weatherEffect.onUpdate();
} catch (Throwable t) {
Log.severe("Failed to tick weather " + Log.toString(weatherEffect), t);
}

if (var2 == null || var2.isDead) {
weatherEffects.remove(var1--);
if (weatherEffect.isDead) {
iterator.remove();
}
}
}

Expand Down Expand Up @@ -759,26 +761,26 @@ public void updateEntities() {
unloadedEntitySet.clear();
theProfiler.endStartSection("entities");
for (var1 = 0; var1 < loadedEntityList.size(); ++var1) {
var2 = (Entity) loadedEntityList.get(var1);
weatherEffect = (Entity) loadedEntityList.get(var1);

if (var2.ridingEntity != null) {
if (!var2.ridingEntity.isDead && var2.ridingEntity.riddenByEntity == var2) {
if (weatherEffect.ridingEntity != null) {
if (!weatherEffect.ridingEntity.isDead && weatherEffect.ridingEntity.riddenByEntity == weatherEffect) {
continue;
}

var2.ridingEntity.riddenByEntity = null;
var2.ridingEntity = null;
weatherEffect.ridingEntity.riddenByEntity = null;
weatherEffect.ridingEntity = null;
}

theProfiler.startSection("tick");

if (!var2.isDead) {
if (!weatherEffect.isDead) {
try {
updateEntity(var2);
updateEntity(weatherEffect);
} catch (Throwable var7) {
var4 = CrashReport.makeCrashReport(var7, "Ticking entity");
var5 = var4.makeCategory("Entity being ticked");
var2.func_85029_a(var5);
weatherEffect.func_85029_a(var5);

throw new ReportedException(var4);
}
Expand All @@ -787,19 +789,19 @@ public void updateEntities() {
theProfiler.endSection();
theProfiler.startSection("remove");

if (var2.isDead) {
var3 = var2.chunkCoordX;
var13 = var2.chunkCoordZ;
if (weatherEffect.isDead) {
var3 = weatherEffect.chunkCoordX;
var13 = weatherEffect.chunkCoordZ;

if (var2.addedToChunk) {
if (weatherEffect.addedToChunk) {
Chunk chunk = getChunkIfExists(var3, var13);
if (chunk != null) {
chunk.removeEntity(var2);
chunk.removeEntity(weatherEffect);
}
}

loadedEntityList.remove(var1--);
releaseEntitySkin(var2);
releaseEntitySkin(weatherEffect);
}

theProfiler.endSection();
Expand Down

0 comments on commit 17e901b

Please sign in to comment.