# OpenGLHelpers::isContextActive() crashes in ProTools

**URL:** <https://forum.juce.com/t/openglhelpers-iscontextactive-crashes-in-protools/45781>\
**Category:** General JUCE discussion\
**Created:** [April 30, 2021, 5:05pm UTC](https://forum.juce.com/t/openglhelpers-iscontextactive-crashes-in-protools/45781 "2021-04-30T17:05:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aaronleese1](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/aaronleese1/32/19725_2.png) [@aaronleese1](https://forum.juce.com/u/aaronleese1)\
**Post date:** [April 30, 2021, 5:05pm UTC](https://forum.juce.com/t/openglhelpers-iscontextactive-crashes-in-protools/45781/1 "2021-04-30T17:05:27Z")

</div>

Hey guys -

Fairly easy to reproduce crash here, if you add:

`if (OpenGLHelpers::isContextActive()) OpenGLHelpers::clear(Colours::grey);`

To the resize method of you pluginEditor, you get some serious issues in ProTools and PluginDoctor.

Specifically, if the plugin is **has an active gl context** , you get a crash in either program.

If the plugin **does not have a context** , then PT is fine and PluginDoctor hangs (PT doesn’t use gl for rendering, PluginDoctor does … which seems to be the difference).

I assume this call should be valid when called from resize(), but please let me know if not.

I am making this call simply to clear the context (since otherwise it is bright RED, which is ugly):

> [@OpenGL 2D rendering RED on resize](https://forum.juce.com/t/opengl-2d-rendering-red-on-resize/44256/8):
>
> I got the same problem as jakemumu. Even though I attached my GL context using mGLContext.attachTo(\*this) I get false for isContextActive in the resized function. Here is how I could solve it instead: I subclass juce::OpenGlRenderer. And in its renderOpenGl() function I put this: void MyOpenGlRenderer::renderOpenGL() { if (OpenGLHelpers::isContextActive()) { OpenGLHelpers::clear(Colours::blue); } } Now I only have to tell my GL context, that I am using a custom renderer…

---

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [April 30, 2021, 6:10pm UTC](https://forum.juce.com/t/openglhelpers-iscontextactive-crashes-in-protools/45781/2 "2021-04-30T18:10:55Z")

</div>

An OpenGL context is not thread-safe. This means that if you try to modify the context (e.g. by clearing it) from a thread other than the rendering thread, you’ll run into problems. I’d recommend only attempting to modify the OpenGL context from within `Component::paint` or `OpenGLRenderer::renderOpenGL`.

---

<div class="post-metadata">

**Author:** ![aaronleese1](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/aaronleese1/32/19725_2.png) [@aaronleese1](https://forum.juce.com/u/aaronleese1)\
**Post date:** [April 30, 2021, 6:49pm UTC](https://forum.juce.com/t/openglhelpers-iscontextactive-crashes-in-protools/45781/3 "2021-04-30T18:49:28Z")

</div>

Aha! Good to know, I was wondering if that might be the case.

Follow up then: could we please have new contexts clear to something other than RED? When resizing a plugin that uses openGL, it’s quite ugly to get flashes of red around the edges.

---

<div class="post-metadata">

**Author:** ![RobinReumers2021](https://avatars.discourse-cdn.com/v4/letter/r/96bed5/32.png) [@RobinReumers2021](https://forum.juce.com/u/RobinReumers2021)\
**Post date:** [May 5, 2021, 1:31pm UTC](https://forum.juce.com/t/openglhelpers-iscontextactive-crashes-in-protools/45781/5 "2021-05-05T13:31:13Z")

</div>

I agree with Aaron. It would be great to somehow set the color, but at the very least don’t be red. Black (preferred for me) or white would be much better, and not freak out users.
