Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash an application when setting not exist material parameters on ubershader #6121

Closed
daemyung opened this issue Sep 29, 2022 · 1 comment · Fixed by #6122
Closed

Crash an application when setting not exist material parameters on ubershader #6121

daemyung opened this issue Sep 29, 2022 · 1 comment · Fixed by #6122
Assignees
Labels
bug Something isn't working gltf Specific to glTF support

Comments

@daemyung
Copy link
Contributor

daemyung commented Sep 29, 2022

Describe the bug
Crash an application when setting not exist material parameters. Material comes from ubershader.

To Reproduce
Steps to reproduce the behavior:

  1. Prepare a GLTF model that has material properties. This material causes a crash.
  2. Run gltf_viewer with ubershader

Sorry I can't share this model file. But this crash is happened if hasIOR is true.

(filament::gltfio::MaterialKey) $0 = {
  doubleSided = true
  unlit = false
  hasVertexColors = true
  hasBaseColorTexture = false
  hasNormalTexture = false
  hasOcclusionTexture = false
  hasEmissiveTexture = false
  useSpecularGlossiness = false
  alphaMode = OPAQUE
  enableDiagnostics = false
   = {
     = (hasMetallicRoughnessTexture = false, metallicRoughnessUV = 0 '\0')
     = (hasSpecularGlossinessTexture = false, specularGlossinessUV = 0 '\0')
  }
  baseColorUV = '\0' 0 '\0'
  hasClearCoatTexture = false
  clearCoatUV = '\0' 0 '\0'
  hasClearCoatRoughnessTexture = false
  clearCoatRoughnessUV = '\0' 0 '\0'
  hasClearCoatNormalTexture = false
  clearCoatNormalUV = '\0' 0 '\0'
  hasClearCoat = false
  hasTransmission = false
  hasTextureTransforms = false
  emissiveUV = '\0' 0 '\0'
  aoUV = '\0' 0 '\0'
  normalUV = '\0' 0 '\0'
  hasTransmissionTexture = false
  transmissionUV = '\0' 0 '\0'
  hasSheenColorTexture = false
  sheenColorUV = '\0' 0 '\0'
  hasSheenRoughnessTexture = false
  sheenRoughnessUV = '\0' 0 '\0'
  hasVolumeThicknessTexture = false
  volumeThicknessUV = '\0' 0 '\0'
  hasSheen = false
  hasIOR = true
  hasVolume = false
  padding = '\0' 0 '\0'
}

Expected behavior
Load a GLTF model and run well.

Logs

utils::PreconditionPanic
in const SamplerInterfaceBlock::SamplerInfo *filament::SamplerInterfaceBlock::getSamplerInfo(std::string_view) const:97
in file filament/libs/filabridge/src/SamplerInterfaceBlock.cpp
reason: sampler named "clearCoatMap" not found
#0	0x1011147ac utils::CallStack::update(unsigned long) + 32
#1	0x1011308d0 utils::TPanic<utils::PreconditionPanic>::TPanic(char const*, char const*, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) + 168
#2	0x101131c84 utils::PreconditionPanic::PreconditionPanic(char const*, char const*, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) + 68
#3	0x101130478 utils::PreconditionPanic::PreconditionPanic(char const*, char const*, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) + 52
#4	0x101130244 utils::TPanic<utils::PreconditionPanic>::panic(char const*, char const*, int, char const*, ...) + 228
#5	0x101109714 filament::SamplerInterfaceBlock::getSamplerInfo(std::__1::basic_string_view<char, std::__1::char_traits<char> >) const + 176
#6	0x100fa55ec filament::FMaterialInstance::setParameter(std::__1::basic_string_view<char, std::__1::char_traits<char> >, filament::backend::Handle<filament::backend::HwTexture>, filament::backend::SamplerParams) + 76
#7	0x100fa57e0 filament::FMaterialInstance::setParameterImpl(std::__1::basic_string_view<char, std::__1::char_traits<char> >, filament::FTexture const*, filament::TextureSampler const&) + 428
#8	0x100f024c8 filament::MaterialInstance::setParameter(char const*, unsigned long, filament::Texture const*, filament::TextureSampler const&) + 92
#9	0x100fcd6bc filament::MaterialInstance::setParameter(char const*, filament::Texture const*, filament::TextureSampler const&) + 76
#100x101241988 (anonymous namespace)::UbershaderProvider::createMaterialInstance(filament::gltfio::MaterialKey*, std::__1::array<filament::gltfio::UvSet, 8ul>*, char const*, char const*) + 2080
#110x10118c858 filament::gltfio::FAssetLoader::createMaterialInstance(cgltf_data const*, cgltf_material const*, std::__1::array<filament::gltfio::UvSet, 8ul>*, bool) + 452
#120x101189dd4 filament::gltfio::FAssetLoader::createRenderable(cgltf_data const*, cgltf_node const*, utils::Entity, char const*) + 656
#130x101189160 filament::gltfio::FAssetLoader::recurseEntities(cgltf_data const*, cgltf_node const*, utils::bitset<unsigned int, 1ul, void>, utils::Entity, filament::gltfio::FFilamentInstance*) + 964
#140x101189278 filament::gltfio::FAssetLoader::recurseEntities(cgltf_data const*, cgltf_node const*, utils::bitset<unsigned int, 1ul, void>, utils::Entity, filament::gltfio::FFilamentInstance*) + 1244
#150x101187b9c filament::gltfio::FAssetLoader::createInstance(cgltf_data const*) + 528
#160x101187560 filament::gltfio::FAssetLoader::createInstances(cgltf_data const*, unsigned long) + 72
#170x101186c2c filament::gltfio::FAssetLoader::createInstancedAsset(unsigned char const*, unsigned int, filament::gltfio::FilamentInstance**, unsigned long) + 416

Additional context
If the material key is like below

(filament::gltfio::MaterialKey) $0 = {
  doubleSided = true
  unlit = false
  hasVertexColors = true
  hasBaseColorTexture = false
  hasNormalTexture = false
  hasOcclusionTexture = false
  hasEmissiveTexture = false
  useSpecularGlossiness = false
  alphaMode = OPAQUE
  enableDiagnostics = false
   = {
     = (hasMetallicRoughnessTexture = false, metallicRoughnessUV = 0 '\0')
     = (hasSpecularGlossinessTexture = false, specularGlossinessUV = 0 '\0')
  }
  baseColorUV = '\0' 0 '\0'
  hasClearCoatTexture = false
  clearCoatUV = '\0' 0 '\0'
  hasClearCoatRoughnessTexture = false
  clearCoatRoughnessUV = '\0' 0 '\0'
  hasClearCoatNormalTexture = false
  clearCoatNormalUV = '\0' 0 '\0'
  hasClearCoat = false
  hasTransmission = false
  hasTextureTransforms = false
  emissiveUV = '\0' 0 '\0'
  aoUV = '\0' 0 '\0'
  normalUV = '\0' 0 '\0'
  hasTransmissionTexture = false
  transmissionUV = '\0' 0 '\0'
  hasSheenColorTexture = false
  sheenColorUV = '\0' 0 '\0'
  hasSheenRoughnessTexture = false
  sheenRoughnessUV = '\0' 0 '\0'
  hasVolumeThicknessTexture = false
  volumeThicknessUV = '\0' 0 '\0'
  hasSheen = false
  hasIOR = true
  hasVolume = false
  padding = '\0' 0 '\0'
}

then a queried material from ubershader has the sampler interface block like below.

(const filament::SamplerInterfaceBlock) $0 = {
  mName = {
     = {
      mCStr = 0x00006000009a0e44 "MaterialParams"
      mData = 0x00006000009a0e44
    }
  }
  mStageFlags = ALL_SHADER_STAGE_FLAGS
  mSamplersInfoList = {
    mData = 0x0000600003efb860
    mSize = 7
    mCapacityAllocator = {
      utils::FixedCapacityVector<filament::SamplerInterfaceBlock::SamplerInfo, std::__1::allocator<filament::SamplerInterfaceBlock::SamplerInfo>, true>::SizeTypeWrapper<unsigned int> = (value = 7)
    }
  }
  mInfoMap = size=7 {
    [0] = (first = "volumeThicknessMap", second = 6)
    [1] = (first = "transmissionMap", second = 5)
    [2] = (first = "normalMap", second = 2)
    [3] = (first = "occlusionMap", second = 3)
    [4] = (first = "metallicRoughnessMap", second = 1)
    [5] = (first = "emissiveMap", second = 4)
    [6] = (first = "baseColorMap", second = 0)
  }
}
@daemyung
Copy link
Contributor Author

daemyung commented Sep 29, 2022

I create #6122 and this changes fix this crash. But I'm not sure it's a correct fix. Because both options can be used at the same time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working gltf Specific to glTF support
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants