Filament: macOS encountered a N5utils18PostconditionPanicE with backedColor material in Metal mode

Created on 27 Feb 2020  Â·  8Comments  Â·  Source: google/filament

Describe the bug

Sorry to bother again. I continue to play with macOS (Catalina) and noticed that if I try to create a material with a simple backedColor like below:

// matc -o bakedColor.inc -f header bakedColor.mat
static constexpr uint8_t BAKED_COLOR_PACKAGE[] = {
    #include "bakedColor.inc"
};
...
  filament::Material* pMaterial = filament::Material::Builder()
        .package((void*) BAKED_COLOR_PACKAGE, sizeof(BAKED_COLOR_PACKAGE))
        .build(*pEngine);
  filament::MaterialInstance* pMaterialInstance = pMaterial->createInstance();

then in Metal mode the following error happens:

% ./demo 
Filament library loaded.
FEngine (64 bits) created at 0x10ee10000 (threading is enabled)
FEngine resolved backend: Metal
N5utils18PostconditionPanicE
in static filament::MaterialParser *filament::details::FMaterial::createParser(backend::Backend, const void *, size_t):493
reason: could not parse the material package

libc++abi.dylib: terminating with uncaught exception of type utils::PostconditionPanic
zsh: abort      ./demo

Note if I switch to OpenGL mode then the crash is gone.

To Reproduce
Steps to reproduce the behavior:

  1. The sample code is located in https://github.com/yongtang/demo
  2. In the directory I created a Makefile so bazel install is not needed.
  3. Download the artifact from the latest build. Note I downloaded the build from #2173 to make sure it is the latest from master. Then uncompress the artifact into the current directory so that the file structure is:
    demo.cc Makefile filament/ bin/ include/ lib/
  4. Invoke make to build the binary:
    % make
  5. Invoke the program:
    ```
    % ./demo
    Filament library loaded.
    FEngine (64 bits) created at 0x10ee10000 (threading is enabled)
    FEngine resolved backend: Metal
    N5utils18PostconditionPanicE
    in static filament::MaterialParser *filament::details::FMaterial::createParser(backend::Backend, const void *, size_t):493
    reason: could not parse the material package

libc++abi.dylib: terminating with uncaught exception of type utils::PostconditionPanic
zsh: abort ./demo
```

  1. Open demo.cc and switch to OpenGL mode (see comment in demo.cc), and build again.
  2. The program runs without the above crash.

Expected behavior

The program is expected to run in both Metal and OpenGL mode.

Screenshots
n/a

Desktop (please complete the following information):

  • OS: macOS Catalina
  • GPU: Intel UHD Graphics
  • Backend: OpenGL works, Metal crashes.
bug macos metal

Most helpful comment

By default, matc only compiles materials for the OpenGL backend. To compile for Metal as well, update the arguments to:

filament/bin/matc -a opengl -a metal -o bakedColor.inc -f header bakedColor.mat

That fixes the crash.

All 8 comments

All of our Metal samples work (and they all load unlit materials). Did you build matc yourself or is it a prebuilt? We made recent changes to materials which breaks compatibility with older matc versions.

Although I think we stopped using the header file forma for materials, maybe there's something broken there? We now use resgen instead.

@romainguy I download the matc from the same artifact in #2173 and the program I build is linked to the same library in the artifact. The bakedColor.mat file is from the sample directory in filament (https://github.com/google/filament/blob/master/samples/materials/bakedColor.mat)

material {
    name : bakedColor,
    requires : [
        color
    ],
    shadingModel : unlit,
    culling : none
}

fragment {
    void material(inout MaterialInputs material) {
        prepareMaterial(material);
        material.baseColor = getColor();
    }
}

Although I think we stopped using the header file forma for materials, maybe there's something broken there? We now use resgen instead.

@romainguy wondering if there is some "getting started" documentation about C++? I saw documentations in other languages but couldn't find a C++ documentation to get started. (The filament/samples directory has quite some library dependencies like SDL, not very easy to follow without prior background).

Unfortunately the best "getting started" is in our README and not terribly useful. Check out the README of resgen, it might explain how to use it (resgen generates a .S file and a header file from a binary — it can be a material or anything else — and thus offers a much more efficient way to embed binaries compared to the #include solution you're using).

By default, matc only compiles materials for the OpenGL backend. To compile for Metal as well, update the arguments to:

filament/bin/matc -a opengl -a metal -o bakedColor.inc -f header bakedColor.mat

That fixes the crash.

@bejado The updated command fixed the issue, thanks for the help!

@romainguy Thanks for the pointers. I will take a look at resgen.

@bejado We should probably improve the error message to indicate the material doesn't contain shaders for the selected backend (which I believe we used to have?)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yongtang picture yongtang  Â·  5Comments

molysgaard picture molysgaard  Â·  6Comments

Y0hy0h picture Y0hy0h  Â·  5Comments

NathanBWaters picture NathanBWaters  Â·  6Comments

cx20 picture cx20  Â·  5Comments