Skip to content

Commit

Permalink
Add feature flag for material/instance destroy assert (#8411)
Browse files Browse the repository at this point in the history
This will allow a more lenient rollout of the assertion, which
otherwise will increase crashes for current clients.

We also disable features.engine.debug.assert_material_instance_in_use
by default (it was enabled for debug builds).
  • Loading branch information
poweifeng authored Feb 4, 2025
1 parent fff7bd2 commit a040199
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
11 changes: 6 additions & 5 deletions filament/src/details/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -690,11 +690,9 @@ class FEngine : public Engine {
bool use_shadow_atlas = false;
} shadows;
struct {
#ifndef NDEBUG
bool assert_material_instance_in_use = true;
#else
// TODO: default the following two flags to true.
bool assert_material_instance_in_use = false;
#endif
bool assert_destroy_material_before_material_instance = false;
} debug;
} engine;
struct {
Expand All @@ -721,7 +719,10 @@ class FEngine : public Engine {
&features.engine.shadows.use_shadow_atlas, false },
{ "features.engine.debug.assert_material_instance_in_use",
"Assert when a MaterialInstance is destroyed while it is in use by RenderableManager.",
&features.engine.debug.assert_material_instance_in_use, false }
&features.engine.debug.assert_material_instance_in_use, false },
{ "features.engine.debug.assert_destroy_material_before_material_instance",
"Assert when a Material is destroyed but its instances are still alive.",
&features.engine.debug.assert_destroy_material_before_material_instance, false },
}};

utils::Slice<const FeatureFlag> getFeatureFlags() const noexcept {
Expand Down
11 changes: 8 additions & 3 deletions filament/src/details/Material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,14 @@ void FMaterial::terminate(FEngine& engine) {
auto const& materialInstanceResourceList = engine.getMaterialInstanceResourceList();
auto pos = materialInstanceResourceList.find(this);
if (UTILS_LIKELY(pos != materialInstanceResourceList.cend())) {
FILAMENT_CHECK_PRECONDITION(pos->second.empty())
<< "destroying material \"" << this->getName().c_str_safe() << "\" but "
<< pos->second.size() << " instances still alive.";
if (engine.features.engine.debug.assert_destroy_material_before_material_instance) {
FILAMENT_CHECK_PRECONDITION(pos->second.empty())
<< "destroying material \"" << this->getName().c_str_safe() << "\" but "
<< pos->second.size() << " instances still alive.";
} else {
utils::slog.e << "destroying material \"" << this->getName().c_str_safe() << "\" but "
<< pos->second.size() << " instances still alive.";
}
}


Expand Down

0 comments on commit a040199

Please sign in to comment.