4.7.5 Slate Brush Resource- Becomes null after 30 sec

Hi,

I have a strange issue:
In my C++ widget construct function I doing:

TSharedRef<FSlateGameResources> SlateResources = FSlateGameResources::New(FName("MyStyle"), "/Game/UI", "/Game/UI");
FSlateGameResources& MyStyle= SlateResources.Get();
const FSlateBrush* ScoreBrush = MyStyle.GetBrush(FName("/InGame/Score/Score_Brush"));

after, I’m using the brush with

SNew(SImage).Image(ScoreBrush)

Once my widget is set on the screen, I’m just have to wait for 30Sec for the game to crash.
This is only happening in standalone game and not in PIE.

Here is the log:
[2015.04.15-21.21.55:194][456]LogWindows: === Critical error: ===
Fatal error!

Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0xffffffff

UE4Editor-CoreUObject.dll!UObjectBaseUtility::IsA() (0x000007fedcc5600f) + 0 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\coreuobject\private\uobject\uobjectbaseutility.cpp:254]
UE4Editor-SlateRHIRenderer.dll!FSlateRHIResourceManager::GetShaderResource() (0x000007fed582adb5) + 34 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\slaterhirenderer\private\slaterhiresourcemanager.cpp:388]
UE4Editor-SlateCore.dll!FSlateElementBatcher::AddBoxElement() (0x000007fed972ce30) + 16 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\slatecore\private\rendering\elementbatcher.cpp:220]
UE4Editor-SlateCore.dll!FSlateElementBatcher::AddElements() (0x000007fed973150c) + 0 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\slatecore\private\rendering\elementbatcher.cpp:86]
UE4Editor-SlateRHIRenderer.dll!FSlateRHIRenderer::DrawWindows_Private() (0x000007fed581eead) + 0 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\slaterhirenderer\private\slaterhirenderer.cpp:580]
UE4Editor-Slate.dll!FSlateApplication::PrivateDrawWindows() (0x000007fed9a22d41) + 73 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\slate\private\framework\application\slateapplication.cpp:1123]
UE4Editor-Slate.dll!FSlateApplication::Tick() (0x000007fed9a403ff) + 12 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\slate\private\framework\application\slateapplication.cpp:1323]
UE4Editor.exe!FEngineLoop::Tick() (0x000000013f2b036f) + 0 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\launch\private\launchengineloop.cpp:2284]
UE4Editor.exe!GuardedMain() (0x000000013f2a267c) + 0 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\launch\private\launch.cpp:142]
UE4Editor.exe!GuardedMainWrapper() (0x000000013f2a26ea) + 5 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\launch\private\windows\launchwindows.cpp:126]
UE4Editor.exe!WinMain() (0x000000013f2b2219) + 17 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\launch\private\windows\launchwindows.cpp:202]
UE4Editor.exe!__tmainCRTStartup() (0x000000013f2b3159) + 21 bytes [f:\dd\vctools\crt\crtw32\dllstuff\crtexe.c:618]
kernel32.dll!UnknownFunction (0x00000000770059ed) + 0 bytes [UnknownFile:0]
ntdll.dll!UnknownFunction (0x000000007723c541) + 0 bytes [UnknownFile:0]
ntdll.dll!UnknownFunction (0x000000007723c541) + 0 bytes [UnknownFile:0]

In fact from what I’m understanding, the brush is garbagge collected, so the Ressouce behind the brush is null and then it crash.

Thanks for your feedback

Can this be link to the fact that the Style is not registered in slate?

It’s the FSlateGameResources instance that stops the resources within the brushes from being GC’d, however it looks like you’re just creating that temporarily in your constructor and then throwing it away?

You can either store that as a member of your widget so that it stays alive as along as the widget needs it, or, and probably preferentially, you may to want to store that somewhere more centralised so that multiple widgets can grab their style information from it. FVehicleStyle from the VehicleGame sample provides an example of a centralised FSlateGameResources instance (it also adds in a font since it pre-dates the Slate composite font support, but you can probably just ignore that).

Thanks for the clarification.

Another topic link to that, how do you manage DynamicMaterialInstace in slate?
I mean I’m able to retrieve the MaterialBrush, get the ressource behind it to create a DynamicMaterialInstance but I have an issue when the widget is destroyed.

In fact, when you create a DMI yo need to specify a UObject as the outer, so I used the HUD Uobject as the Slate Widget classes are Raw C++.
But, I can’t find a way to clean this properly and not crash when my Widget is destroyed.

Thanks,

Slate does not manage dynamic material instances for you. You need to do that yourself. The standard method is to reference your dynamic material instance on another UObject so it is not destroyed by garbage collection. When your widget is done with it you can null out the reference to the material on the other object to ensure it is released by garbage collection.

It is unclear how you are crashing so please provide some more info and the callstack.

I try to set to null th eDynamic material in the destructor, but it’s not called. it crash before.

here is the call stack:

[2015.04.16-18.35.36:899][531]LogReferenceChain: Generating reference chains …
[2015.04.16-18.35.36:900][531]LogReferenceChain:
[2015.04.16-18.35.36:900][531]LogReferenceChain: External Referencers:
[2015.04.16-18.35.36:901][531]LogReferenceChain:
[2015.04.16-18.35.36:902][531]LogReferenceChain: (root) (standalone) SlateBrushAsset /Game/UI/InGame/TeamInfos/NewSlateBrushAsset.NewSlateBrushAsset->ResourceObject
[2015.04.16-18.35.36:902][531]LogReferenceChain: MaterialInstanceDynamic /Game/Maps/Wip/UEDPIE_0_WipVM.WipVM:PersistentLevel.ZB4HUD_DOM_0.MaterialInstanceDynamic_30->Outer
[2015.04.16-18.35.36:903][531]LogReferenceChain: (PendingKill) ZB4HUD_DOM /Game/Maps/Wip/UEDPIE_0_WipVM.WipVM:PersistentLevel.ZB4HUD_DOM_0->Outer
[2015.04.16-18.35.36:904][531]LogReferenceChain: Level /Game/Maps/Wip/UEDPIE_0_WipVM.WipVM:PersistentLevel->OwningWorld
[2015.04.16-18.35.36:904][531]LogReferenceChain: (target) World /Game/Maps/Wip/UEDPIE_0_WipVM.WipVM
Fatal error: [File:D:\BuildFarm\buildmachine_++depot+UE4-Releases+4.7\Engine\Source\Developer\MessageLog\Private\Model\MessageLogListingModel.cpp] [Line: 70]
Critical Error ZB4PlayerState /Game/Maps/Wip/UEDPIE_0_WipVM.WipVM:PersistentLevel.MyPlayerState_1 Object from PIE level still referenced. Shortest path from root: (Object is not currently rooted)

UE4Editor.exe has triggered a breakpoint.

Hey -

Sorry for the delayed response and thank you for including the requested information. The crash you reported is still being investigated to understand what is causing it. If possible could you send us the project that is crashing so that we can take a look directly to help us determine what is happening?

I’m sorry I can’t share this project code.

Have you been able to repo it on your side?

I’ve not been able to reproduce this myself. Would it be possible to send a small sample project if you’re able to reproduce the crash in a new project with no additional content?