Hello,
We make extensive use of view models on our HUD. Several of our widgets rely on view models with their creation type set to Manual.
After upgrading from Unreal Engine 5.4 to 5.5 (specifically 5.5.4), we started encountering the following ensure message when the HUD is created a second time:
Ensure condition failed: bIsPointerValid == bIsBitfieldValid [C:\UE\Engine\Plugins\Runtime\ModelViewViewModel\Source\ModelViewViewModel\Private\View\MVVMView.cpp] [Line: 412]
The source SOMEVIEWMODEL should be valid.
Upon debugging, we found that MVVMView extensions are now being reused during the second creation of the HUD. As a result, some internal states are no longer reset to their defaults. Specifically, for each ViewSource, the bSetManually flag remains true. This causes a different code path to be followed during Construct, ultimately leading to the ensure failure.
To address this, we modified the UninitializeSource function to reset the state of all ViewSources, regardless of whether they were set manually. However, we only release the ViewSource instance if it wasn’t manually set.
Additionally, we reset the ViewSource.RegisteredCount to 0 in UMVVMView::UninitializeSourceBindings.
That said, we’re still unsure if this is the correct approach. Previously, this issue didn’t occur because MVVMView was recreated along with the widget. Now that it’s reused, the problem surfaces.
Below is our modified UninitializeSource function:
`void UMVVMView::UninitializeSource(FMVVMView_SourceKey SourceKey)
{
FMVVMView_Source& ViewSource = Sources[SourceKey.GetIndex()];
const FMVVMViewClass_Source& ClassSource = GeneratedViewClass->GetSource(ViewSource.ClassKey);
if (ViewSource.bSourceInitialized)
{
ViewSource.bSourceInitialized = false;
if (!ViewSource.bSetManually)
{
ClassSource.ReleaseInstance(ViewSource.Source, this);
}
ViewSource.bSetManually = false;
ViewSource.Source = nullptr;
if (ViewSource.bAssignedToUserWidgetProperty)
{
UUserWidget* UserWidget = GetUserWidget();
FObjectPropertyBase* FoundObjectProperty = FindFProperty(UserWidget->GetClass(), ClassSource.GetUserWidgetPropertyName());
if (ensureAlwaysMsgf(FoundObjectProperty, TEXT(“The compiler should have added the property”)))
{
FoundObjectProperty->SetObjectPropertyValue_InContainer(UserWidget, nullptr);
}
ViewSource.bAssignedToUserWidgetProperty = false;
}
ValidSources &= ~ViewSource.ClassKey.GetBit();
#if UE_WITH_MVVM_DEBUGGING
UE::MVVM::FDebugging::BroadcastViewSourceValueChanged(this, ViewSource.ClassKey, SourceKey);
#endif
}
}`