# GL\_INVALID\_OPERATON when sharing objects between contexts

**URL:** https://discourse.glfw.org/t/gl-invalid-operaton-when-sharing-objects-between-contexts/1138
**Category:** support
**Created:** [June 16, 2018, 5:13pm UTC](https://discourse.glfw.org/t/gl-invalid-operaton-when-sharing-objects-between-contexts/1138 "2018-06-16T17:13:50Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![wobak](https://avatars.discourse-cdn.com/v4/letter/w/54ee81/32.png) [@wobak](https://discourse.glfw.org/u/wobak)
#### Post date: [June 16, 2018, 5:13pm UTC](https://discourse.glfw.org/t/gl-invalid-operaton-when-sharing-objects-between-contexts/1138/1 "2018-06-16T17:13:50Z")

</div>

Hello,  
I am using Ubuntu 16.4 LTS with proprietary NVIDIA driver 384.111 and cannot get context sharing to work reliably.  
In my own application, using glfw 3.1.1, a GL\_INVALID\_OPERATION error is triggered whenever accessing an object in a context different from the one it was create in. This error is only triggered when _the first window_ is created with an OpenGL version above 3.1.

To see if this was specific to my application, I compiled and tested the sharing example in both glfw 3.1.1 and 3.2.1. However, an GL\_INVALID\_OPERATION is generated at glEnd() when drawing the quad, regardless of the OpenGL version. ThereforeI could not use the test as a reference.

Now I have two questions:  
Was there a change in context handling between OpenGL version 3.1 and 3.2, or is this a bug in the driver/GLFW?  
Is the context sharing bidirectional? From the GLFW documentation it is not clear whether it is only the first window(passed into the second glfwCreateWindow) which can access the other window’s objects.

---

<div class="post-metadata">

### Author: ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)
#### Post date: [June 17, 2018, 11:27am UTC](https://discourse.glfw.org/t/gl-invalid-operaton-when-sharing-objects-between-contexts/1138/2 "2018-06-17T11:27:49Z")

</div>

It looks like you’ve added [an issue for sharing on X11 to GLFW’s tracker](https://github.com/glfw/glfw/issues/1291) so I’ll link to it here.

---

<div class="post-metadata">

### Author: ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)
#### Post date: [June 17, 2018, 11:35am UTC](https://discourse.glfw.org/t/gl-invalid-operaton-when-sharing-objects-between-contexts/1138/3 "2018-06-17T11:35:32Z")

</div>

You mention for the sharing example that:

> [@wobak](#):
>
> GL\_INVALID\_OPERATION is generated at glEnd() when drawing the quad, regardless of the OpenGL version

However I can’t find glEnd() in the [current sharing example on Github](https://github.com/glfw/glfw/blob/master/examples/sharing.c). Could you check against this example if possible?

---

<div class="post-metadata">

### Author: ![elmindreda](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/elmindreda/32/26_2.png) [@elmindreda](https://discourse.glfw.org/u/elmindreda)
#### Post date: [June 17, 2018, 1:21pm UTC](https://discourse.glfw.org/t/gl-invalid-operaton-when-sharing-objects-between-contexts/1138/4 "2018-06-17T13:21:01Z")

</div>

It got [moved from tests](https://github.com/glfw/glfw/blob/3.2.1/tests/sharing.c) and rewritten for 3.3.

---

<div class="post-metadata">

### Author: ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)
#### Post date: [June 17, 2018, 2:29pm UTC](https://discourse.glfw.org/t/gl-invalid-operaton-when-sharing-objects-between-contexts/1138/5 "2018-06-17T14:29:18Z")

</div>

Thanks @elmindreda. I take it it’s still worth trying the revised example (as this shouldn’t raise an error on the deprecated legacy OpenGL glEnd() function)?

---

<div class="post-metadata">

### Author: ![elmindreda](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/elmindreda/32/26_2.png) [@elmindreda](https://discourse.glfw.org/u/elmindreda)
#### Post date: [June 17, 2018, 5:23pm UTC](https://discourse.glfw.org/t/gl-invalid-operaton-when-sharing-objects-between-contexts/1138/6 "2018-06-17T17:23:51Z")

</div>

Yes, it’s definitely worth trying.

---

<div class="post-metadata">

### Author: ![wobak](https://avatars.discourse-cdn.com/v4/letter/w/54ee81/32.png) [@wobak](https://discourse.glfw.org/u/wobak)
#### Post date: [June 17, 2018, 8:57pm UTC](https://discourse.glfw.org/t/gl-invalid-operaton-when-sharing-objects-between-contexts/1138/7 "2018-06-17T20:57:23Z")

</div>

Thanks for the quick replies!  
I cloned and compiled the current master with glGetError calls inserted and it did not produce anz errors. When I copied over the new sharing example to version 3.2.1, there is no error as well.  
I thought that the sharing test applications were using the default OpenGL version (1.0) and thus should not trigger any legacy warnings. This is however only true for the test in glfw 3.1.1.

From the new sharing example, it seems like sharing is bidirectional. Is that the case in all glfw versions?

---

<div class="post-metadata">

### Author: ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)
#### Post date: [June 18, 2018, 10:05am UTC](https://discourse.glfw.org/t/gl-invalid-operaton-when-sharing-objects-between-contexts/1138/8 "2018-06-18T10:05:47Z")

</div>

Hi @wobak,

GLFW only acts as a platform independent way to setup a context so it shares objects with another, but the behaviour is set by the OpenGL implementation rather than GLFW. The sharing is bi-directional.

See [the OpenGL wiki on Object Sharing](https://www.khronos.org/opengl/wiki/OpenGL_Object#Object_Sharing).

Cheers,

Doug.
