Loading resources from a separate thread

Home / Forums / Marmalade Archive / IwGL / Loading resources from a separate thread
6 replies [Last post]
by: p3gyorgy
Status: Offline
Joined: 2012-04-11
Points: 1640

...yields this:

IwAssert failure:
Channel: IW_GL
File: IwGL.cpp
Line: 322
Expression: g_IwGLThread == pthread_self()
Message: GL called from a different thread to IwGLInit(). IwGL doesn't support multi-threaded OpenGL ES use.

I've tried moving my resource loading to a different thread as iPhone 3GS couldn't deal with loading everything in one go and I've already made sure that memory and texture size isn't an issue, as per: http://www.madewithmarmalade.com/devnet/forum/app-crashes-ipad2-iphone3gs-runs-fine-ipad3-iphone4-android-simulator

I'm loading a group consisting of a bunch of .png-s (directly - no materials specified for them) when this assertion is tripped.

What exactly is calling to OpenGL ES / causing the problem (my guess would be CIwTexture::Upload()), and how can I work around it?

Thanks in advance.
György

by: MonRoyals
Status: Offline
Joined: 2010-08-09
Points: 26970
There's no chance to upload

There's no chance to upload texutres in a separate thread. The only chance you have is to load the data from the file in a separate thread. The upload to the VRAM must happen in the main thread. Maybe this thread is interesting for you: https://www.madewithmarmalade.com/devnet/forum/asynchronous-loading-compressed-textures-2

by: p3gyorgy
Status: Offline
Joined: 2012-04-11
Points: 1640
Hi MonRoyals,

Hi MonRoyals,

Thank you for your feedback, it's very much appreciated. The thread was quite informative.

I've got suggestions that I'm okay to hang the main thread once I have rendered at least a frame (loading screen), but this proved to be bogus. (I'm loading a 512*64 texture for this, and it still crashes.)

As for loading on the separate thread I wanted to see if IwResourceManager is capable of loading CIwImages rather than CIwTextures, but that won't work (CIwImage isn't a CIwResource).

My main concern is CIwModel though - I'm not sure how can I dissect it so that its materials aren't Upload()ed until I want them to be (I remember a flag in CIwMaterials to omit Upload()ing, but it'd still mean that I need to go through all my materials and add it manually, and it doesn't look futureproof).

I'd be interested how others do the resource loading without having to write their own resource management. Them again, I also wonder whether this is really the problem...

by: bluescrn
Status: Offline
Joined: 2011-02-26
Points: 7810
I'd recommend avoiding

I'd recommend avoiding threading entirely for now if at all possible. See this thread:

http://www.madewithmarmalade.com/devnet/forum/threads-broken-ios-3

by: p3gyorgy
Status: Offline
Joined: 2012-04-11
Points: 1640
Thanks bluescrn, I've done

Thanks bluescrn, I've done just that (the thread was quite informative).

by: Jez Hammond
Status: Offline
Joined: 2010-10-11
Points: 20130
Threading is fine if you are

Threading is fine if you are willing to reinvent the wheel, I've done so and only now after all year can benefit from threading. Guess that's the advantage of teaching yourself, find a way - go with it whatever it takes! Obviously useless if you want the built in resource manager to handle polish, using that is handy but results will be generic.

by: bluescrn
Status: Offline
Joined: 2011-02-26
Points: 7810
Looks like that R9 issue on

Looks like that R9 issue on iOS should be fixed in 6.0.6 - http://www.madewithmarmalade.com/devnet/forum/marmalade-606-planning-0

Although I still wouldn't recommend using threading unless you *really* need to. Even if Marmalade works flawlessly, you could easily create timing-sensitive bugs that may only show up on certain devices, and not in the simulator.

If you're just doing it, for example, make a loading screen animate - consider alternatives. (e.g. Put the effort into speeding up the loading, so you don't spend much time on loading screens)

Latest Posts

Latest Comments

Top Contributors

  • Chris D : 27,010
  • MonRoyals : 26,970
  • Salman : 26,720
  • Jez Hammond : 20,130
  • pjan : 11,150
  • gjw : 10,350
  • Paolo Oliverio : 9,640
  • Beaker_2 : 8,390
  • Kite : 8,210
  • bluescrn : 7,810