Dynamic Meshes Crashing in 4.1.1

Dear Everyone,

Has anyone else had trouble with dynamic meshes crashing in 4.1.1 (hotfixed 4.1)?

I’ve been using the same code, unchanged, since 4.0, and now it is absolutely not working, reliably crashing every time.

There is no crash call stack at all, just a Render Thread Exception.

It crashes right here


bool UVictoryMeshComponent::SetGeneratedMeshTriangles(const TArray<FVMeshTri>& Triangles)
{
        **//if I comment this out, no crash, but also no dynamic meshes
        //This code used to just work fabulously!**
	GeneratedMeshTris = Triangles;
 
	**/*
//#if WITH_EDITOR
	if (ModelBodySetup) ModelBodySetup->InvalidatePhysicsData(); // This is required for the first time after creation
//#endif
 
	UpdateCollision();
 */**

	// Need to recreate scene proxy to send it over
	MarkRenderStateDirty();

	return true;
}

It’s not the physics stuff,I commented that out (and it always worked)

It’s the core of the dynamic mesh concept itself that is not working, directly setting the triangles array is causing instant crash.

I can even comment out MarkRenderStateDirty() and it still crashes.

For rest of related code you can use the original UE4 plugin or Dmacesic’s tutorial as a reference :slight_smile:

Thanks for any input on this!

Rama

PS: I repeat I have not touched my relevant code at all since 4.0

It’s still working fine for me. The only code that was changed recently was the vertex coloring fix from Ryvar, which is this line:



NewData.ColorComponent = STRUCTMEMBER_VERTEXSTREAMCOMPONENT(VertexBuffer, FDynamicMeshVertex, Color, VET_Color);


But I’ve included that in my current code and it works fine… Have you checked the call stack? Is Triangles being invalidated somewhere? What’s the specific exception?

EDIT: SetGeneratedMeshTriangles is called from your triangle generating function, is the reference to Triangles being destroyed? Are you using a TSharedPtr?

I tried keeping a global array just as a test, it’s not that (and it was never an issue before)

The only callstack / error I get is this


[2014.05.30-15.07.56:239][673]LogWindows:Error: appError called: Rendering thread exception:
Fatal error!


[2014.05.30-15.07.56:239][673]LogWindows:Error: Windows GetLastError: The operation completed successfully. (0)
[2014.05.30-15.07.56:240][673]LogWindows: === Critical error: ===


[2014.05.30-15.07.56:240][673]LogWindows: Rendering thread exception:
Fatal error!

[2014.05.30-15.07.56:241][673]LogExit: Executing StaticShutdownAfterError


So as you can imagine that doesn’t leave me much to work with :slight_smile:

I will keep poking around, thanks for caring Dmacesic!


Edit

Okay this is ridiculous!

It even crashes instantly if I manually fill the array with some random triangle, without deleting/switching/changing anything, simply ADDing a new triangle!




```

bool UVictoryMeshComponent::SetGeneratedMeshTriangles(const TArray<FVMeshTri>& Triangles)
{
	FVMeshTri NewTri;
	
	NewTri.Vertex0.Position = FVector(FMath::RandRange(-128,128),FMath::RandRange(-128,128),3);
	NewTri.Vertex1.Position = FVector(1,FMath::RandRange(-128,128),3);
	NewTri.Vertex2.Position = FVector(FMath::RandRange(-128,128),2,3);
	
	GeneratedMeshTris.Add(NewTri);
 
//#if WITH_EDITOR
	if (ModelBodySetup) ModelBodySetup->InvalidatePhysicsData(); // This is required for the first time after creation
//#endif
 
	UpdateCollision();
 
	// Need to recreate scene proxy to send it over
	MarkRenderStateDirty();

	return true;
}

```



Why I feel the crash is related to the code above

The crash doesn’t happen if I comment out the code above / that part of the whole process (see original post for more info) :slight_smile:


Edit 2:

I replaced my custom version with the exact code on the wiki, just so I can say I have a more neutral position to say it must be something else.

It still crashes!

And I can stop the entire crashing behavior by commenting out a single line



```

bool UVictoryMeshComponent::SetGeneratedMeshTriangles(const TArray<FVMeshTri>& Triangles)
{
	**//GeneratedMeshTris = Triangles;**
 
#if WITH_EDITOR
	if (ModelBodySetup) ModelBodySetup->InvalidatePhysicsData(); // This is required for the first time after creation
#endif
 
	UpdateCollision();
 
	// Need to recreate scene proxy to send it over
	MarkRenderStateDirty();
 
	return true;
}

```




I am going to hope this just magically goes away in 4.2, because I have absolutely no idea why this is occurring, I know my data is sound as I noted above, even random sample data causes the crash.

I can only presume there's something wonky with my current engine build.


However, this is not to put the code on the wiki in a bad light at all, I love that wiki code!

And for many it still works! So Enjoy it!

But unless I hear from someone about having any idea what's going on here, I will hope it just vanishes in 4.2 :)

Rama

Have you tried running it in VS debugging mode? What happens at each step in the stack trace?

Can you show the code that calls SetGeneratedMeshTriangles? Is there something garbage collecting the triangle array, or even your component (i.e it gets destroyed while you are assigning triangles)

I have no idea why it isn’t working for you…

Dear Dmacesic,

Here’s the code that is calling generate triangles:


const FVector Loc = Canvas3DActor->GetActorLocation() + FVector(0,0,1024); 
AVictoryWallCanvas3D* NewVWall = UVictoryCore::Spawn<AVictoryWallCanvas3D>(Loc,FRotator::ZeroRotator);
if(!NewVWall) 
{
  return;
}
//~~~~~~~~~~~
		
//ask Canvas3D to provide an array of FVMeshTri
GlobalTrisTest.Empty();                               //global array is just a test
Canvas3D->GetVMeshTris(GlobalTrisTest);
NewVWall->VJoyInit(GlobalTrisTest);
//NewVWall->VMesh->SetMaterial(0,VictoryPC->BC_Mat);

inside of the new wall actor:


void AVictoryWallCanvas3D::VJoyInit(const TArray<FVMeshTri>& Triangles)
{
	VMesh->SetGeneratedMeshTriangles(Triangles);
	//VMesh->UpdateBodySetup();
	//VMesh->UpdateCollision();
};

again this never crashes if I simply comment out the one single line mentioned above, so its not the other pointers :slight_smile:

I find it hard to believe it is some GC going on, when it is happening instantly, every time I create a new actor and then try to set the data.

Again I’ve tried setting actual known good data, and I’ve also tried using random sample data :slight_smile:

Soon as I have opportunity I will try to get more info, thanks again for your concern Dmacesic!

Rama

Praises Be to 4.2

Now in 4.2 I get exact crash information!

Thanks Epic!


[2014.06.09-04.39.01:395] 66]LogWindows: === Critical error: ===
Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0xffffffff

[2014.06.09-04.39.01:395] 66]LogWindows: Rendering thread exception:
Fatal error!

FGeneratedMeshSceneProxy::DrawDynamicElements() 0xd6c77f80 + 23 bytes [File=c:\users\rama\documents\unreal projects\victorygame\source\victorygame\private\dynamicmesh\victorymeshcompbase.cpp:148] [in C:\Users\Rama\Documents\Unreal Projects\VictoryGame\Binaries\Win64\UE4Editor-VictoryGame.dll]
FTranslucentPrimSet::RenderPrimitive() 0xdbdcbd0e + 14 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\renderer\private	ranslucentrendering.cpp:511] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-Renderer.dll]
FDeferredShadingSceneRenderer::RenderTranslucency() 0xdbdcc601 + 289 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\renderer\private	ranslucentrendering.cpp:614] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-Renderer.dll]
FDeferredShadingSceneRenderer::Render() 0xdbc37591 + 8 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\renderer\private\deferredshadingrenderer.cpp:734] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-Renderer.dll]
RenderViewFamily_RenderThread() 0xdbd2a1f9 + 0 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\renderer\private\scenerendering.cpp:919] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-Renderer.dll]
TGraphTask<`FRendererModule::BeginRenderingViewFamily'::`11'::EURCMacro_FDrawSceneCommand>::ExecuteTask() 0xdbcfab80 + 0 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\core\public\async	askgraphinterfaces.h:635] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-Renderer.dll]
FTaskThread::ProcessTasks() 0xe2546142 + 0 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\core\private\async	askgraph.cpp:321] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-Core.dll]
FTaskThread::ProcessTasksUntilQuit() 0xe25462fd + 0 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\core\private\async	askgraph.cpp:173] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-Core.dll]
RenderingThreadMain() 0xe3486229 + 0 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\rendercore\private\renderingthread.cpp:236] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-RenderCore.dll]
FRenderingThread::Run() 0xe34866a9 + 0 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\rendercore\private\renderingthread.cpp:319] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-RenderCore.dll]
FRunnableThreadWin::Run() 0xe27ac809 + 0 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\core\private\windows\windowsrunnablethread.cpp:75] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-Core.dll]
FRunnableThreadWin::GuardedRun() 0xe27a6571 + 8 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\core\private\windows\windowsrunnablethread.cpp:25] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-Core.dll]
Address = 0x776b652d (filename not found) [in C:\Windows\system32\kernel32.dll]
Address = 0x777ec521 (filename not found) [in C:\Windows\SYSTEM32
tdll.dll]
Address = 0x777ec521 (filename not found) [in C:\Windows\SYSTEM32
tdll.dll]


That line looks like this:


FMaterialRenderProxy* MaterialProxy = NULL;
if(bWireframe)
{
	MaterialProxy = &WireframeMaterialInstance;
}
else
{
	MaterialProxy = Material->GetRenderProxy(IsSelected());  //<- Crash
}

That Material was expected to have been during the initialization like so


// Grab material
Material = Component->GetMaterial(0);
if(Material == NULL)
{
	Material = UMaterial::GetDefaultMaterial(MD_Surface);
}

I thought the issue was that Material was null

Crash protection does not catch this, it seems as though Material is valid!

Something else is causing the crash on this line!!!


//CRASH PROTECITON
if(!Material)
{
	return;
}
else
{
	MaterialProxy = Material->GetRenderProxy(IsSelected()); //crash
}

It Is the Material

Actually it is the Material

If I do an IsValidLowLevel() check, Material does not pass and the function exits, and there is no crash!

There’s also no mesh visible though… :slight_smile:


//CRASH PROTECITON
if(!Material || !Material->IsValidLowLevel())
{
	return;
}
else
{
	MaterialProxy = Material->GetRenderProxy(IsSelected()); //never gets here
}


**Invalid Material Crash Protection**

I made it official now, and it is firing off constantly!

The material is clearly invalid!



```

//CRASH PROTECITON
if(!Material || !Material->IsValidLowLevel())
{
  UE_LOG(Victory,Error,TEXT("UVictoryMeshCompBase::DrawDynamicElements>> The Material for this Component is not valid!!!"));
  return;
}
else
{
	MaterialProxy = Material->GetRenderProxy(IsSelected());
}

```



Something is Really Wrong

I tried 3 different materials that I know are valid, as I use them elsewhere in my game code during runtime, and I am getting the materials via static constructor helper so I would know if they were not being found (editor gives a CDO error if the materials are not valid when found via static constructor helper)

Now that I added the log errors above for the material, I am also seeing this error


LogUObjectArray:Warning: Other object in slot

full log


[2014.06.09-05.11.03:043][624]Victory:Error: UVictoryMeshCompBase::DrawDynamicElements>> The Material for this Component is not valid!!!
[2014.06.09-05.11.03:053][625]LogUObjectArray:Warning: Other object in slot
[2014.06.09-05.11.03:054][625]Victory:Error: UVictoryMeshCompBase::DrawDynamicElements>> The Material for this Component is not valid!!!
[2014.06.09-05.11.03:064][626]LogUObjectArray:Warning: Other object in slot
[2014.06.09-05.11.03:065][626]Victory:Error: UVictoryMeshCompBase::DrawDynamicElements>> The Material for this Component is not valid!!!
[2014.06.09-05.11.03:075][627]LogUObjectArray:Warning: Other object in slot
[2014.06.09-05.11.03:076][627]Victory:Error: UVictoryMeshCompBase::DrawDynamicElements>> The Material for this Component is not valid!!!
[2014.06.09-05.11.03:087][628]LogUObjectArray:Warning: Other object in slot
[2014.06.09-05.11.03:087][628]Victory:Error: UVictoryMeshCompBase::DrawDynamicElements>> The Material for this Component is not valid!!!
[2014.06.09-05.11.03:098][629]LogUObjectArray:Warning: Other object in slot
[2014.06.09-05.11.03:099][629]Victory:Error: UVictoryMeshCompBase::DrawDynamicElements>> The Material for this Component is not valid!!!
[2014.06.09-05.11.03:115][630]LogUObjectArray:Warning: Other object in slot
[2014.06.09-05.11.03:116][630]Victory:Error: UVictoryMeshCompBase::DrawDynamicElements>> The Material for this Component is not valid!!!
[2014.06.09-05.11.03:122][631]LogUObjectArray:Warning: Other object in slot
[2014.06.09-05.11.03:122][631]Victory:Error: UVictoryMeshCompBase::DrawDynamicElements>> The Material for this Component is not valid!!!
[2014.06.09-05.11.03:140][632]LogUObjectArray:Warning: Other object in slot
[2014.06.09-05.11.03:150][632]Victory:Error: UVictoryMeshCompBase::DrawDynamicElements>> The Material for this Component is not valid!!!
[2014.06.09-05.11.03:151][632]LogUObjectArray:Warning: Other object in slot
[2014.06.09-05.11.03:152][632]Victory:Error: UVictoryMeshCompBase::DrawDynamicElements>> The Material for this Component is not valid!!!

Stuck

I am stuck now, see my above diary of my proceedings.

The crash I was getting is actually on this line, if I don’t set any material, there is no crash / UE LOG errors, but also the mesh never shows up.

If I use any material (I tried lots)


Canvas3D->GetVMeshTris(GlobalTrisTest);

//initializing Dynamic Mesh Component
NewVWall->VJoyInit(GlobalTrisTest);  
     
//HERE is the issue, any material I try has isses, the PC pointer is indeed valid
//its inside of the component when the new material is applied that the issue arises
//see above diary for details.
**NewVWall->VMesh->SetMaterial(0,VictoryPC->AssetMat_Chrome); **

I get these log errors (see above diary for how I created the log error below, the other error is from ObjectArray


[2014.06.09-05.11.03:043][624]Victory:Error: UVictoryMeshCompBase::DrawDynamicElements>> The Material for this Component is not valid!!!
[2014.06.09-05.11.03:053][625]LogUObjectArray:Warning: Other object in slot
[2014.06.09-05.11.03:054][625]Victory:Error: UVictoryMeshCompBase::DrawDynamicElements>> The Material for this Component is not valid!!!
[2014.06.09-05.11.03:064][626]LogUObjectArray:Warning: Other object in slot
[2014.06.09-05.11.03:065][626]Victory:Error: UVictoryMeshCompBase::DrawDynamicElements>> The Material for this Component is not valid!!!
[2014.06.09-05.11.03:075][627]LogUObjectArray:Warning: Other object in slot
[2014.06.09-05.11.03:076][627]Victory:Error: UVictoryMeshCompBase::DrawDynamicElements>> The Material for this Component is not valid!!!
[2014.06.09-05.11.03:087][628]LogUObjectArray:Warning: Other object in slot
[2014.06.09-05.11.03:087][628]Victory:Error: UVictoryMeshCompBase::DrawDynamicElements>> The Material for this Component is not valid!!!
[2014.06.09-05.11.03:098][629]LogUObjectArray:Warning: Other object in slot
[2014.06.09-05.11.03:099][629]Victory:Error: UVictoryMeshCompBase::DrawDynamicElements>> The Material for this Component is not valid!!!
[2014.06.09-05.11.03:115][630]LogUObjectArray:Warning: Other object in slot
[2014.06.09-05.11.03:116][630]Victory:Error: UVictoryMeshCompBase::DrawDynamicElements>> The Material for this Component is not valid!!!
[2014.06.09-05.11.03:122][631]LogUObjectArray:Warning: Other object in slot
[2014.06.09-05.11.03:122][631]Victory:Error: UVictoryMeshCompBase::DrawDynamicElements>> The Material for this Component is not valid!!!
[2014.06.09-05.11.03:140][632]LogUObjectArray:Warning: Other object in slot
[2014.06.09-05.11.03:150][632]Victory:Error: UVictoryMeshCompBase::DrawDynamicElements>> The Material for this Component is not valid!!!
[2014.06.09-05.11.03:151][632]LogUObjectArray:Warning: Other object in slot
[2014.06.09-05.11.03:152][632]Victory:Error: UVictoryMeshCompBase::DrawDynamicElements>> The Material for this Component is not valid!!!

Summary

My Dynamic Mesh code which worked perfectly in every editor version before 4.1.1 now does not work, It is not working 4.2 as well.

I have narrowed it down to the material somehow not being valid within the component.

But I have no idea how to make the material valid, since I know the materials I am passing in via SetMaterial are valid!

//In Dynamic Mesh Comp


//CRASH PROTECITON
**if(!Material || !Material->IsValidLowLevel())**
{
  UE_LOG(Victory,Error,TEXT("UVictoryMeshCompBase::DrawDynamicElements>> The Material for this Component is not valid!!!"));
  return;
}
else
{
	MaterialProxy = Material->GetRenderProxy(IsSelected());
}


**Critical Note**

It is critical to note that I do not get the crash protection using just if(!Material)

it is only when I added the 

```

if(!Material->IsValidLowLevel()) 

```

 that the crashing pattern stopped, so clearly something is wrong with the material!

but I have no idea what!



And I know the materials I am passing in are valid as I use them in my game during runtime!

Rama

Update: NumPrimitivesCrash with Default Material

If use the default material, overriding any SetMaterial,


//Using Default Material
Material = UMaterial::GetDefaultMaterial(MD_Surface);
		
//CRASH PROTECITON
if(!VISVALID(Material))
{
UE_LOG(Victory,Error,TEXT("UVictoryMeshCompBase::DrawDynamicElements>> The Material for this Component is not valid!!!"));
  return;
}
else
{
  MaterialProxy = Material->GetRenderProxy(IsSelected());
}

I get a crash related to the Number of Primitives Being 0


LogWindows:Error: appError called: Assertion failed: Mesh.GetNumPrimitives() > 0

Yet I know I have valid triangle data cause I am using that same data to draw the pre-finalized mesh using DynamicMeshBuilder!


[2014.06.09-05.30.51:675][467]LogWindows:Error: appError called: Assertion failed: Mesh.GetNumPrimitives() > 0 [File:e:\victoryue4\unrealengine-4.2\engine\source\runtime\renderer\private\DynamicPrimitiveDrawing.inl] [Line: 102]

Stack:
FWindowsPlatformStackWalk::StackWalkAndDump() 0xe1fdece6 + 0 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\core\private\windows\windowsplatformstackwalk.cpp:177] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-Core.dll]
FDebug::AssertFailed() 0xe1e813f5 + 0 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\core\private\misc\outputdevice.cpp:176] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-Core.dll]
TDynamicPrimitiveDrawer<FTranslucencyDrawingPolicyFactory>::DrawMesh() 0xdb9baf88 + 0 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\renderer\private\dynamicprimitivedrawing.inl:103] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-Renderer.dll]
FGeneratedMeshSceneProxy::DrawDynamicElements() 0xd873812d + 0 bytes [File=c:\users\rama\documents\unreal projects\victorygame\source\victorygame\private\dynamicmesh\victorymeshcompbase.cpp:185] [in C:\Users\Rama\Documents\Unreal Projects\VictoryGame\Binaries\Win64\UE4Editor-VictoryGame.dll]
FTranslucentPrimSet::RenderPrimitive() 0xdb9cbd0e + 14 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\renderer\private	ranslucentrendering.cpp:511] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-Renderer.dll]
FDeferredShadingSceneRenderer::RenderTranslucency() 0xdb9cc601 + 289 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\renderer\private	ranslucentrendering.cpp:614] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-Renderer.dll]
FDeferredShadingSceneRenderer::Render() 0xdb837591 + 8 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\renderer\private\deferredshadingrenderer.cpp:734] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-Renderer.dll]
RenderViewFamily_RenderThread() 0xdb92a1f9 + 0 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\renderer\private\scenerendering.cpp:919] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-Renderer.dll]
TGraphTask<`FRendererModule::BeginRenderingViewFamily'::`11'::EURCMacro_FDrawSceneCommand>::ExecuteTask() 0xdb8fab80 + 0 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\core\public\async	askgraphinterfaces.h:635] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-Renderer.dll]
FTaskThread::ProcessTasks() 0xe1d76142 + 0 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\core\private\async	askgraph.cpp:321] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-Core.dll]
FTaskThread::ProcessTasksUntilQuit() 0xe1d762fd + 0 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\core\private\async	askgraph.cpp:173] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-Core.dll]
RenderingThreadMain() 0xe3486229 + 0 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\rendercore\private\renderingthread.cpp:236] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-RenderCore.dll]
FRenderingThread::Run() 0xe34866a9 + 0 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\rendercore\private\renderingthread.cpp:319] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-RenderCore.dll]
FRunnableThreadWin::Run() 0xe1fdc809 + 0 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\core\private\windows\windowsrunnablethread.cpp:75] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-Core.dll]
FRunnableThreadWin::GuardedRun() 0xe1fd6571 + 8 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\core\private\windows\windowsrunnablethread.cpp:25] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-Core.dll]
Address = 0x776b652d (filename not found) [in C:\Windows\system32\kernel32.dll]
Address = 0x777ec521 (filename not found) [in C:\Windows\SYSTEM32
tdll.dll]

**The Ah-Hah Moment
**

Okay well something is definitely actually wrong with the data, or how it is being accessed from within the DrawDynamicElements section

2f51d388a318bc4f1152fd1fd5c1ac0164736147.jpeg

The Constructor is Never Being Called

So I added a bunch of log info to the constructor for the FGeneratedMeshSceneProxy



/** Scene proxy */
class FGeneratedMeshSceneProxy : public FPrimitiveSceneProxy
{
public:

FGeneratedMeshSceneProxy(UVictoryMeshCompBase* Component)
	: FPrimitiveSceneProxy(Component)
	, MaterialRelevance(Component->GetMaterialRelevance())
	, VictoryMeshComponent(Component)
{
	// Add each triangle to the vertex/index buffer
	for(int TriIdx=0; TriIdx<Component->GeneratedMeshTris.Num(); TriIdx++)
	{
		FVMeshTri& Tri = Component->GeneratedMeshTris[TriIdx];
		
		IndexBuffer.Indices.Add(
			VertexBuffer.Vertices.Add(Tri.Vertex0) //returns new index
		);
	
		IndexBuffer.Indices.Add(
			VertexBuffer.Vertices.Add(Tri.Vertex1) //returns new index
		);
		
		IndexBuffer.Indices.Add(
			VertexBuffer.Vertices.Add(Tri.Vertex2) //returns new index
		);
		
		**UE_LOG**(Victory,Warning, TEXT("VICTORY MESH BASE COMP FGeneratedMeshSceneProxy >>> VERTEX WORLD POS %s"), *Tri.Vertex2.Position.ToString() );
	}

	
	**UE_LOG**(Victory,Error,TEXT("Component->GeneratedMeshTris.Num() is currently %d"), Component->GeneratedMeshTris.Num());
	
	
	**UE_LOG**(Victory,Error,TEXT("IndexBuffer.Indices.Num() / 3 is currently %d"), IndexBuffer.Indices.Num() / 3);

[SIZE=3]The Constructor is Never Being Called!!!
[/SIZE]

But the DrawDynamicElements() portion is!


**Create Scene Proxy Never Called**

CreateSceneProxy() is not getting called!



```

FPrimitiveSceneProxy* UVictoryMeshCompBase::CreateSceneProxy()
{
	
	****UE_LOG****(Victory,Error,TEXT("CreateSceneProxy() DID RUN YESYSYESYSY"));
		
	FPrimitiveSceneProxy* Proxy = NULL;
	if(GeneratedMeshTris.Num() > 0)
	{
		Proxy = new FGeneratedMeshSceneProxy(this);
	}
	return Proxy;
}

```



The Big Question

but how is the DrawDynamicElements() code ever running if neither constructor nor the CreateSceneProxy seem to be running / running the UE_LOG ?


**The Destructor IS Getting Called**


Destructor



```

virtual ~FGeneratedMeshSceneProxy()
	{
		**UE_LOG(Victory,Error,TEXT("DESTRUCTOR GOT CALLED"));**
		
		
		/*
		VertexBuffer.ReleaseResource();
		IndexBuffer.ReleaseResource();
		VertexFactory.ReleaseResource();
		*/
	}

```



//Log

The log goes nuts when I exit the game, the destructor log DOES appear though, unlike the constructor and the CreateSceneProxy()

What in Heaven's name is going on here?



```

**[2014.06.09-06.08.23:593][872]Victory:Error: DESTRUCTOR GOT CALLED**
[2014.06.09-06.08.23:662][872]LogExit: Game engine shut down
[2014.06.09-06.08.24:950][872]LogWindows:Error: appError called: Rendering thread exception:
Fatal error!

FRefCountedObject::Release() 0xdc3297e6 + 0 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\core\public	emplates\refcounting.h:32] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-Core.dll]
FVertexFactory::~FVertexFactory() Address = 0xdcefef68 (filename not found) [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-ShaderCore.dll]
FGeneratedMeshSceneProxy::~FGeneratedMeshSceneProxy() 0xd16d3a81 + 13 bytes [File=c:\users\rama\documents\unreal projects\victorygame\source\victorygame\private\dynamicmesh\victorymeshcompbase.cpp:142] [in C:\Users\Rama\Documents\Unreal Projects\VictoryGame\Binaries\Win64\UE4Editor-VictoryGame.dll]
FGeneratedMeshSceneProxy::`scalar deleting destructor'() Address = 0xd16da814 (filename not found) [in C:\Users\Rama\Documents\Unreal Projects\VictoryGame\Binaries\Win64\UE4Editor-VictoryGame.dll]
FScene::RemovePrimitiveSceneInfo_RenderThread() 0xd87a78a8 + 17 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\renderer\private\rendererscene.cpp:502] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-Renderer.dll]
`FScene::RemovePrimitive'::`5'::EURCMacro_FRemovePrimitiveCommand::DoTask() 0xd87713eb + 251 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\renderer\private\rendererscene.cpp:528] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-Renderer.dll]
TGraphTask&lt;`FScene::RemovePrimitive'::`5'::EURCMacro_FRemovePrimitiveCommand&gt;::ExecuteTask() 0xd877ce7a + 0 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\core\public\async	askgraphinterfaces.h:635] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-Renderer.dll]
FTaskThread::ProcessTasks() 0xdc366142 + 0 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\core\private\async	askgraph.cpp:321] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-Core.dll]
FTaskThread::ProcessTasksUntilQuit() 0xdc3662fd + 0 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\core\private\async	askgraph.cpp:173] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-Core.dll]
RenderingThreadMain() 0xe3466229 + 0 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\rendercore\private\renderingthread.cpp:236] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-RenderCore.dll]
FRenderingThread::Run() 0xe34666a9 + 0 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\rendercore\private\renderingthread.cpp:319] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-RenderCore.dll]
FRunnableThreadWin::Run() 0xdc5cc809 + 0 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\core\private\windows\windowsrunnablethread.cpp:75] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-Core.dll]
FRunnableThreadWin::GuardedRun() 0xdc5c6571 + 8 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\core\private\windows\windowsrunnablethread.cpp:25] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-Core.dll]
Address = 0x776b652d (filename not found) [in C:\Windows\system32\kernel32.dll]
Address = 0x777ec521 (filename not found) [in C:\Windows\SYSTEM32
tdll.dll]
Address = 0x777ec521 (filename not found) [in C:\Windows\SYSTEM32
tdll.dll]

