I get a crash when updating my dynamic texture in my Unreal OpenCV project.
The CVTexture object, which doesn’t really wrap anything OpenCV related, is an implementation of a dynamic texture whose texture data can be updated with the contents of a cv::Mat. The UpdateTextureRegions function (which is essentially copied from UTexture2D) crashes inconsistently in some cases. I imagine it’s because of the asynchronous behavior of the call. It might be because there was enough time between it’s executions for the then following operation of the Dynamic Material’s Texture being updated to reference the texture data potentially mid update? I’m not entirely sure what the crash IS but the crash report says that it happens mid way through the operations of the asynchronous function while executing bytecode. I have addressed it so far by switching the order of operations such that the Dynamic Material Texture variable is updated before CVTexture::UpdateTextureRegions is called giving it the time between frames to resolve. This seems to have addressed the problem.
Still I am unhappy that I’ve created nodes that crash Unreal. What can I do to fix this?
Current code can be viewed here.