Skip to content

Conversation

@ksuprynowicz
Copy link
Member

Fixes #1970

@ksuprynowicz ksuprynowicz added bug Something isn't working needs CR This pull request needs to be code reviewed needs QA This pull request needs to be tested labels Dec 27, 2025
Comment on lines +210 to +213
auto gpuTexture = _texture->getGPUTexture();
if (gpuTexture != nullptr) {
_texture->getGPUTexture()->setSampler(sampler);
}
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?

Comment on lines +210 to 215
auto gpuTexture = _texture->getGPUTexture();
if (gpuTexture != nullptr) {
_texture->getGPUTexture()->setSampler(sampler);
}
// It's ok to pass nullptr to setResourceTexture.
batch->setResourceTexture(0, _texture->getGPUTexture());
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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working needs CR This pull request needs to be code reviewed needs QA This pull request needs to be tested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash in setSampler

4 participants