Engine crashes when stop simulating while a dynamic material instance is being set to a sprite component

Hello, I’m using UE 5.3.2 and I’m experiencing an issue in which if you stop simulating (press ESC), while set a parameter of a dynamic material instance in event tick (or in a timeline, or quick timer), the engine crashes, here is the log (with symbols installed):

Assertion failed: Index>=0 && Index<NumBits [File:D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Public\Containers\BitArray.h] [Line: 1418]

UnrealEditor_Core!FOutputDeviceRedirector::Panic() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Private\Misc\OutputDeviceRedirector.cpp:773]
UnrealEditor_Core!ReportCrash() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Private\Windows\WindowsPlatformCrashContext.cpp:1610]
UnrealEditor_RenderCore!`FRenderingThread::Run'::`1'::filt$0() [D:\build\++UE5\Sync\Engine\Source\Runtime\RenderCore\Private\RenderingThread.cpp:539]
VCRUNTIME140
ntdll
ntdll
ntdll
UnrealEditor_Engine!FMaterialRenderProxy::UpdateDeferredCachedUniformExpressions() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\Materials\MaterialRenderProxy.cpp:680]
UnrealEditor_Renderer!FScene::UpdateAllPrimitiveSceneInfos() [D:\build\++UE5\Sync\Engine\Source\Runtime\Renderer\Private\RendererScene.cpp:5356]
UnrealEditor_Engine!FSceneInterface::UpdateAllPrimitiveSceneInfos() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\SceneInterface.cpp:17]
UnrealEditor_Renderer!TEnqueueUniqueRenderCommandType<`FScene::Release'::`2'::FReleaseCommandName,`FScene::Release'::`2'::<lambda_3> >::DoTask() [D:\build\++UE5\Sync\Engine\Source\Runtime\RenderCore\Public\RenderingThread.h:209]
UnrealEditor_Renderer!TGraphTask<TEnqueueUniqueRenderCommandType<`FScene::Release'::`2'::FReleaseCommandName,`FScene::Release'::`2'::<lambda_3> > >::ExecuteTask() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Public\Async\TaskGraphInterfaces.h:1265]
UnrealEditor_Core!FNamedTaskThread::ProcessTasksNamedThread() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Private\Async\TaskGraph.cpp:758]
UnrealEditor_Core!FNamedTaskThread::ProcessTasksUntilQuit() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Private\Async\TaskGraph.cpp:649]
UnrealEditor_RenderCore!RenderingThreadMain() [D:\build\++UE5\Sync\Engine\Source\Runtime\RenderCore\Private\RenderingThread.cpp:411]
UnrealEditor_RenderCore!FRenderingThread::Run() [D:\build\++UE5\Sync\Engine\Source\Runtime\RenderCore\Private\RenderingThread.cpp:537]
UnrealEditor_Core!FRunnableThreadWin::Run() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Private\Windows\WindowsRunnableThread.cpp:149]

Some notes:

  • I’ve Already reinstalled the engine and visual studio

  • It only seems to happen with sprite components, trying the same with a static mesh component for exemple do not have this issue

Launching the project in debug mode with visual studio, the first breakpoint of the crash happens in this file and function:

File: MaterialRenderProxy.cpp

Function: (Line 659)void FMaterialRenderProxy::UpdateDeferredCachedUniformExpressions()

Line: (Line 683) const FMaterial* Material = MaterialProxy->GetMaterialNoFallback(InFeatureLevel);

Steps to reproduce in a clean project:

  • Create a new actor an add a Sprite Component

  • On Begin Play create a dynamic material instance and set the sprite material

  • On Tick (or in a timeline, or quick timer) set a parameter of the Dynamic Material

  • Place the Actor in the Level and Play

  • Stop Simulating (Press Esc)

Sometimes it will take a couple of attempts for the crash to happen, sometimes it will be first try.

Any help or workaroud will be highly apreciated, as this is greatly slowing the development of my project. Thanks.

4 Likes

Hey there @RodrigoFMello11! Welcome to the community! It’s reproducible with only sprites it seems. Other materials don’t seem to cause it, and it’s still yet inconsistent with sprites. Looks like a bug, you can report those here:

Thanks, I’ve reported the bug. But since it is related to Paper2D I don’t expect it to be fixed any time soon. So if someone have a workaround I would be very thankful, as this issue is greatly slowing the development of my project

Have same issue. UE 5.3.2, Paper2D, Not the dymanic material instance but “Set material parameter” to change color of a Paper2D Sprite. Engine crash randomly after quitting PIE preview. seems it will crash when you quitting and a parameter changed in same tick.

Scratching my head for days and still have no solution. Dev guys should really fit some Paper2D bugs. Reported and waiting.

For me it just crash in engine, standalone or build game are stable without problem, But still very annoying at working.

1 Like

By inserting the C++ code below into the EndPlay function of a certain class, the crash no longer occurs.

#include "Materials/MaterialRenderProxy.h"

void ASampleViewer::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
	Super::EndPlay(EndPlayReason);

#if WITH_EDITOR
	if (EndPlayReason == EEndPlayReason::EndPlayInEditor)
	{
		FUniformExpressionCacheAsyncUpdateScope AsyncUpdateScope;
	}
#endif
}

There is no doubt that this is not the correct way to deal with it, but I have found a way to avoid it as a workaround, so I would like to share it with you.

3 Likes

Sorry for bringing this back up, but does anyone have any idea of how this might be resolved in Blueprints? Like OP, it seems to only have started occurring when I added an emissive color to a custom sprite material that is applied to a Paper2d sprite.

I’m so glad I found this forum post as I can at least disable the effect for now, but I would love to implement it back in if possible.

What is interesting is it would crash even if I didn’t trigger the emissive color.

Any suggestions on how I might be able to implement the same C++ workaround but in BP?

Thanks in advance!

Hey there @8bitSami! Welcome to the community! Unfortunately this workaround is only viable using C++ as it would have to be injected into the base class itself.

Thanks, going to try it, although none of my class are C++ based, it is worth converting them to C++, since this problem is really slowing the development of the project. Hopefuly this will be solved in UE 5.4

Thanks! You saved my life!!

I have 0 experience in C++, and have no idea what this code does, so pardon me if I am asking something that does not make sense.

Is it possible for me to include an object that just runs this code and nothing else to mitigate the issue?

Leaving this here so that poor souls like me who know nothing about C++ can implement the proposed workaround.
Huge Disclaimer: I know nothing about C++, so use it at your own risk.

Steps to implement proposed workaround:

  1. Tools > New C++Class
  2. Name it as SampleViewer (I chose this name because of proposed solution)
  3. Use Actor Class as base
  4. In SampleViewer.cpp,
    4.1 Add #include "Materials/MaterialRenderProxy.h" below #include "SampleViewer.h"
    4.2 Paste the rest of the code below BeginPlay()
    4.3 Visual Studio will prompt you to create EndPlay() in SampleView.h. Use it.
    4.4 Check out the screenshots if these are too confusing
  5. Save
  6. In Unreal Engine Editor, recompile
  7. Create new Blueprint Class
    7.1 Under ALL CLASSES, select newly created SampleViewer
    7.2 Place it anywhere in the Editor

It seems to work fine so far, so kudos to the solution.

Below is what the end result looks like in code:


1 Like