- Home /
Native Plugin: What has to happen in the RenderEvent?
Hello Community, am developing a native plugin in C++ that will manipulate Unity textures and meshes. I've noticed in the official example that it performs such actions as well as rendering actions in a special C++ function called through GL.IssuePluginEvent
in the C# script.
My question is, does any access to GPU memory have to happen inside that function?
Surely the rendering tasks have to happen there, but I noticed that I can successfully call s_CurrentAPI->BeginModifyTexture
from a C++ function that's called from FixedUpdate(). Is this defined behavior or could that lead to unpredictable crashes and I'm forced to do everything graphics related in the RenderEvent? Huge thanks in advance :)
Answer by DragonCoder · May 16, 2020 at 08:42 PM
Yeah, so.. I answered my own question in the most annoying way. After trying to fix rare spontaneous crashes for days, it turns out this was the cause.
BeginModifyTexture and EndModifyTexture (from the official sample code) have definitely to be called inside the RenderEvent. Otherwise there is an approximately 1 in 5000 chance that the call causes a non-catchable crash >_< Guess it is safe to assume that this is the case for all GPU-related tasks.
Thanks for the heads up! The sample says "texture update needs to happen on the rendering thread" in RenderingPlugin.cpp. I might have skimmed over this if I didn't come across your answer.
Your answer
Follow this Question
Related Questions
UnityPluginLoad never called on iOS, Is it just broken? 1 Answer
Native Rendering Plugin with Oculus Rift 0 Answers
OpenGL Context from Plugin 1 Answer
GL.IssuePluginEvent with multiple plugins 1 Answer
NSEvents and Unity 0 Answers