mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-16 08:03:42 +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()
|
||||||
|
.removeIf(renderer -> {
|
||||||
if (renderer.isDead()) {
|
if (renderer.isDead()) {
|
||||||
renderer.invalidate();
|
renderer.invalidate();
|
||||||
return true;
|
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