how to use a non uobject array in a uobject class without getting memory problems.

I am using an external library (opencv with contrib) and obviously it doesn’t take in UObjects. My cpp contains the following in the tick function:

           std::vector < int > ids;
        	std::vector < int > idsR;
        	std::vector < std::vector < Point2f > > corners, rejected;
            std::vector<Vec3d> rvecs, tvecs;
            aruco::detectMarkers(image, dictionary, corners, ids, detectorParameters);

        	if (corners.size() > 1)
        	{
        		aruco::estimatePoseSingleMarkers(corners, markerSize, cameraMatrix, distCoeffs, rvecs, tvecs);
        		AllVisibleMarkers.Empty();
        		for (int i = 0; i < ids.size(); i++)
        		{
        			UPWMatrix44 *tempMatrix = NewObject<UPWMatrix44>();
        			tempMatrix = FormMatrixFromVec3d(rvecs[i], tvecs[i]);
        			tempMatrix->setID(ids[i]);
        			AllVisibleMarkers.Add(tempMatrix);
        		}
        	}

and the h file

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = PWAR)
		TArray<UPWMatrix44*> AllVisibleMarkers;
Mat cameraMatrix, distCoeffs;

Where detectMarkers writes to corners and ids, estimatePoseSingleMarkers writes to rvecs and tvecs and UPWMatrix being a Uobject class. This implementation, with std::vector s instead of TArrays for the tempMatrix and AllVisibleMarkers worked without a problem. Now as soon as I show a marker in front of the camera (where previously detectMarkers was returning corners and ids correctly) I get an “Access violation writing location” at the line of detectMarkers.

I suspect that it is to do with the UE4 garbage collection but I can’t find anything online about how to stop them being destroyed without making the vectors into a different format that the opencv library can’t handle. There may also be problems with the tempMatrix and AllVisibleMarkers but I have yet to hit a breakpoint inside the if statement so I have no idea yet.
If I force in a single value for corners and ids it will still not get into the if statement but instead breaks at line 85 of MallocTBB.cpp NewPtr = scalable_realloc(Ptr, NewSize) which makes me even more confident it’s a problem with memory allocation that I don’t understand.

image, dictionary, detectorParamaters, cameraMatrix and distCoeffs are all set prior to this and as best I can tell are set correctly (I can’t get the pdb files to step through them but the data that is visible all looks correct)

All help is gratefully appreciated, this is pretty much the last stumbling block on my project and it’s driving me insane.

Philip Wilson.