mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-27 07:26:48 +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
|
||||
public void draw() {
|
||||
if (!isInitialized()) init();
|
||||
if (!initialized) init();
|
||||
if (!isValid()) return;
|
||||
|
||||
vao.bind();
|
||||
|
@ -26,16 +26,12 @@ public class ArrayModelRenderer extends ModelRenderer {
|
|||
vao.unbind();
|
||||
}
|
||||
|
||||
private boolean isValid() {
|
||||
return model != null && model.valid();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
initialized = true;
|
||||
IModel model = modelSupplier.get();
|
||||
|
||||
if (model.vertexCount() <= 0) return;
|
||||
if (model.empty()) return;
|
||||
|
||||
this.model = new IndexedModel(model);
|
||||
|
||||
|
|
|
@ -19,30 +19,29 @@ public class ModelRenderer {
|
|||
* Renders this model, checking first if there is anything to render.
|
||||
*/
|
||||
public void draw() {
|
||||
|
||||
if (!isInitialized()) init();
|
||||
if (!model.valid()) return;
|
||||
if (!initialized) init();
|
||||
if (!isValid()) return;
|
||||
|
||||
model.setupState();
|
||||
model.drawCall();
|
||||
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() {
|
||||
if (model != null)
|
||||
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() {
|
||||
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