@wihu: glad you like it.
Loading assets before entering the game, loading screen.
(37 posts) (16 voices)-
Posted 1 year ago #
-
Greetngs,
I just wanted to chime in about Thomvis's code as well. It is a really nice solution to the loading screen issue. At first glance it does look a tad complicated (especially if you are unfamiliar with protocols) but once you spend a little time with it you will see it is fairly straightforward and really does a great job loading assets in the background.
For simplicity, I wanted to post this link to Thomvis's code: http://gist.github.com/Thomvis as it's easy to miss a file or two (or it was for me!) in the previous set of links. Anyway, the files you need are all dated October 10th and October 2nd. Just create a sample cocos2d program and add them all in and change your delegate as needed. Then just Build and Go and look at the console.
@Thomvis, If you ever are so inclined, I think alot more people would try the code if it was downloadable as a complete XCode project rather than a separate set of files. Just a thought. In any case, it is a great solution to a common problem and thank you for posting the code.
Regards,
Q
PS(No offense intended to the other solutions posted on this thread, they all have their advantages and disadvantages, I just thought it worth giving props to Thomvis's code as it is definitely worth considering for anyone facing the whole loading assets issue.).Posted 1 year ago # -
Uh actually.. Im still having problem with Preloading assets with multiple threads, I think there is nothing wrong with Thomvis's code/solution, probably Im just missing something. So, after a while testing the game with preloader, SOME times I got this error appearing on the console:
OpenGL error 0x0502 in - [EAGLView swapBuffers]
sometimes some of the sprites turn out to be blank/white rectangle, and sometimes I got EXC_BAD_ACCESS,
then I checked the crash log report:
Date/Time: 2010-05-08 01:22:53.668 +0800
OS Version: Mac OS X 10.6.2 (10C2234)
Report Version: 6Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000000000018
Crashed Thread: 0Application Specific Information:
iPhone Simulator 3.1 (139.1), iPhone OS 3.0 (7A341)Thread 0 Crashed:
0 ??? 0x07b336a7 0 + 129185447
1 ??? 0x07b331f9 0 + 129184249
2 GLRendererFloat 0x005e2f2c gldDestroyQuery + 10459
3 GLEngine 0x03cd8721 gliDestroyContext + 137700
4 GLEngine 0x03d40a05 gliDestroyContext + 564424
5 GLEngine 0x03d40fa7 gliDestroyContext + 565866
6 OpenGLES 0x005052e6 glDrawArrays + 57
7 TestGame 0x0004e7f1 -[CCSprite draw] + 498 (CCSprite.m:521)
8 TestGame 0x0003f2f4 -[CCNode visit] + 502 (CCNode.m:440)
9 TestGame 0x0003f3d6 -[CCNode visit] + 728 (CCNode.m:440)
10 TestGame 0x0003f3d6 -[CCNode visit] + 728 (CCNode.m:440)
11 TestGame 0x00025362 -[CCDirector mainLoop] + 258 (CCDirector.m:227)
12 Foundation 0x305355cd __NSFireTimer + 141
13 CoreFoundation 0x302454a0 CFRunLoopRunSpecific + 3696
14 CoreFoundation 0x30244628 CFRunLoopRunInMode + 88
15 GraphicsServices 0x32044c31 GSEventRunModal + 217
16 GraphicsServices 0x32044cf6 GSEventRun + 115
17 UIKit 0x309021ee UIApplicationMain + 1157
18 TestGame 0x00002374 main + 82 (main.m:13)
19 TestGame 0x000022f6 start + 54Thread 1:
0 libSystem.B.dylib 0x917568da mach_msg_trap + 10
1 libSystem.B.dylib 0x91757047 mach_msg + 68
2 CoreFoundation 0x30244d62 CFRunLoopRunSpecific + 1842
3 CoreFoundation 0x30244628 CFRunLoopRunInMode + 88
4 WebCore 0x3588ea13 RunWebThread(void*) + 467
5 libSystem.B.dylib 0x91783fbd _pthread_start + 345
6 libSystem.B.dylib 0x91783e42 thread_start + 34Thread 2:
0 libSystem.B.dylib 0x91784806 __semwait_signal + 10
1 libSystem.B.dylib 0x91786158 pthread_cond_wait$UNIX2003 + 73
2 libGLProgrammability.dylib 0x06101753 glvmPreInit + 1235
3 libSystem.B.dylib 0x91783fbd _pthread_start + 345
4 libSystem.B.dylib 0x91783e42 thread_start + 34Thread 3:
0 TestGame 0x0000f9a3 -[GameLayer loadWithDelegate:] + 980 (GameLayer.m:83)
1 TestGame 0x0000ec10 -[Loader main] + 380 (Loader.m:81)
2 Foundation 0x30577345 -[NSOperation start] + 469
3 Foundation 0x3050a79d -[NSThread main] + 45
4 Foundation 0x3050a338 __NSThread__main__ + 280
5 libSystem.B.dylib 0x91783fbd _pthread_start + 345
6 libSystem.B.dylib 0x91783e42 thread_start + 34Thread 0 crashed with X86 Thread State (32-bit):
eax: 0x00000000 ebx: 0x04039a80 ecx: 0x04039200 edx: 0x04038800
edi: 0x04039200 esi: 0x07b328c0 ebp: 0xbfffd7b8 esp: 0xbfffd060
ss: 0x0000001f efl: 0x00010282 eip: 0x07b336a7 cs: 0x00000017
ds: 0x0000001f es: 0x0000001f fs: 0x00000000 gs: 0x00000037
cr2: 0x00000018
any help would be very much appreciated.
Posted 1 year ago # -
Are you implementing
- (BOOL) loadingUsesOpenGL;to return YES in the Loadables that load textures?Posted 1 year ago # -
yes, i am, but I can not see where it is being used? Because the loader doesnt seem to call it anywhere.
Posted 1 year ago # -
Looking again at my code I realise that the loadingUsesOpenGL method is not used anymore. The thing with the white textures occurs when more than one thread simultaniously load textures. The OpenGL calls should be synchronized. I guess the current cocos version does this differently from when I wrote that code (it was then v0.82). I'm afraid I don't have the time to modify my code to make it up to date with the current version. What should be done is that the loading of textures in the new Loader threads is done similar to
-(void) addImageWithAsyncObject:(CCAsyncObject*)asyncinCCTextureCache(the locking part, not the new thread creation).Posted 1 year ago # -
@Thomvis: Sorry I havent gotten back to you for so long, I kept this problem aside, and was doing something else, but now I think I managed to fix the problem, I am not sure if Im doing it the way you intended, but I changed the main method in the Loader.m as follows:
-(void)main { if (_async && ![NSThread isMainThread]) { //[EAGLContext setCurrentContext:[[[CCDirector sharedDirector] openGLView] context]]; [_contextLock lock]; if (auxEAGLcontext == nil) { auxEAGLcontext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1 sharegroup:[[[[CCDirector sharedDirector] openGLView] context] sharegroup]]; if (!auxEAGLcontext) { NSLog(@"[Loader] main: Could not create EAGL context"); } } if ([EAGLContext setCurrentContext:auxEAGLcontext]) { // load for (NSObject<Loadable> *loadable in _loadables) { [loadable loadWithDelegate:self]; } [EAGLContext setCurrentContext:nil]; } else { NSLog(@"[Loader] main: EAGLContext error"); } [_contextLock unlock]; } else { for (NSObject<Loadable> *loadable in _loadables) { [loadable loadWithDelegate:self]; } } }it seems to work fine and more stable, at least, I havent seen any OpenGL errors in the console.
Thanks a lot.Posted 1 year ago #
Reply
You must log in to post.