ffd8 / P5LIVE

p5.js collaborative live-coding vj environment!
https://p5live.org
GNU General Public License v3.0
229 stars 35 forks source link

"tab freeze" in chrome halts sketch after some time #96

Closed kaosbeat closed 1 month ago

kaosbeat commented 1 month ago

I have a sketch running as part of an installation. It's on a keyboardless/mouseless mac mini, connected to a large screen projection. A virgin mac mini with chrome and an offline P5Live installation.

All is working fine, but after some time the patch freezes. connecting the Bluetooth mouse and moving it resumes the sketch.

I suspect chrome is doing "energy saving" and freezes all foreground tabs (reference)

is there a way to keep the tab active, in code?

ffd8 commented 1 month ago

Heyhey awesome setup – curious what you have running?

How interesting.. haven't experienced this, even when recently exhibiting a few imacs running P5LIVE for a week long exhibition (2 of them had no user input but kept doing their thing). Have you already disabled 'eco render' in the settings panel? That pauses the p5.js sketch when the focus is lost from the window.. I was opening the chrome browser from terminal using the kiosk option (don't have the exact CLI command here, but it should be something like): /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome -kiosk URL_PATH_HERE

Some suggest loading it with this flag also helps (could be toggled on when the kiosk mode is used?): --disable-hang-monitor

Let me know if/what works...

kaosbeat commented 1 month ago

Running from terminal with that exact switch --kiosk. I'll look into your links. Osx version is Sonoma, which apparently has the power management rehauled. I haven't used osx since long... Developed this on a linux laptop where it ran smooth and long...

On Wed, Sep 25, 2024, 21:07 ffd8 @.***> wrote:

Heyhey awesome setup – curious what you have running?

How interesting.. haven't experienced this, even when recently exhibiting a few imacs running P5LIVE for a week long exhibition (2 of them had no user input but kept doing their thing). Have you already disabled 'eco render' in the settings panel? That pauses the p5.js sketch when the focus is lost from the window.. I was opening the chrome browser from terminal using the kiosk option (don't have the exact CLI command here, but it should be something like): /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome -kiosk URL_PATH_HERE

Some suggest https://stackoverflow.com/a/66311152 loading it with this flag also helps (could be toggled on when the kiosk mode is used?): --disable-hang-monitor

Let me know if/what works...

— Reply to this email directly, view it on GitHub https://github.com/ffd8/P5LIVE/issues/96#issuecomment-2374959559, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABR6VH7YZDOQLHATNBV5NDZYMCWRAVCNFSM6AAAAABO3CU34KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNZUHE2TSNJVHE . You are receiving this because you authored the thread.Message ID: @.***>

kaosbeat commented 1 month ago

I here's what I tried overnight.

I loaded a video (using P5s createVideo) and played it with one pixel only visible on a loop. I read somewhere (source missing) that having media playback will stop the browser from freezing. Unfortunately the page crashed (well the popup "your page is unresponsive, wait/kill" was there when I checked)

Another thing I tried was rerunning the setup function periodically by adding setInterval(function(){ setup() },10000); to my setup(){} I would do it like every hour or so but this seems to crash the page after like 10 times. Might still work as I will reboot the mac every day. This though makes me suspect I have a (tiny) memory problem somewhere in my code... but maybe it is not triggered on my 64Gb RAM computer vs the 8Gb Macmini?

I also tried completely reloading the page, but for some reason puttingsetInterval(function(){window.location.reload(true);}, 1000) does not execute the code after a reload

The whole thing is just displaying some animated text with author names (a lot though, like 1500) for a festivity in a local book shop. I disabled the hydra layer, tried to delete and reinstance all arrays containing text particle objects, I tracked the length of my object arrays, I tried to do some memory profiling in chrome (not an expert at all). I also reduced the list of names from 1500 to 15, disabled the check for dublkicate names on screen and still get the same behaviour. Which again makes me think there is a performance issue. Drafting a minimal crash example now

kaosbeat commented 1 month ago

Ok I went ahead and deleted about everything. it still crashes... I tried it with one of the official examples (_canvas_small)
Continuously rerunning the setup function always crashes P5Live
// setInterval(function(){ setup() },1000); .

ffd8 commented 1 month ago

Originally I was going to suggest to have the browser console open and see if anything spits out when it crashes? But it seemed to be a browser pausing issue.. now it sounds like a crashing issue.. i wonder the following things:

Hope one of those helps... and not the GPU side... + test on another machine.. same OS... maybe it's the macmini? + what happens if you just plug a mouse/keyboard into it without using it?

kaosbeat commented 1 month ago

I finally I wrote an applescript that kills and starts chrome every hour, short flash, but seems to solve the problem. You can do chrome://restart from the address bar, but unfortunately not from javascript itself I was thinking along the lines of using an older chromium/P5js but haven't tried it, as I had similar problems in firefox

the chromium lectron wrapper seems a good idea, gonna check that out. Thanks for helping out

Just a reminder that chrome/firefox always seem to crash when rerunning setup() 10 times in a row... That might have been an issue thta was overlooked earlier, but came up as I tried it as one of the solutions.. some memory cleanup not being done on hard recompile?

On Thu, Sep 26, 2024 at 2:33 PM ffd8 @.***> wrote:

Originally I was going to suggest to have the browser console open and see if anything spits out when it crashes? But it seemed to be a browser pausing issue.. now it sounds like a crashing issue.. i wonder the following things:

  • hardware issue, GPU? ram size?

  • browser issue, new version with a bug and should revert to earlier one?

  • p5.js version issue? (or P5LIVE, using the latest?) i still need to load the latest p5.js in P5LIVE ,but you can do it manually by dragging the files into includes/p5/ and drop the latest 1.1.0 version of p5.min.js in there (in offline mode, it uses that, not the CDN of course)

  • any issues with code.. try just having a basic demo from the math folder running and see if same issue occurs?

  • another option is to not use chrome, but rather an electron app (still chromium) that loads localhost:5000 (or 5001) in a kiosk way.. no idea which repo i used back in 2019, but it still works great... a quick search, revealed this fancier https://github.com/innovation-system/electron-kiosk one that also has refresh settings

  • also try running at a lower resolution, using pixelDensity(1) in your setup, so it's not retina graphics and double the size canvas?

  • not sure if you're using a RECODING to change stuff automatically? or just a sketch that could be exported as an HTML with local libs etc..? in the latest version, i also introduced an exhibit mode https://github.com/ffd8/p5live?tab=readme-ov-file#view-only-mode that hides everything except the visuals if that's useful eek.. not working, gotta check? In the meantime, you can add the follow flags to the URL if you don't want the menu/code: ?menu=0&editor=0.

Hope one of those helps... and not the GPU side... + test on another machine.. same OS... maybe it's the macmini? + what happens if you just plug a mouse/keyboard into it without using it?

— Reply to this email directly, view it on GitHub https://github.com/ffd8/P5LIVE/issues/96#issuecomment-2376826370, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABR6VCZXEMI4GUB36XZUK3ZYP5IZAVCNFSM6AAAAABO3CU34KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNZWHAZDMMZXGA . You are receiving this because you authored the thread.Message ID: @.***>

ffd8 commented 1 month ago

Somehow haven't had any issues with this at all – also in an installation that ran for a week (auto turned on/off each day) – across 3x 2020 iMacs running Ventura and Sonoma... really curious what might be causing it.. as it only happens on your MacMini and not on your laptop – curious what else is happening on that machine? Or also on laptop?

If going electron route, definitely add flags to prevent caching as you develop it.

And with setup() crashing if ran multiple times.. I wonder what is taking place in there that could be causing an issue when re-generating. I just tested calling it every few seconds from the draw() and no issue.. also double checked iFrame wasn't producing multiple canvases – but was replacing them. Whenever triggering a 'hardCompile' – it replaces the entire iframe contents, so nothing lingers. One can also just toss specific contents wanted from the setup() into a customInit() function that is called inside the setup and again on demand... that way createCanvas() and any other 1x only functions don't get called?

Last but not least, you can also call a hardCompile from your code (perhaps with a setInterval for every x minutes/hours): parent.recompile(true)

Would be great to know if there's any other memory cleanup issues being missed.. but hope it works out and if you can isolate the issue and share some code that causes it, would be happy to look into it. Until then, I'm guessing we can close this?

kaosbeat commented 1 month ago

Ok, I'm learning a lot here, I was not able to isolate the issue The installation seems to be running fine for a couple of days already. Not touching it now :-) No access to a mac also for now. But I'll remember tot test this earlier on the next time... maybe the 4K resolution is not a good Idea after all

ffd8 commented 1 month ago

Glad to hear and hope it works out well – feel free to share later a docu of the setup, very curious what it's doing.

ffd8 commented 1 month ago

Randomly was searching Chrome preferences to disable something when I stumbled across this setting I made at some point in the past, noo idea when:

image

I'm curious if you had also added your localhost for P5LIVE to such a list?

kaosbeat commented 1 month ago

Yes I did. Meanwhile the installation is still running fine. I think it maybe has to do with the amount of data I'm preloading? Although it's in the order of kilobytes, it is creating particles out of it, and maybe copies them to memory... Already on the next project and that seems to be running fine on raspberry pi4. Only difference is the data loaded

On Thu, Oct 17, 2024, 01:01 ffd8 @.***> wrote:

Randomly was searching Chrome preferences to disable something when I stumbled across this setting I made at some point in the past, noo idea when: image.png (view on web) https://github.com/user-attachments/assets/e09215de-e937-4a78-8bb6-7d252612b24c

I'm curious if you had also added your localhost for P5LIVE to such a list?

— Reply to this email directly, view it on GitHub https://github.com/ffd8/P5LIVE/issues/96#issuecomment-2418109407, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABR6VGALQ44JKTGIQ4UMNLZ33V3BAVCNFSM6AAAAABO3CU34KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMJYGEYDSNBQG4 . You are receiving this because you modified the open/close state.Message ID: @.***>