Strange behavior for custom render engine material previews

Hello! I’m making a Python add-on for a custom rendering engine. It uses the gpu & bgl modules for rendering, but I’ve been struggling to get material previews working, as it seems like using bgl in any capacity for them has a lot of odd side effects. The main issues come out when the 3D view is in solid mode, and they occur on the next draw in the viewport after a preview image is generated. (After that, everything’s fine) These effects include the screen going completely black, meshes becoming somewhat translucent, and everything getting tinted white. (Seems like the effect varies every time based on which commands are used)

I’m not sure how to add a block of code on here, but this stackoverflow question describes my problem in more detail and features a little script that shows what I’m talking about. Is it possible to generate material previews using bgl, or do you have to use other means?