mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-29 08:27:03 +01:00
Fix nullpointer when contraptions stop
This commit is contained in:
parent
c674b5df8d
commit
468435e1a0
2 changed files with 19 additions and 8 deletions
|
@ -50,13 +50,17 @@ public abstract class ContraptionRenderManager<C extends ContraptionRenderInfo>
|
||||||
}
|
}
|
||||||
|
|
||||||
public void beginFrame(BeginFrameEvent event) {
|
public void beginFrame(BeginFrameEvent event) {
|
||||||
visible.clear();
|
|
||||||
|
|
||||||
renderInfos.int2ObjectEntrySet()
|
renderInfos.int2ObjectEntrySet()
|
||||||
.stream()
|
.stream()
|
||||||
.map(Map.Entry::getValue)
|
.map(Map.Entry::getValue)
|
||||||
.forEach(renderInfo -> renderInfo.beginFrame(event));
|
.forEach(renderInfo -> renderInfo.beginFrame(event));
|
||||||
|
|
||||||
|
collectVisible();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void collectVisible() {
|
||||||
|
visible.clear();
|
||||||
renderInfos.int2ObjectEntrySet()
|
renderInfos.int2ObjectEntrySet()
|
||||||
.stream()
|
.stream()
|
||||||
.map(Map.Entry::getValue)
|
.map(Map.Entry::getValue)
|
||||||
|
@ -80,6 +84,9 @@ public abstract class ContraptionRenderManager<C extends ContraptionRenderInfo>
|
||||||
renderInfos.clear();
|
renderInfos.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove all render infos associated with dead/removed contraptions.
|
||||||
|
*/
|
||||||
public void removeDeadRenderers() {
|
public void removeDeadRenderers() {
|
||||||
renderInfos.values().removeIf(ContraptionRenderInfo::isDead);
|
renderInfos.values().removeIf(ContraptionRenderInfo::isDead);
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,13 +80,17 @@ public class FlwContraptionManager extends ContraptionRenderManager<RenderedCont
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeDeadRenderers() {
|
public void removeDeadRenderers() {
|
||||||
renderInfos.values().removeIf(renderer -> {
|
boolean removed = renderInfos.values()
|
||||||
if (renderer.isDead()) {
|
.removeIf(renderer -> {
|
||||||
renderer.invalidate();
|
if (renderer.isDead()) {
|
||||||
return true;
|
renderer.invalidate();
|
||||||
}
|
return true;
|
||||||
return false;
|
}
|
||||||
});
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
// we use visible in #tick() so we have to re-evaluate it if any were removed
|
||||||
|
if (removed) collectVisible();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue