Why GetArrayView is null in standalone?

Hello,

I have a raycast code which works perfectly in Editor builds (DebugGame Editor and Development Editor) but crashes in modes without editor.

example:

	const auto* Actor = RV_Hit.GetActor();
	UStaticMeshComponent* HitStaticMeshComponent = Cast<UStaticMeshComponent>(RV_Hit.Component.Get());

	if (HitStaticMeshComponent)
	{
		UStaticMesh* StaticMesh = HitStaticMeshComponent->StaticMesh;
		FStaticMeshLODResources& LODModel = StaticMesh->RenderData->LODResources[0];
		FIndexArrayView Indices = LODModel.IndexBuffer.GetArrayView();

this is a raycast/hit check code fragment.
Indices is correct in editor modes, but NULL in standalone modes, therefore crashes in next lines where I want access it.

What I need to set/add in C++ for getting it work in standalone modes?

thanks,
Gabor

new info:

the following boolean seems controls this:

bool bNeedsCPUAccess = !FPlatformProperties::RequiresCookedData();

tooltip shows that GetArrayView is only valid when bNeedsCPUAccess is true.

and it is confirmed, there is diff:

standalone:

+ LODModel.IndexBuffer {IndexStorage={bNeedsCPUAccess=**false** } b32Bit=false } FRawStaticIndexBuffer

editor:

+ FIndexBuffer {IndexBufferRHI={Reference=0x000000000f8405d0 <Information not available, no symbols loaded for UE4Editor-D3D11RHI.dll> } } FIndexBuffer
+ IndexStorage {bNeedsCPUAccess=**true** } TResourceArray<unsigned char,0>
b32Bit false bool

so the exact question is, how can I set this variable true for standalone?

Anyone with a solution for this?

well maybe this is also an important info:
seems not only the mentioned boolean bNeedsCPUAccess is the problem, in standalone the entire IndexBuffer is NULL for that LOD. seems in standalone there is no initialisation for that buffer, therefore GetArrayView returns also with NULL (which works from IndexBuffer)
it is quite strange, as many UE sources use that method, and as I see, not only Editor related sources.

Hi BigaC,

Could you provide some additional information about this issue?

  • What version of the Engine are you using?
  • Are you using the binary version of the Engine installed by the Launcher, or did you build the Engine from source code?
  • Does this happen only in your own project, or are you able to reproduce this in a new project? If so, could you provide the steps you are following to cause the crash to occur?
  • Can you provide the callstack and logs after the crash occurs?

Please see this page for any additional information that may be helpful.

Hello,

Thanks for the reply.
Im using UE 4.4.3, but I had the same problem with previous versions (from 4.3.1). It is the binary version.
Callstack, logs attached.
[link text][1]

[link text][3]

The crash occurs at the line when I want access the indexbuffer of my LOD resource:

	if (HitStaticMeshComponent)
	{
		UStaticMesh* StaticMesh = HitStaticMeshComponent->StaticMesh;
		FStaticMeshLODResources& LODModel = StaticMesh->RenderData->LODResources[0];
		
		FIndexArrayView Indices = LODModel.IndexBuffer.GetArrayView();
		
		const FPositionVertexBuffer& PositionVertexBuffer = LODModel.PositionVertexBuffer;

	>>>>	int32 Index0 = Indices[RV_Hit.FaceIndex * 3];

This source works well if I start the game with editor build (DebugGame Editor), ut doesnt work if I start it as standalone (DebugGame). The buffer is ok in the editor modes, but NULL in standalone (see Watch screen), so accessing it by index fails.

The mesh Im using for raycast is the standard UE sphere:
StaticMesh’/Game/Shapes/EditorSphere.EditorSphere

Im working in a small team, two other people has UE, and they experience the same crash on same line.

I try to check it in a new project, though it isnt so easy, but probably I can do it with a simpler code today.

Repro steps for crash:

  1. Create new C++ project: Code First Person, name as RayCastTest

  2. Add Source Code from UE menu, select Player Controller as base class, name MyPlayerController

  3. Edit sources with VS and add RHI, RenderCore to RayCastTest.Build.cs file

  4. Replace MyPlayerController.h and MyPlayerController.cpp with attached sources

  5. Add following lines to RayCastTestGameMode.cpp: include “MyPlayerController.h”, to the constructor: PlayerControllerClass = AMyPlayerController::StaticClass();

  6. Start project with editor build

  7. Open level blueprint and add raycast to mouse click according to attached screen save

  8. Make breakpoint to line 68 (bool bDebug = true) in myplayercontroller.cpp

  9. Build it with DebugGame Editor, run the project in UE, Play and click to a white staticmesh box, breakpoint should be triggered: Indices is valid

  10. Cook in UE and then build it with DebugGame (standalone), run and click to same mesh: Indices is NULL

If you need further detail or sth not clear, pls let me know! :slight_smile:

[link text][1]

Thank you for providing the additional reproduction steps. I was able to reproduce everything down through step 9. However, in step 10 when I try to run the project from Visual Studio in DebugGame configuration, it hits a breakpoint when loading, so I can’t test for the crash that you were seeing.

I did see a different crash happening in DebugGame Editor if the Raytrace hit one of the walls of the level instead of first hitting a cube. It happens where HitStaticMeshComponent is created, so I don’t think it is related to the original issue (Indices has not been created yet).

Which breakpoint hit if you run without editor while loading?
OK catching 10 would be important, my debuggame build ran correctly from VS and stops only at the BP I set.
I assume cook done correctly there…
I attach all sources generated/modified in my project, maybe there is a difference…

Yeah the other crash is irrelevant, it is due to short/demo code, it is only for staticmesh actors (which type we use in our game), other actors not handled.
link text

The breakpoint issue I was experiencing turned out to be unrelated to the issue you were seeing. It was something that was recently fixed internally, and isn’t something that should be a bother to you or other users.

After spending most of today trying to sort out the issue above, I was finally able to reproduce the issue that you described. I have a couple more tests I want to run tomorrow, and then I will be submitting a report to have this investigated further by one of our developers.

thats a good news, thanks for your efforts.

Hi BigaC,

Sorry for not getting back to you yesterday. I have entered a ticket for this issue (UE-5494), and a developer will be investigating further.

I am being hit by exactly the same problem.

UDK: 4.5
Platform: Win

Crashes when it hits that line. How do I see the update on that ticket?

Hi PompeyPaul,

Unfortunately there isn’t a way for you to directly check the ticket. However, if you ever need an update on the status of the ticket, please feel free to ask for one here. Any new posts here will re-open this issue, and we can check the ticket and give you an update.

Currently, the issue is still under investigation.

As BigaC mentions, we don’t keep the index buffer CPU accessible outside the editor, to save memory. That is exactly what the bNeedsCPUAccess logic is doing. You should be able to change the logic though if you need access to the graphics triangles. Another option would be to ask the PhysX colliison mesh for the vertex (e.g. using PxMeshQuery::getTriangle).

Thanks, won’t the collision mesh and render mesh often be different? Thus I would need to modify the engine to keep the triangle list?

The per-poly collision should match the graphics triangles.

Is that still true if the artist has supplied a separate collision mesh for the static mesh? Or is there always a per-poly collision mesh available? I.e. would going this route compel me to use per-poly collision meshes?

Artist supplied ‘simple collision’ is in addition to per-poly collision, you usually need both, and can choose which is used when you do the query. Hitscan weapons normally want to trace against actual visible geometry for example. The only time we don’t pass the graphics polys to PhysX is if you disable collision for a section in the Static Mesh Editor.