iosobjective-cuiwebviewmutexoctest

pthread_mutex_lock lets OCTest crash when UIWebView alloc


just another question for Unit testing. In one of my iOS Projects doing Unit tests, it is necessary to use a UIWebView. When i create one in - (void)setUp; or any test method, the whole Test crashes without any further information. The Debug Navigator shows only: 0 pthread_mutex_lock

I don´t do anything with locks or multithreading at all. I´ve tried to synchronize it with the same error. I´ve also tried a completely different and new project with the same behavior. This happens only when i try to alloc a UIWebview. I´ve tried to alloc UIViews as well as UIViewController and all did fine.

So my questions are:

  1. Why does this happen?
  2. How can i resolve this Problem?

The only way i see here is to use a Framework like OCMock to mock a web view. But i like to know why my tests are crashing this way...

Thanks in advance, Tomte

UPDATE: I still have this Problem in Xcode 5 as well in Xcode 4. I tried to use a mock with OCMock but i didn´t get rid of the delegates of the original UIWebView. If anyone has an example how to use a mock with all the delegates, then feel free to tell me...


Solution

  • I found this thread while searching for a similar problem, where using pthread mutexes was crashing with EXC_BAD_ACCESS + EXC_ARM_DA_ALIGN during pthread_mutex_lock(), pthread_mutex_trylock(), etc. It affected several of my iOS devices, but worked great in the simulator, on some other iOS devices, and even on some previous builds. It's a time-consuming and very frustrating problem, and ultimately may be a compiler issue.

    I later found the solution here: http://aleksmaus.blogspot.com/2012/03/excbadaccess-error-with-excarmdaalign.html

    Basically, you need to make sure that any pthread_mutex_t's are passed by pointer, rather than ever doing a value assignment on them. I don't understand why the compiler screws that up, but it is what it is.