Advertise Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

sdkIQ for iPhone
($4.99)

Your First iPhone App
($1.99)

iPhone Code Generator
($9.99)

Dual Matches
($0.99)

Calcuccino Programmers' Calculator
($2.99)

SDKtoday
(free)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-12-2010, 02:52 AM   #1 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 5
Unhappy Loading textures in the background?

So I am trying to do something that is not new or revolutionary...display a progress bar during the loading of my levels.

To do this I spawn a new thread to do all the loading, while the main thread draws the progress bar...seems like it should work huh?

Nope!

When I go to render my world I get nothing but white...

If I do everything in the main thread (which of course doesn't allow the progress bar to work) everything renders fine.

So my question is wtf?!

I've been looking at this for the last two days and am really at my wit's end.

I was thinking that maybe because I am loading my textures in a different thread only that thread would know about them...so I created a singleton object to hold all my textures...so shouldn't matter what thread is populating it...since it's a singleton...it should be available to everyone? I mean the next thread (the main thread) that grabs it should get the correct data...right?

During debugging I can inspect all my texture objects and sure enough everything is there...name, image name, texture coords, verts, etc... But sadly only white is displayed =(

Anyone know what's going on here?

Thank you for your time.
bluelobster is offline   Reply With Quote
Old 03-12-2010, 02:56 AM   #2 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 248
Default

Quote:
Originally Posted by bluelobster View Post

To do this I spawn a new thread to do all the loading, while the main thread draws the progress bar...seems like it should work huh?
What happens when you load in the main thread and do the progress bar in the new thread?
georgeburns is offline   Reply With Quote
Old 03-12-2010, 03:09 AM   #3 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 5
Default

Good question.

Maybe I don't understand how threads work but here is what I understand needs to happen...

For the progress bar:

Code:
// level load
- (void) loadLevel
{
  // do some stuff
  
  // update percentDone

  // do more stuff

  // update percentDone
}

// render
- (void) render
{
  // figure out the bar length
  barLength = barLength * percentDone;
  // render the bar
  renderBar();
}
So the problem here is the core of the progress bar update is done in the render loop...I don't know that a thread that is created would be able to access the render loop since it is setup and called from the grand daddy game loop. Know what I mean?

Is it possible to render stuff in a separate thread? I don't know how to do that...

What's nice about what i'm doing now...well not that nice because it doesn't work...but I can let my main game loop go rendering the frames as it does and when I spawn off the thread to do the loading work it doesn't have to worry about being involved with the renderer...
bluelobster is offline   Reply With Quote
Old 03-12-2010, 05:34 AM   #4 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 248
Default

Quote:
Originally Posted by bluelobster View Post
Good question.

Maybe I don't understand how threads work but here is what I understand needs to happen...

For the progress bar:

Code:
// level load
- (void) loadLevel
{
  // do some stuff
  
  // update percentDone

  // do more stuff

  // update percentDone
}

// render
- (void) render
{
  // figure out the bar length
  barLength = barLength * percentDone;
  // render the bar
  renderBar();
}
So the problem here is the core of the progress bar update is done in the render loop...I don't know that a thread that is created would be able to access the render loop since it is setup and called from the grand daddy game loop. Know what I mean?

Is it possible to render stuff in a separate thread? I don't know how to do that...

What's nice about what i'm doing now...well not that nice because it doesn't work...but I can let my main game loop go rendering the frames as it does and when I spawn off the thread to do the loading work it doesn't have to worry about being involved with the renderer...
I'm not seeing any code for the threading.
georgeburns is offline   Reply With Quote
Old 03-12-2010, 10:33 AM   #5 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 5
Default

Quote:
Originally Posted by georgeburns View Post
I'm not seeing any code for the threading.
Oh here you go...

Code:
- (void) spawnThread
{
  [NSThread detachNewThreadSelector:@selector(loadLevel) toTarget:self withObject:nil];
}

// level load
- (void) loadLevel
{
  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

  // do some stuff
  
  // update shared variable
  percentDone += x;

  // do more stuff

  // update percentDone
  percentDone += x;

  [pool release];
}

// render
- (void) render
{
  // figure out the bar length
  barLength = barLength * percentDone;
  // render the bar
  [bar render];

  // render rest of the scene
}
bluelobster is offline   Reply With Quote
Old 03-12-2010, 11:20 AM   #6 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 5
Default

Hmmm I think I may have found the problem...

It seems this thread I am spawning off may not have an OpenGL context?


*Edit* it has an opengl context but doesn't have the same one the main thread is use...

Last edited by bluelobster; 03-12-2010 at 03:08 PM.
bluelobster is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


» Advertisements
» Stats
Members: 41,862
Threads: 49,770
Posts: 213,057
Top Poster: BrianSlick (3,139)
Welcome to our newest member, futurevilla216
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 07:03 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0