Tasharen Entertainment Forum

Support => Other Packages => Topic started by: jchowdown on October 23, 2013, 07:49:39 PM

Title: FOWSystem refactor (using coroutines to init) now crashes on teardown
Post by: jchowdown on October 23, 2013, 07:49:39 PM
Hi, I modified the FOW system to not block when being initialized. We had to timeslice it because the initial CreateGrid() was taking too long and we need to show some sort of animated loading screen.

Basically what I did was:
1) turned the FOWSystem.Start method into a coroutine that yields several times during the CreateGrid() call. This new coroutine is still responsible for spawning the update thread.
2) added a 'm_initialized' that starts out as false and is set to true at the end of my coroutine. FOWSystem.Update() changed to return if m_initialized is false.

Now all this runs fine and dandy in the Editor but as soon as I run it on my ipad I get a crash when I load another scene:
http://screencast.com/t/Z5AbAu8WOHVz (within UpdateBuffer)
The crash happens at various times within FOWSystem.OnDestroy. Sometimes mThread.Abort() has been called but other times it hasn't been called yet.

Has anyone seen this before? Can the worker thread even be started by a coroutine? I tried moving the thread start to Update() but it didn't seem to make a difference.

Thanks very much,
Jeff
Title: Re: FOWSystem refactor (using coroutines to init) now crashes on teardown
Post by: ArenMook on October 25, 2013, 01:01:23 AM
You can start a worker thread just fine, but keep in mind that you can't have both the main thread and the worker thread access the same memory at the same time, which often happens when you're working with different threads. You need to use lock() to ensure that only one thread modifies data at a time.