mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-28 16:06:28 +01:00
Fix nullpointer in ModelRenderer
- Somehow managed to only do a check in a subclass - Add #empty() helper method to IModel
This commit is contained in:
parent
e3b1172925
commit
60c85ec4f6
3 changed files with 25 additions and 22 deletions
|
@ -16,7 +16,7 @@ public class ArrayModelRenderer extends ModelRenderer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw() {
|
public void draw() {
|
||||||
if (!isInitialized()) init();
|
if (!initialized) init();
|
||||||
if (!isValid()) return;
|
if (!isValid()) return;
|
||||||
|
|
||||||
vao.bind();
|
vao.bind();
|
||||||
|
@ -26,16 +26,12 @@ public class ArrayModelRenderer extends ModelRenderer {
|
||||||
vao.unbind();
|
vao.unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isValid() {
|
|
||||||
return model != null && model.valid();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void init() {
|
protected void init() {
|
||||||
initialized = true;
|
initialized = true;
|
||||||
IModel model = modelSupplier.get();
|
IModel model = modelSupplier.get();
|
||||||
|
|
||||||
if (model.vertexCount() <= 0) return;
|
if (model.empty()) return;
|
||||||
|
|
||||||
this.model = new IndexedModel(model);
|
this.model = new IndexedModel(model);
|
||||||
|
|
||||||
|
|
|
@ -19,30 +19,29 @@ public class ModelRenderer {
|
||||||
* Renders this model, checking first if there is anything to render.
|
* Renders this model, checking first if there is anything to render.
|
||||||
*/
|
*/
|
||||||
public void draw() {
|
public void draw() {
|
||||||
|
if (!initialized) init();
|
||||||
if (!isInitialized()) init();
|
if (!isValid()) return;
|
||||||
if (!model.valid()) return;
|
|
||||||
|
|
||||||
model.setupState();
|
model.setupState();
|
||||||
model.drawCall();
|
model.drawCall();
|
||||||
model.clearState();
|
model.clearState();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void init() {
|
|
||||||
initialized = true;
|
|
||||||
IModel model = modelSupplier.get();
|
|
||||||
|
|
||||||
if (model.vertexCount() <= 0) return;
|
|
||||||
|
|
||||||
this.model = new IndexedModel(model);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isInitialized() {
|
|
||||||
return initialized;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void delete() {
|
public void delete() {
|
||||||
if (model != null)
|
if (model != null)
|
||||||
model.delete();
|
model.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void init() {
|
||||||
|
initialized = true;
|
||||||
|
IModel model = modelSupplier.get();
|
||||||
|
|
||||||
|
if (model.empty()) return;
|
||||||
|
|
||||||
|
this.model = new IndexedModel(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean isValid() {
|
||||||
|
return model != null && model.valid();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,4 +63,12 @@ public interface IModel {
|
||||||
default int size() {
|
default int size() {
|
||||||
return vertexCount() * format().getStride();
|
return vertexCount() * format().getStride();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is there nothing to render?
|
||||||
|
* @return true if there are no vertices.
|
||||||
|
*/
|
||||||
|
default boolean empty() {
|
||||||
|
return vertexCount() == 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue