RenderThumbnail leads to FPhysScene crash??

I just want to call function ThumbnailTools::RenderThumbnail() to render a real-time material sphere with slate widget in game.
But it will lead to a crash at FPhysScene::FlushDeferredCollisionDisableTableQueue or somewhere else in FPhysScene.
Is there anything relationship between them?

Could I render a material thumbnail in game just like contentbrowser does in edior?
Thanks!!

If I play it in editor and it will be fine:

if I play it in standalone game, it will crash here:
const bool bIsInPIEOrSimulate = GEditor->PlayWorld != NULL || GEditor->bIsSimulatingInEditor;

GEditor is NULL, but you can fix that code to get out the crash, and you will get another crash:

void FPhysScene::FlushDeferredCollisionDisableTableQueue()
{
	check(IsInGameThread()); 
	for (int32 i = 0; i < DeferredCollisionDisableTableQueue.Num(); ++i)//crash here
	{
           ..
         }
}

I must miss something to use the Assetthumbnail class, please help!thanks!

May be it was caused by multithreading garbage collection(reander thread and game thread).

So anybody can give some tips, please~~

Hi mylkrex,

What version of the Engine are you using, and are you using an Engine built from source code, or using the Launcher? When the Editor crashes, do you see the crash report tool? If so, can you copy the callstack that it provides and paste it here? Also, if you can provide the most recent log for your project when it crashes, that would be great. You can find the logs at \Saved\Logs.

Also, please take a look at this post to get an idea of any other information you may have that would help us investigate this issue.

Thanks, I did not meant the editor crashed.
I mean that if I launch the game with out editor, the game will crash because of my game code.

Ok, I have got a solution but not the best solution.
what lead to crash is when you create a FThumbnailPreviewScene, you actually create a new UWorld with no PhysicsScene.

So the physicsscene is NULL, and many code about physicsscene will lead to a crash.

What I do it just fix this line in ThumbnailHelpers.cpp:

FThumbnailPreviewScene::FThumbnailPreviewScene()
	: FPreviewScene( ConstructionValues()
						.SetLightRotation( FRotator(304.736, 39.84, 0) )
						.SetCreatePhysicsScene(true) //set it to true
						.SetTransactional(false))

But you know we should not create a physicsscene for a thumbnail world.
If you have many thumbnails, oh, you can imagine that…

So any better ideas?

Heya mylkrex!

ThumbnailTools::RenderThumbnail was made for editor use and will not work in game. All the code to render thumbnails lives in editor classes which will not exist when you make a cooked standalone version of your game. You should be using render-to-texture for this effect in game. You should check out the Blueprint Office sample, there is a monitor in the security room that renders one of the security camera’s views to a texture to display.

Thanks! I have found that I can not compile my game code with ‘Development’ configration successfully. So I can not package my game.

So that means one can not include any header files(Such as UnrealEd.h AssetThumbnail.h ObjectTools.h) about eidtor.in game project.
Am I right?

Correct. If you want to catch editor dependencies as they are added, you should remove all editor module dependencies in your non-editor build.cs files. That way including editor code will be a compile error and linking will also not work.

Hi,BobTellez:
I got new progress of this effect:

1.I move all thumbnail editor code to my own game module as tools.
2.I can compile it with development configration and run it in package game without errors.
3.But I get all thumbnails to be black in package game. And it works fine with ‘Debug Editor’.

It works fine with ‘Debug Editor’

black thumbnail in package game

I have focused the these lines:

const int32 XPos = 0;
const int32 YPos = 0;
//UMyMaterialInstanceThumbnailRenderer is same as the original version,
//But ReadPixelPtr got black result from the rendertargetresource.
    			RenderInfo->Renderer->Draw(   
    				InObject,
    				XPos,
    				YPos,
    				DrawWidth,
    				DrawHeight,
    				RenderTargetResource,
    				&Canvas
    				);
    			Canvas.DrawShadowedText(10, 10, FText::FromString("12345678912312324365345435345345"), GetStatsFont(), FLinearColor(0.8, 1.0, 0.2, 1.0)); //canvas works fine in package game

Dose packaged version stop something rendering from working?Thanks!

I can not debug the packaged game.
I get waring: the game module ‘FSGame’ could not be found with ‘Debug’ configration.
So some tips about this will be very helpful!! thanks!!

I don’t really know. Show flags might be different in the packaged game and some rendering code might be disabled in game, too. Did you look into rendering to texture in the Blueprint Office sample project? You will probably have more success since that method is made to work in non-editor environments.

Do you mean CaptureScene2D? Yes I have a search for it, and It seems to be no difference between the two solutions.
The Only difference is that thumbnail solution create a new preview world and preview sphere sm actor and give it a directional light, and get a rendertexure for us. I will give a deep further research for SceneCaptureComponent.
Thanks.

When you say you “moved all the thumbnail editor code into your project” what do you mean? Did you copy/paste thumbnailhelpers.cpp/.h and all the files it’s dependent on into your project? I ask only because that seems like that’d be a lot of effort to find/move all those files.