```




Rama

OMG

I had several dynamic mesh classes for different things

I had several definitions at the global scope for these scene proxies, in my various .cpp files


/** Scene proxy */
class FGeneratedMeshSceneProxy : public FPrimitiveSceneProxy
{
public:

Solution

The original code on the Wiki should not be defining SceneProxy classes at the GLOBAL scope!

It should be defined, nestled locally inside of Create Scene Proxy

then

if people make multiple classes based on the wiki code, they will not accidentally create multiple classes with the same name at the global scope.

Here is my solution code:


FPrimitiveSceneProxy* UVictoryMeshCompBase::CreateSceneProxy()
{
	
	/** Scene proxy class, no longer polluting global name space */
	class FVictoryMeshCompBaseSceneProxy : public FPrimitiveSceneProxy
	{
	public:
	 
		FVictoryMeshCompBaseSceneProxy(UVictoryMeshCompBase* Component)
			: FPrimitiveSceneProxy(Component)
			, MaterialRelevance(Component->GetMaterialRelevance())
			, VictoryMeshComponent(Component)
		{
			
               //REST OF THE CLASS DEFINITION
	};
	
	if(GeneratedMeshTris.Num() > 0)
	{
		//Create new instance of this very local class 
		//		which will now never pollute the global name space
		return new FVictoryMeshCompBaseSceneProxy( this );
	}
	else
	{
		return NULL;		//not enough tris
	}
}

Resolved

This matter has finally been resolved!

I have updated the Wiki code for Procedural Meshes to account for this error:

  1. You should never be defining SceneProxy classes at the global scope! Because then if you copy paste to create multiple dynamic mesh classes you will then have duplicate scene proxy classes with same name at global scope (which is why my destructor was being called but not my constructor, UE4 was pulling from both classes with same name somehow)

  2. Always nestle the definition of the sceneproxy class INSIDE of CreateSceneProxy (as the UE4 code base does) to ensure that scene proxy class is never global and only exists inside the context of that one function.

Thank you again for the Procedural Mesh Tutorial and wiki!

I am very glad for the information that Dmacesic and others have shared on that wiki.

I have now made my own contribution to the code to ensure that this error does not arise for anyone else.

(review entire thread for details)


**Wiki Tutorial Code I updated:**

https://wiki.unrealengine.com/Procedural_Mesh_Generation#GeneratedMeshComponent.cpp

I only changed the position of the scene proxy class, I did not change any of its code.

I also changed how the scene proxy is created.

Enjoy!

Rama

Picture For You

Here is my highest resolution Torus Knot yet!

Made with the help of the Procedural Mesh Wiki code!

I just made this mesh while in-game!

Where’s My Character

See if you can find my character in this pic!

Glad you fixed your issue Rama. The 4.2 code still has the proxy code outside the create function, but within the cpp (Engine\Plugins\Runtime\CustomMeshComponent\Source\CustomMeshComponent\Private\CustomMeshComponent.cpp)

I still find it strange it caused your difficulties, but all’s well that ends well.

"The 4.2 code still has the proxy code outside the create function, but within the cpp "

I really think Epic should fix that so the sceneproxy is not being declared at the global scope :slight_smile:

Great to hear from you Dmacesic!

Thanks again for doing all this research!

[FONT=Comic Sans MS]:heart:

Rama

EDIT: I posted this scoping fix on github

https://github.com/EpicGames/UnrealEngine/pull/226

I am bold enough to declare it a “fix” because I had to spend 4 hours debugging the issue to realize what was happening. And my scoping solution did actually fix my problem, no other change was required to my code base.

See entire thread for details.