Problem with async graph tasks and Hierarchical Instanced Static Mesh Components

Hi there!

I followed this tutorial here: https://wiki.unrealengine.com/Multi-…k_Graph_System

And made Tasks that receive a Pointer to a HierarchicalInstancedStaticMeshComponent and a Pointer to a custom Actor Component and when the Task is executed and comes to this line:



// Task properties set through constructor
UHierarchicalInstancedStaticMeshComponent * HISM;
UDataComponent * Data;
// and in DoTask
HISM->AddInstance(FTransform(Data->GetLocation(idx)));


it crashes with an “Access violation writing location” message.

I am checking both for != nullptr.

I’ve read that it could be caused by the fact that I’m not using virtual method stubs but I tried making GetLocation virtual and it didn’t fix it.

Any ideas?

UPDATE:
I split the line up into this:



// DoTask
FVector location = Data->GetLocation(idx);
FTransform transform = FTransform(location);
HISM->AddInstance(transform); // <--- Access violation writing location


And it only crashes in the last line.

Postet it on Answerhub as well: https://answers.unrealengine.com/que…0178/view.html
But as there are not many ppl doing c++ there I was hoping I’d get an answer in the forums.

UPDATE:
settingRefs.jpeg
In the first pic you can see the hierarchy, “VoxelDataRenderThread” is an Actor Component that creates the tasks.

It receives references to the other components (HISM and Data) as shown in the second pic. This happens before the tasks are created.

As of now, I tried moving the AddInstance call into the “VoxelDataRenderThread” (out of the Task) but it didn’t change anything.

Could there be a problem with the way I’m setting the references? Or is it just not possible to call AddInstance from a peer component and I need to somehow move it up once again, to the Actor for example?

Maybe if, from the task, I call a function of the class that created the task, and add the instance from there, so I don’t AddInstances from within the task but only trigger it from there?

EDIT: It’s not sufficient to make it from the custom actor component that creates the tasks. It crashes with the same error.

UPDATE: Even when I convert the Render Thread to a child class of HISMC and the AddInstance code is inside a class function, there is an access violation…

Is it even possible to use graph tasks for this?

EDIT: If said function is a UFUNCTION and triggered from BP, everything works fine. If it’s triggered from the task, it crashes.

Tried using ThreadSafe TSharedPtr; same result…

EDIT:
Found another wiki article on the topic:

Is it even possible to trigger Render calls from tasks?

Hi hi!
Resing this thread since this is the closest one to my issue and clicking the link is no option since the new, community hosted wiki.
Have you solved this issue? or found a walkaround?

Sorry for the late answer to an even older thread!
I fear I can’t really recall what I actually did back then. I looked up the old project that was still 4.24 and I think most of the code was commented.
Probably I just went with the synchronous approach and called the logic from Blueprint. As it was an educational project without real performance requirements it was enough.

If you find out anything, I’d be happy if you post it here. I’d be really interested in how these things work in Unreal!