Skip to content

Conversation

ggcrunchy
Copy link
Contributor

I took the sample in this issue and seemed to pin down where the crash itself was happening. A description and analysis are mentioned in my comments here.

The comment here, right before the task was issued, was on the right track. The Append() is being performed in the audio thread but the Run() is happening in the main thread. Since there was no synchronization an Append() would occasionally happen during a Run().

This adds a couple mutexes to guard against this. (Rtt_Scheduler seems to be a singleton, so I made them static rather than add <mutex> in the header file, but they could just as well be a static or even regular member.)

Since you could have patterns like in the test, I added Tasks to a list and synchronized them at certain points. That way the Run() shouldn't be stalling Append()s repeatedly. One possible issue is that Delete() could miss between extracting the list and synchronizing it, due to the two mutexes, but I didn't see any evidence of its use in the codebase. (Looks like apart from playing sounds, only the shell executing at startup and audio recording use the scheduler.) I think the sync in the destructor will account for any last-minute additions, since it happens in the same thread as Run().

ggcrunchy and others added 22 commits February 7, 2019 17:09
…nd buffer and assignment logic

Next up, prepare details from graphics.defineEffect()
…from Program

Slight redesign of TimeTransform with caching (to synchronize multiple invocations with a frame) and slightly less heavyweight call site
Err, was calling Modulo for sine method, heh

That said, time transform seems to work in basic test
Fixed error detection for positive number time transform inputs

Relaxed amplitude positivity requirement
Maintenance Revert Test
My mistake adding back changes made
@ggcrunchy ggcrunchy requested a review from Shchvova as a code owner December 5, 2023 06:06
Copy link
Contributor

@Shchvova Shchvova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems legit. Lets' hope it won't cause wake locks/ANRs

@Shchvova Shchvova merged commit 1beb40a into coronalabs:master Dec 5, 2023
@ggcrunchy
Copy link
Contributor Author

I've converted the scheduler to use atomic variables rather than the mutexs as it was doing. (I do wonder if the scheduler might balk if Append() is called on the same thread as Run().) Seems perfectly stable on Windows so far.

If this is needed sooner one of us can make a PR.

There are other issues: the Lua state being used on the audio thread, or rather the smart pointer to it, is not safe at all. The cleanup of arrayOfChannelToLuaCallbacks is also not secure. I will try to get on these pretty quickly, once I nail down the Mac relaunch behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants