Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash because of a collected texture. #11

Open
Lawendt opened this issue Dec 6, 2023 · 1 comment
Open

Crash because of a collected texture. #11

Lawendt opened this issue Dec 6, 2023 · 1 comment

Comments

@Lawendt
Copy link

Lawendt commented Dec 6, 2023

Hello. We're having a crash happening on packaged builds after a time of showing textures. In my experience, it helps alt tabbing a lot while the texture is being shown. From my research it seems like it's happening due to the slate resource being released and then it's trying to create it again, but with an invalid object

This is the callstack

[Inlined] FStructBaseChain::IsChildOfUsingStructArray(const FStructBaseChain &) Class.h:365
[Inlined] UStruct::IsChildOf(const UStruct *) Class.h:623
[Inlined] UObjectBaseUtility::IsChildOfWorkaround(const UClass *,const UClass *) UObjectBaseUtility.h:714
[Inlined] UObjectBaseUtility::IsA(UClass *) UObjectBaseUtility.h:736
UObjectBaseUtility::IsA<UMaterialInterface>() UObjectBaseUtility.h:743
FSlateRHIResourceManager::GetShaderResource(const FSlateBrush &,TVector2<float>,float) SlateRHIResourceManager.cpp:675
FSlateShaderResourceManager::GetResourceHandle(const FSlateBrush &,TVector2<float>,float) ShaderResourceManager.cpp:31
FSlateRHIRenderer::GetResourceHandle(const FSlateBrush &,TVector2<float>,float) SlateRHIRenderer.cpp:1851
FSlateRenderer::GetResourceHandle(const FSlateBrush &) SlateRenderer.h:342
FTextureManager::FTextureEntry::GetResourceHandle() TextureManager.cpp:158
SImGuiWidget::OnPaint(const FPaintArgs &,const FGeometry &,const FSlateRect &,FSlateWindowElementList &,int,const FWidgetStyle &,bool) SImGuiWidget.cpp:688
...

And on this screenshot we can see a trash object on the brush. This object is stored on a TObjectPtr with a UPROPERTY macro, so it should update to a null ptr if the resource isn't valid anymore, but because the slatebrush itself isn't stored on a uproperty, this is not recognized by unreal. Causing this crash.
image

It can be for a faulty usage of the texture resource on imgui, but anyway this seems like a good thing to be in mind for fixing.

Our code using this is:

auto icon_handle = FImGuiModule::Get().FindTextureHandle(from_texture->GetFName());
if (!icon_handle.IsValid())
{
   icon_handle = FImGuiModule::Get().RegisterTexture(from_texture->GetFName(), loaded_texture);
}

Changing it to just the following, helps fixing this crash, but it's mixing up texture, one that should be shown on A is being shown on C, B is showing on A and it goes on...

auto icon_handle = FImGuiModule::Get().RegisterTexture(from_texture->GetFName(), loaded_texture);

eventually tho, this also makes another crash happen for basically the same reason

[Inlined] FStructBaseChain::IsChildOfUsingStructArray(const FStructBaseChain &) Class.h:365
[Inlined] UStruct::IsChildOf(const UStruct *) Class.h:623
[Inlined] UObjectBaseUtility::IsChildOfWorkaround(const UClass *,const UClass *) UObjectBaseUtility.h:714
[Inlined] UObjectBaseUtility::IsA(UClass *) UObjectBaseUtility.h:736
[Inlined] UObjectBaseUtility::IsA() UObjectBaseUtility.h:743
[Inlined] Cast(UObject *) Casts.h:123
FSlateRHIResourceManager::ReleaseDynamicResource(const FSlateBrush &) SlateRHIResourceManager.cpp:978
FTextureManager::FTextureEntry::Reset(bool) TextureManager.cpp:170
[Inlined] FTextureManager::FTextureEntry::operator=(FTextureManager::FTextureEntry &&) TextureManager.cpp:139
FTextureManager::AddTextureEntry(const FName &,UTexture *,bool) TextureManager.cpp:104
[Inlined] FTextureManager::CreateTextureResources(const FName &,UTexture *) TextureManager.cpp:36
FImGuiModule::RegisterTexture(const FName &,UTexture *,bool) ImGuiModule.cpp:95
...
image

So right now I don't know what would be the ideal way of using textures on imgui. I would love to get more information on that. By the way, using unreal 5.3.1

@Lawendt
Copy link
Author

Lawendt commented Dec 11, 2023

update: I was able to not have this issue by storying the the texture on UPROPERTY array on a game instance subsystem. But this seems more of a workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant