Irritating intermittent bug with set player filename

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
bbalmerTotalFluency
Posts: 84
Joined: Mon Apr 06, 2020 1:19 pm
Contact:

Irritating intermittent bug with set player filename

Post by bbalmerTotalFluency » Sat Jul 06, 2024 2:24 am

Update: problem fixed

The KEY change that finally fixed everything was creating a new player each fifth time it was used. That was a suggestion from SWEdeAndy - so thanks for that!!!

It does look like it was a memory leak and that setting the filename to empty BEFORE setting it to the real filename did not fix the memory leak, as supposed.

This thing was driving me nuts. So I am VERY happy it is over with.

grateful programmer of Thailand

============

I have a strange bug in my software that crashes either the livecode ide version of my app or the macOS standalone. The same line of code will run successfully for an average of around 200 times without issue then the next time that line runs the code crashes. It does not appear to be about the accumulation of some problem because it might crash after 20 and it might take till 400 or more. The action being dealt with is simple and consistent - setting the filename of a player object.

I wonder if anyone here is familiar with this situation?

line of code: set the filename of player "audio" of me to tFile

tFile was calculated about 4 lines earlier and since it was calculated I have written to a log file 3 times so I don't think adding a "wait 10 milliseconds" is going to help this time though it has helped in the past with other situations.

I've checked that the tFile address is correct - which it is. I've checked that the audio file it is calling is present and named correctly. It is. What I don't know is if it happens on playing the same files (chosen at random and just started investigating that) but I doubt it since the file it most recently crashed on is in perfect working order.

update: last 3 crashes have all been the line above, all with different audio files

I think I'm correct in saying that with macOS you have to use a player rather than just play the file (AAC) directly.

LC: 10.0.0 - DP 7
macOS: Sonoma 14.2.1
macmini2 - M1

Driving me nuts!

The programme does not get as far as playing the audio file. It is the action of setting the filename that crashes it, something I would have thought was innocent enough. When it crashes, it will have had the previous filename present, so it isn't being blank that is causing trouble.

code is below. As you can see my log gets the filename of the player and I can see that that name is correct and the file exists at that address etc. etc.

if the platform = "macOS" then
set the filename of player "audio" of me to tFile -- tFile calculated 4 lines ago
fileAddLine "log", "practice" && n() && the filename of player "audio" of me -- n() gets the line number
wait 10 milliseconds
start player "audio" of me
fileAddLine "log", "practice" && n() && the number of lines in pendingMessages()
end if

update2: I've increased the wait time to 30 milliseconds; no benefit.
I have tried opening the file directly from the filing system using quicktime player. It is perfectly happy to play it.
Last edited by bbalmerTotalFluency on Wed Jul 17, 2024 3:55 am, edited 4 times in total.

SWEdeAndy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 324
Joined: Sat Aug 16, 2008 9:48 am
Contact:

Re: Irritating intermittent bug with set player filename

Post by SWEdeAndy » Sat Jul 06, 2024 10:37 am

This is interesting, as I have wrestled with a very similar problem a few years ago, but then it concerned the mobile player on iOS. Specifically, it made the app freeze on certain iPads after a random number of changes to the filename of the player. It was never properly resolved, and I had to use a workaround that consisted of creating the player and set its filename on startup and never change it. For that app I only needed 16 audio files in total, so it was an acceptable workaround for that project.

Anyway, some of the things I tried had an impact on the crash/hang frequency (if not eliminating it), so for what it's worth, here are some ideas:

1) Put set the currentTime of player "audio" of me to zero before the line that starts the player.
2) In case you have acceleratedRendering turned on, turn it off at startup. (This may have had an impact only on mobile, but worth a shot).
3) Set the filename of the player to empty before setting it to the new filename.
4) Delete the player and create a new one each time (seems excessive, but might help).
5) You already tried "wait x milliseconds" before starting the player - does it make any difference to add "with messages" to that?
6) Are you working on multiple monitors? There's a bug report on issues with players and multiple monitors: https://quality.livecode.com/show_bug.cgi?id=20707

Hope any of this may help.
Andreas Bergendal
Independent app and system developer
Free LC dev tools: https://github.com/wheninspace
(WIS_WebDeployHelper, WIS_ScriptDependencies, WIS_BrowserAnimation)
WhenInSpace: https://wheninspace.com

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Irritating intermittent bug with set player filename

Post by jacque » Sat Jul 06, 2024 5:55 pm

Does it crash (IDE quits) or hang (no response, freezes) ? I've had trouble in the past with hangs which I think we're due to memory. I fixed it by setting the filename to empty, waiting a few milliseconds with messages, and then setting the new filename. Setting it to empty clears out the old one and frees memory. Also there used to be a bug where setting the currentTime to 0 caused an issue but setting it to 1 was okay. I got in the habit of doing that. There's virtually no difference in playback. That may be fixed now but the workaround doesn't hurt.

The fact that the problem is intermittent seems to point to memory issues.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

bbalmerTotalFluency
Posts: 84
Joined: Mon Apr 06, 2020 1:19 pm
Contact:

Re: Irritating intermittent bug with set player filename

Post by bbalmerTotalFluency » Sun Jul 07, 2024 1:41 am

Thank you, SWEdeAndy and Jaques.

Not on multiple monitors. Not on mobile. Crashes doesn't hang. Crashes hard with a very lengthy report from Apple from which I derive nothing useful (that is likely more about me than the report).

Update: I inserted another logging line which is written between setting the filename and start player. It is definitely setting the filename that crashes the app. It doesn't get as far as trying to start the player (which is when I would have intuitively guessed the trouble would begin).

Yes, the intermittent nature is disturbing. It sounds like memory issues or maybe occasionally the OS is busy and it needs a longer delay before setting the name but doesn't get one - just gets the standard length. It's extremely annoying. I crashed it again this morning, minutes ago, but it took 40 minutes to get a crash, so I could benefit from my new logging line between set filename and start.

I'll try those various suggestions in order of implementation effort and report back if I get anywhere. The idea of destroying the player and recreating each time sounds drastic BUT if it works it works. I would prefer that my app didn't crash for my customers.

I thought someone might have had this issue before. It seems I've been unlucky and it is not a common thing. Nor has it never happened to anyone else.

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Re: Irritating intermittent bug with set player filename

Post by SparkOut » Sun Jul 07, 2024 10:10 am

Is it possible the filename is somehow corrupted? Is it read from a field, selected from a list, etc? Could it possibly concatenate the filename with some other data anyhow?
Do you have any "non-Western" characters in the filename? (That wouldn't explain why it works sometimes but not others.)
Have you tried the same on Windows, to tell whether the crash is Mac specific?

bbalmerTotalFluency
Posts: 84
Joined: Mon Apr 06, 2020 1:19 pm
Contact:

Re: Irritating intermittent bug with set player filename

Post by bbalmerTotalFluency » Sun Jul 07, 2024 3:44 pm

Mr. Sparkout.

Good questions all. Don't have a windows machine so can't try on that platform and anyhow other than diagnostics, I am not producing the app for windows.

Corrupted filename: no. In my log file I get the exact name that is the filename of the player and it's fine. No funny characters, no concatenation. It's very bizarre.

bbalmerTotalFluency
Posts: 84
Joined: Mon Apr 06, 2020 1:19 pm
Contact:

Re: Irritating intermittent bug with set player filename

Post by bbalmerTotalFluency » Sun Jul 07, 2024 3:48 pm

Update:

Many thanks for SWEdeAndy and Jacques. I implemented several of their suggestions and I can't say I understand exactly why, but for now it has stopped crashing. I've done 40 minutes now, about 600 clicks no crashes.

I'll update again if it crashes soon or I can home in on the exact factor that made the difference. As I was a bit desperate for time, I just did several things in one go.

So I now am using wait with messages and putting an empty filename into the player first before setting the name to the correct value. I also added another logging line so effectively another short delay.

But for anyone with the same problem - those two suggestions together + my extra pause seem to have done the trick.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Irritating intermittent bug with set player filename

Post by jacque » Sun Jul 07, 2024 5:15 pm

If it does crash again, save the Apple report and include it in a bug report along with your stack. Crashes get top priority fixes and the team wants to know. You can select and copy the crash report text and paste it into a text file to add to the bug report. And don't worry, those things mean little to most of us but the team understands them.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

bbalmerTotalFluency
Posts: 84
Joined: Mon Apr 06, 2020 1:19 pm
Contact:

Re: Irritating intermittent bug with set player filename

Post by bbalmerTotalFluency » Tue Jul 09, 2024 12:37 am

Thanks again Jacque, I will.

Although the problem seems to have been 100% resolved.

Post Reply