# Shared background GL context on iOS problems

**URL:** <https://discourse.libsdl.org/t/shared-background-gl-context-on-ios-problems/19981>\
**Category:** SDL Development\
**Created:** [September 19, 2013, 11:48am UTC](https://discourse.libsdl.org/t/shared-background-gl-context-on-ios-problems/19981 "2013-09-19T11:48:18Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![slimshader](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/47e85d/32.png) [@slimshader](https://discourse.libsdl.org/u/slimshader)\
**Post date:** [September 19, 2013, 11:48am UTC](https://discourse.libsdl.org/t/shared-background-gl-context-on-ios-problems/19981/1 "2013-09-19T11:48:18Z")

</div>

Hi,

did anyone manage to create secondary / shared GL context on iOS? My code works fine on Windows but just creating second context on iOS causes many runtime erros.

---

<div class="post-metadata">

**Author:** ![slimshader](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/47e85d/32.png) [@slimshader](https://discourse.libsdl.org/u/slimshader)\
**Post date:** [September 20, 2013, 9:13am UTC](https://discourse.libsdl.org/t/shared-background-gl-context-on-ios-problems/19981/2 "2013-09-20T09:13:26Z")

</div>

No one is uploading textures in background thread on iOS?

---

<div class="post-metadata">

**Author:** ![Pallav\_Nawani](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/pallav_nawani/32/237_2.png) [@Pallav\_Nawani](https://discourse.libsdl.org/u/Pallav_Nawani)\
**Post date:** [September 21, 2013, 5:36am UTC](https://discourse.libsdl.org/t/shared-background-gl-context-on-ios-problems/19981/3 "2013-09-21T05:36:48Z")

</div>

If you are using SDL’s rendering, then you can’t do this. You can load  
image files in a background thread, but you need to create texture in  
the same thread that created the OpenGL context.

If you only use SDL to handle events, then you can create two opengl  
contexts and use one to create textures in background while you display  
using another.On 9/20/2013 2:43 PM, slimshader wrote:

> No one is uploading textures in background thread on iOS?
> 
> * * *
> 
> SDL mailing list  
> SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

–  
_Pallav Nawani_  
_Game Designer/CEO_

> **[Ironcode Gaming](https://ironcode.com/)**
>
> Founded in 2004 Ironcode is an independent developer and publisher of quality games. Here at Ironcode we develop and produce original games and also provide end

Twitter: [x.com](http://twitter.com/Ironcode_Gaming)  
Facebook: [Ironcode Gaming](http://www.facebook.com/Ironcode.Gaming)

---

<div class="post-metadata">

**Author:** ![slimshader](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/47e85d/32.png) [@slimshader](https://discourse.libsdl.org/u/slimshader)\
**Post date:** [September 22, 2013, 4:41pm UTC](https://discourse.libsdl.org/t/shared-background-gl-context-on-ios-problems/19981/4 "2013-09-22T16:41:45Z")

</div>

Maybe I didn’t explain clear: I do have second (shared) GL context that is suppose to be current in background thread. I use this second context to upload textures in the background. Problems is, it does not work on iOS giving crashes. On Windows it works OK but it seems iOS implementation of contexts is buggy. Btw: creating a context makes is current which is not a good design imo. Those actions should be separated so it should be possible to create 2nd context in main thread and then pass it to secondary thread which makes it current.

Pallav Nawani wrote:\> If you are using SDL’s rendering, then you can’t do this. You can load

> image files in a background thread, but you need to create texture in  
> the same thread that created the OpenGL context.
> 
> If you only use SDL to handle events, then you can create two opengl  
> contexts and use one to create textures in background while you display  
> using another.
> 
> On 9/20/2013 2:43 PM, slimshader wrote:
> 
> > No one is uploading textures in background thread on iOS?
> > 
> > * * *
> > 
> > SDL mailing list  
> > SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> > [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)
> 
> –  
> _Pallav Nawani_  
> _Game Designer/CEO_  
> [http://www.ironcode.com](http://www.ironcode.com)  
> Twitter: [x.com](http://twitter.com/Ironcode_Gaming)  
> Facebook: [Ironcode Gaming](http://www.facebook.com/Ironcode.Gaming)
> 
> * * *
> 
> SDL mailing list  
> SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

---

<div class="post-metadata">

**Author:** ![Pallav\_Nawani](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/pallav_nawani/32/237_2.png) [@Pallav\_Nawani](https://discourse.libsdl.org/u/Pallav_Nawani)\
**Post date:** [September 23, 2013, 5:01am UTC](https://discourse.libsdl.org/t/shared-background-gl-context-on-ios-problems/19981/5 "2013-09-23T05:01:25Z")

</div>

I haven’t tried it in iOS either (I am using SDL\_Render)  
However, I did implement background loading under Windows using Direct  
3D renderer (where you can create textures on separate threads). Later I  
had to implement loading in the main thread. It wasn’t a big performace  
hit.On 9/22/2013 10:11 PM, slimshader wrote:

> Maybe I didn’t explain clear: I do have second (shared) GL context  
> that is suppose to be current in background thread. I use this second  
> context to upload textures in the background. Problems is, it does not  
> work on iOS giving crashes. On Windows it works OK but it seems iOS  
> implementation of contexts is buggy. Btw: creating a context makes is  
> current which is not a good design imo. Those actions should be  
> separated so it should be possible to create 2nd context in main  
> thread and then pass it to secondary thread which makes it current.
> 
> Pallav Nawani wrote:  
> If you are using SDL’s rendering, then you can’t do this. You can load  
> image files in a background thread, but you need to create texture in  
> the same thread that created the OpenGL context.
> 
> If you only use SDL to handle events, then you can create two opengl  
> contexts and use one to create textures in background while you display  
> using another.
> 
> On 9/20/2013 2:43 PM, slimshader wrote:
> 
> Quote:  
> No one is uploading textures in background thread on iOS?
> 
> * * *
> 
> SDL mailing list
> 
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)
> 
> –  
> _Pallav Nawani_  
> _Game Designer/CEO_  
> [http://www.ironcode.com](http://www.ironcode.com)  
> Twitter: [x.com](http://twitter.com/Ironcode_Gaming)  
> Facebook: [Ironcode Gaming](http://www.facebook.com/Ironcode.Gaming)
> 
> * * *
> 
> SDL mailing list
> 
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)
> 
> * * *
> 
> SDL mailing list  
> SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

–  
_Pallav Nawani_  
_Game Designer/CEO_

> **[Ironcode Gaming](https://ironcode.com/)**
>
> Founded in 2004 Ironcode is an independent developer and publisher of quality games. Here at Ironcode we develop and produce original games and also provide end

Twitter: [x.com](http://twitter.com/Ironcode_Gaming)  
Facebook: [Ironcode Gaming](http://www.facebook.com/Ironcode.Gaming)

---

<div class="post-metadata">

**Author:** ![Limanima](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/l/ecae2f/32.png) [@Limanima](https://discourse.libsdl.org/u/Limanima)\
**Post date:** [October 11, 2013, 9:06pm UTC](https://discourse.libsdl.org/t/shared-background-gl-context-on-ios-problems/19981/6 "2013-10-11T21:06:18Z")

</div>

I want to do this too.  
I want to do all loadings in the background while main thread is display a nice animated loading icon.  
Is this possible or not?  
I’m need this in iOS and Android.

---

<div class="post-metadata">

**Author:** ![Limanima](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/l/ecae2f/32.png) [@Limanima](https://discourse.libsdl.org/u/Limanima)\
**Post date:** [October 11, 2013, 9:08pm UTC](https://discourse.libsdl.org/t/shared-background-gl-context-on-ios-problems/19981/7 "2013-10-11T21:08:38Z")

</div>

Limanima wrote:

> I want to do this too.  
> I want to do all loadings in the background while main thread is display a nice animated loading icon.  
> Is this possible or not?  
> I’m need this in iOS and Android.

I’m not sure why I can’t edit my own posts, so I’ll correct my writing here:

I want to do this too.  
I want to do all loadings in the background while the main thread displays a nice animated loading icon.  
Is this possible or not?  
I need this on iOS and Android.

I think it’s better now… 😃

---

<div class="post-metadata">

**Author:** ![Pallav\_Nawani](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/pallav_nawani/32/237_2.png) [@Pallav\_Nawani](https://discourse.libsdl.org/u/Pallav_Nawani)\
**Post date:** [October 12, 2013, 9:41am UTC](https://discourse.libsdl.org/t/shared-background-gl-context-on-ios-problems/19981/8 "2013-10-12T09:41:52Z")

</div>

You can load in background. However, you can do these in the main thread.  
Every frame: Load a resource, update percentage completion, draw loading  
bar. iPhone4 and lower have a single core processor anyway, so it won’t  
matter on those platforms. iPhone5 has a faster processor, so it won’t  
matter so much either.On Sat, Oct 12, 2013 at 2:38 AM, Limanima \<jorge.raposo.lima at [gmail.com](http://gmail.com)\>wrote:

> \*\*
> 
> Limanima wrote:
> 
> I want to do this too.  
> I want to do all loadings in the background while main thread is display a  
> nice animated loading icon.  
> Is this possible or not?  
> I’m need this in iOS and Android.
> 
> I’m not sure why I can’t edit my own posts, so I’ll correct my writing  
> here:
> 
> I want to do this too.  
> I want to do all loadings in the background while the main thread displays  
> a nice animated loading icon.
> 
> Is this possible or not?  
> I need this on iOS and Android.
> 
> I think it’s better now… [image: Very Happy]
> 
> * * *
> 
> SDL mailing list  
> SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

–  
_Pallav Nawani_  
_IronCode Gaming Private Limited_  
Website: [http://www.ironcode.com](http://www.ironcode.com)  
Twitter: [x.com](http://twitter.com/Ironcode_Gaming)  
Facebook: [Ironcode Gaming](http://www.facebook.com/Ironcode.Gaming)  
Mobile: _9997478768_

---

<div class="post-metadata">

**Author:** ![T\_Joseph\_Carter](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/t_joseph_carter/32/2525_2.png) [@T\_Joseph\_Carter](https://discourse.libsdl.org/u/T_Joseph_Carter)\
**Post date:** [October 12, 2013, 12:53pm UTC](https://discourse.libsdl.org/t/shared-background-gl-context-on-ios-problems/19981/9 "2013-10-12T12:53:25Z")

</div>

Regarding post editing: If you’re reading this on the forum, it’s  
actually that you’re posting to the SDL development mailing list.  
Once you send a message, you can’t edit it in people’s email inboxes,  
so no editing. 🙂

JosephOn Fri, Oct 11, 2013 at 09:08:38PM +0000, Limanima wrote:

> I’m not sure why I can’t edit my own posts, so I’ll correct my writing here:  
> [?]
