PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Threads synchronization. Display lock.

tinybulb.com · 12 Mar 2009, 23:56 UTC
My current application mixing platform independed code with platfor depended iPhone OS code. UIKit used to implement menu system. After adding this functionality application starts to crash randomly(some times no, some times yes) on same IBAction, which is used in my app for changing level(and as result unload old resources and load new resources).

Common stack-trace for such crash is:
#0 0x31287574 in Copy8888Span
#1 0x31289920 in glTexSubImage2D
#2 0x000369d2 in EdgeGL_UpdateTextureData at wrap_glesmac.h:293
#3 0x0000d31a in ClassEDisplay::WriteTextureData at emod_dsp.cpp:1354
#4 0x0000e6b8 in ClassEDisplay::UploadTexture at emod_dsp.cpp:2850
#5 0x00006b32 in CResourceManager::LoadBallSet at CResourceManager.cpp:119 << My code, on this line of code I do the following display->UploadTexture(texture);

Texture which display trys to upload always initialized properly. Crash happens always on random resource, not on the same. Sometimes application works fine, sometimes it is enter the level, but some of resources looks incorrectly(textures looks like have a chunks of free or not filled properly memoy). As I think such situation may caused by locking of display or it's parts, because it were accessed at the same time from two places in code(in IBAction and in OnNextFrame) and as result incorrect filling of data in it. Can you propose the way how such situation can be avoided? Do you have any standard ways to stop updates during resource loading etc.? In case if it is not the reason of crashes, can you suggest what it can be by provided stack-trace?

Thanks in advance,
Nikita Leonov
tinybulb.com · 13 Mar 2009, 08:02 UTC
I did small test, and looks like i were right. In case if i do loading of resources for level in OnDisplayInit everything works fine, but in case if i loads resources for level from some other places in code when main loop started and OnNextFrame called repeatedly - application become crash randomly or if didn't crashed - textures looks damaged sometimes.
Hi Tinybulb,

When using threads we recommend making a queue of CreateSurface calls to process, then create them one by one (otherwise texture handles and data may interfere).