Download

Information about instances and problems with them.

I’ve been using Hierarchical instanced static mesh components for a little while now. They’re very quick and have LODs with dither blending. Until today I’ve never had any problems with them but now I’ve stumbled onto some behavior that I can’t fully understand. I spawn an actor and then with a loop, sized between 20 - 400, with each iteration I add an instance to the actor which has a HISM component attached. When adding an instance you only provide a transform, that’s it. You’ve already preset the actual static mesh that is being instanced, so all that work is already done. For some reason during the 23 instance adding, I get a crash that takes me inside the BodyInstance.cpp to this line of code


if (InAggregate->getScene() == nullptr || InAggregate->getScene() == PDyanmicScene)
             {
                 for (PxActor* Actor : PDynamicActors)
                 {
                     InAggregate->addActor(*Actor);
                 }
             }

Why would the 23 iteration of adding this instance would it crash? What could be different on this round of the loop? I’ve checked the transform it is receiving. There a no NaN in there. They are relatively modest values, not too small and not too big. The only thing I can think is that this instance is occupies space that another instance does. But why would this matter? Can’t you spawn instances right on top of each other?

I just noticed this exception thrown.

“this->mConnectorArrayPool.mFreeElement was 0xFFFFFFFFFFFFFFFF.”

Not really sure what to do with it, but I figured it may be relevant.

Below is the main loop for spawning the instances. The container subCells is populated elsewhere. To test out what is going on I created three different container filling methods. 2 of the three container filling methods work. They all reference the subCells container and add cells to it. subCells container is a TArray<int32>. I’ve verified the container that doesn’t work has appropriate contents, no NaN, or extreme values. The thing is, I don’t see how any of this would matter. I would get an error getting the cell middle if this was an issue, or possibly when getting the rotation during the creation of the FTransform. Why it would matter in the addInstance function is a mystery to me.


int numSCs = subCells.Num();
for (int j = 0; j < numSCs; j++)
{
	FVector cellMiddle = UISC::getFaceMiddle(&listVerts[0], mSub.sL[MSL].fC[subCells[j]]);
	FTransform newT = FTransform(getRot(cellMiddle, listVerts[mSub.sL[MSL].fC[curFaceIdx].vrtxA]), cellMiddle, FVector(1,1,1))
	listActor->IcoCellA->AddInstance(newT);
}