Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Multi-threading in OpenGL ES from Cocos2D iOS App

  1. #1
    Member Newbie
    Join Date
    Oct 2016
    Posts
    33

    Multi-threading in OpenGL ES from Cocos2D iOS App

    test... I just spent 10 minutes writing a post and when i submitted it, it said I used URLS or words that were not allowed and I lost everything!!! So I am testing to make sure I can write anything at all before I try again.

    ARRGH!!!

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Posts
    4,655
    Ouch. Sorry you lost your post. So the forum didn't give you an option to copy/paste your text off into a file? If so, that's annoying.

    That said, I haven't heard anyone else reporting that they couldn't post but didn't use any URLs. So could it be that your post matched some disallowed words?

    Hope you decide to rewrite your post. This time though, you might be sure to save a copy of your text into a file before you hit post, just in case something goes wrong.

  3. #3
    Member Newbie
    Join Date
    Oct 2016
    Posts
    33
    Quote Originally Posted by Dark Photon View Post
    Ouch. Sorry you lost your post. So the forum didn't give you an option to copy/paste your text off into a file? If so, that's annoying.

    That said, I haven't heard anyone else reporting that they couldn't post but didn't use any URLs. So could it be that your post matched some disallowed words?

    Hope you decide to rewrite your post. This time though, you might be sure to save a copy of your text into a file before you hit post, just in case something goes wrong.

    Hi. Yeah I re-wrote it (in a text editor this time), but wasn't able to post it either. I didn't realize I could attach a file... So, ok I am attaching my question here as a text file. Perhaps someone here can use it as a means to debug why the site wouldn't accept it. It has code snippets in it, that's the only thing I can imagine it got confused that some code was a url or something, despite it being within the CODE tags...

    Anyway my question is about multi-threading/multi-contexts in OpenGL ES from within the framework of a Cocos2D iOS application.

    Thank you for any help.
    Attached Files Attached Files

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    3,105
    Quote Originally Posted by patrick99e99 View Post
    The only problem is, quite often during level instantiation, I see in the console a gazillion logs of "OpenGL error 0x0502 in -[CCSprite draw] 530".
    0x0502 is GL_INVALID_OPERATION, which typically means that all of the parameters are valid in themselves (invalid parameters result in GL_INVALID_ENUM or GL_INVALID_VALUE) but some aspect of the state isn't valid for the current operation.

    Quote Originally Posted by patrick99e99 View Post
    Does anyone see why I would be getting all these errors and how I might be able to prevent it?
    First, check that you aren't inadvertently using the same context in more than one thread.

    Try adding CHECK_GL_ERROR_DEBUG() in more places, so that you can determine exactly which function is generating the error.

    I can't really help much beyond that, as I'm not familiar with either iOS or ObjectiveC.

  5. #5
    Member Newbie
    Join Date
    Oct 2016
    Posts
    33
    Quote Originally Posted by GClements View Post
    Try adding CHECK_GL_ERROR_DEBUG() in more places, so that you can determine exactly which function is generating the error.
    Gah!! This forum did it again where it rejected my reply and I am having to retype it all over again!!! ... I need to get in the habit of always writing in a text editor.

    Anyway--- What I said was, I did more debug calls and I found that the errors are all getting thrown in the three calls to glVertexAttribPointer()

    I don't know off the top of my head any way to really know if two threads are accidentally using the same context. My code certainly is not... And from looking through Cocos2d's codebase, I see that there is only one place where an auxiliary context is created and that is a method for asynchronously loading textures, which I made certain my code is not making use of as that seemed like potentially a way to end up with the wrong context.

    I also noticed that when Cocos2d sets itself up, it has an option to allocate the EAGLContext object with a share group, but when I inspected this, there is no share group. Could that be a solution to my problem? Should I have a share group?

  6. #6
    Member Newbie
    Join Date
    Oct 2016
    Posts
    33
    Quote Originally Posted by patrick99e99 View Post
    Could that be a solution to my problem? Should I have a share group?
    Hmm, well I guess that's not the problem.. I tried newing up a sharegroup and passing it in, those errors still happen.

  7. #7
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    3,105
    Quote Originally Posted by patrick99e99 View Post
    Anyway--- What I said was, I did more debug calls and I found that the errors are all getting thrown in the three calls to glVertexAttribPointer()
    For OpenGL ES 3.0 (and desktop OpenGL), the error can be generated if no buffer is bound to the GL_ARRAY_BUFFER target, or if the type parameter is one of the packed formats but the number of fields doesn't much the size parameter.

    For OpenGL ES 2.0, glVertexAttribPointer() shouldn't generate GL_INVALID_OPERATION for any reason. Client-side vertex arrays are supported (i.e. it's not necessary to have an array buffer bound) and packed formats don't exist.

    Quote Originally Posted by patrick99e99 View Post
    I also noticed that when Cocos2d sets itself up, it has an option to allocate the EAGLContext object with a share group, but when I inspected this, there is no share group. Could that be a solution to my problem? Should I have a share group?
    If your contexts don't share data, any textures, buffers, programs, etc are specific to the context which was current when they were created, so any objects which are common to multiple contexts need to be created separately for each context.

  8. #8
    Member Newbie
    Join Date
    Oct 2016
    Posts
    33
    Quote Originally Posted by GClements View Post
    For OpenGL ES 3.0 (and desktop OpenGL), the error can be generated if no buffer is bound to the GL_ARRAY_BUFFER target, or if the type parameter is one of the packed formats but the number of fields doesn't much the size parameter.

    For OpenGL ES 2.0, glVertexAttribPointer() shouldn't generate GL_INVALID_OPERATION for any reason. Client-side vertex arrays are supported (i.e. it's not necessary to have an array buffer bound) and packed formats don't exist.

    Hmm.. Well my version of Cocos2d is using 2.0...

    Quote Originally Posted by GClements View Post
    If your contexts don't share data, any textures, buffers, programs, etc are specific to the context which was current when they were created, so any objects which are common to multiple contexts need to be created separately for each context.
    I'm a little confused by what you're saying here. Cocos2d has a texture cache singleton object which holds all the textures in memory (just with a basic key value store)--- so anytime you create a sprite, it will automatically store that texture in the cache, and access it from there the next to you attempt to create that same sprite. That said, both of my threads / contexts are using textures from there (and I can think of at least two textures that are being used on the screen at the same time from both contexts). That is the problem?

  9. #9
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    3,105
    To be honest, I think that you should be asking in a Cocos2D forum. It sounds like Cocos2D does some kind of context management itself (there's no way to have a shared texture cache otherwise, as textures which are created using one context only exist in that context and in contexts which share data with it).

  10. #10
    Member Newbie
    Join Date
    Oct 2016
    Posts
    33
    Quote Originally Posted by GClements View Post
    To be honest, I think that you should be asking in a Cocos2D forum. It sounds like Cocos2D does some kind of context management itself (there's no way to have a shared texture cache otherwise, as textures which are created using one context only exist in that context and in contexts which share data with it).
    Sigh.. Yeah I did that already. No one was able to help me. I just got a response saying cocos isn't meant to be multi-threaded, which to me is an unacceptable answer.

Page 1 of 2 12 LastLast

Similar Threads

  1. Multi-threading and OpenGL context problem on Win32
    By leonmaxx in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 03-02-2014, 05:28 AM
  2. Specific Multi Threading usage in OpenGL
    By Jose Goruka in forum OpenGL: Advanced Coding
    Replies: 12
    Last Post: 05-09-2011, 01:42 PM
  3. multi threading in openGL
    By jayaprakash in forum OpenGL: Windows
    Replies: 1
    Last Post: 01-29-2009, 07:19 AM
  4. LP: Multi-threading?
    By Dirk in forum OpenGL: Advanced Coding
    Replies: 13
    Last Post: 06-27-2007, 02:48 PM
  5. OpenGL multi threading under Windows and C
    By hanner in forum OpenGL: Advanced Coding
    Replies: 6
    Last Post: 07-01-2003, 06:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean