Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,11 @@ void ImageEntityRenderer::doRender(RenderArgs* args) {
auto procedural = std::static_pointer_cast<graphics::ProceduralMaterial>(materials.top().material);
procedural->prepare(*batch, transform.getTranslation(), transform.getScale(), transform.getRotation(), _created, ProceduralProgramKey(transparent));
} else if (pipelineType == Pipeline::SIMPLE) {
_texture->getGPUTexture()->setSampler(sampler);
auto gpuTexture = _texture->getGPUTexture();
if (gpuTexture != nullptr) {
_texture->getGPUTexture()->setSampler(sampler);
}
Comment on lines +210 to +213
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I right in the assumption that we try to render an image entity without knowing if the texture is loaded yet, and that is what is causing getGPUTexture() to return nullptr?
I am assuming that the texture is loaded by something else, while we are building the batch, and it is easier to just try and use it rather than only trying to render things that are finished loading?
I can see that we set setResourceTexture()'s texture to nullptr quite often in our code, so it must be intentional, right?

// It's ok to pass nullptr to setResourceTexture.
batch->setResourceTexture(0, _texture->getGPUTexture());
Comment on lines +210 to 215
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great catch - sorry for not noticing this. I might suggest a simpler fix of just early exiting:

Suggested change
auto gpuTexture = _texture->getGPUTexture();
if (gpuTexture != nullptr) {
_texture->getGPUTexture()->setSampler(sampler);
}
// It's ok to pass nullptr to setResourceTexture.
batch->setResourceTexture(0, _texture->getGPUTexture());
auto gpuTexture = _texture->getGPUTexture();
if (!gpuTexture) {
return;
}
gpuTexture->setSampler(sampler);
batch->setResourceTexture(0, gpuTexture);

while calling setResourceTexture with nullptr is totally safe, it means we're still doing a draw call with an unset texture, which probably isn't desirable.

this is also closer to the intention of the early exit on line 142. in fact, a lot of that logic above should probably be brought into this if (pipelineType == Pipeline::SIMPLE) case, since procedural + material paths don't actually use _texture, but no one is really using those anyways...

} else if (pipelineType == Pipeline::MATERIAL) {
color = glm::vec4(1.0f); // for model shaders, albedo comes from the material instead of vertex colors
Expand Down
Loading