carmines / UnityPluginCollection

source code for Unity plugins for Desktop and UWP
MIT License
30 stars 7 forks source link

Unity Crash when switching pages #3

Closed ElGognolo closed 4 years ago

ElGognolo commented 5 years ago

Hello, I have encountered an issue using your pdfloader plugin : With a multi pages pdf, with scripting backend .Net 4.X start the sample scene and press the right arrow key to switch pages Repeat several times, if quick enough, this will crash Unity

carmines commented 5 years ago

the bug has to do with async callback and the time to when Unity Update() function gets called to update the texture. If you do this too fast, the pointer becomes invalid because the plugin has replaced its texture with the new one.

To fix you will have to implement a cache of pages and their Texture2D/SRV's for that page and on the callback notifies the plugin to update its texture on the next Update, you would call the plugin at that time to get the valid pointer.

If you implement this change, be sure to submit a pull request so we can get that back into the repo