godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
88.34k stars 20.01k forks source link

Frame stutter when playing a project on MacOS/Linux #16766

Open jvanmourik opened 6 years ago

jvanmourik commented 6 years ago

Godot version: 3.0

OS/device including version: MacOS High Sierra, NVIDIA GeForce GT 750M 2 GB

Issue description: Frame stuttering: https://imgur.com/a/nzIIn The FPS seem to remain unaffected when a stutter occurs. I've tried disabling V-sync. All demo projects I've tried have this issue. When using the Profiler I've noticed that the game mostly doesn't stutter anymore. I've managed to capture a profile both with stutter (right side) and without stutter (left side): https://imgur.com/a/ctFMp. An exported version of the game has no frame stuttering. But I will get stuttering even in the exported game when I'm playing both the exported version and the preview game from within Godot.

Steps to reproduce: Be on MacOS (or Linux https://www.reddit.com/r/godot/comments/7y2aba/frame_stutter/dud66un/). Set MacOS' scaling to "More Space". Play any project from within Godot.

Minimal reproduction project: Any (demo) project with character movement to test it

vnen commented 6 years ago

Maybe it's because the remote scene tree? See #13219

jvanmourik commented 6 years ago

I have 'Editor Settings/Debugger/Auto Switch To Remote Scene Tree' disabled. So that can't be it right?

vnen commented 6 years ago

It's easier to look at the editor when playing the scene and see if the remote tree is selected or not.

jvanmourik commented 6 years ago

It will start with a Local tree, I have the option to click on Remote. When I select Remote Tree it will cause even more frame stutter/lag.

Edit: I've tested the same project on Windows using bootcamp on the same device. On Windows it will run butter smooth. So it shouldn't be hardware related.

jvanmourik commented 6 years ago

Might have something to do with #5688 (I also suffer from this issue). When I plug in an low-ress external monitor, the stuttering completely disappears on both my high-dpi retina screen and my external monitor.

I hope this helps in any way.

Edit: After some more testing without the external monitor, I found out that the stuttering only happens on the last scaled resolution option: https://imgur.com/a/QS7sF. Issue #5688 occurs on any scaling though.

SonnyBonds commented 5 years ago

I've had stutters on Mac disappear when I kill the core audio service. (Checking Monitor it was a process taking some CPU so I just tried killing it.) That's obviously not the solution, but maybe the stutters could be caused by the audio renderer doing something silly?

KoBeWi commented 4 years ago

Can anyone still reproduce this bug in Godot 3.2.3 rc1 or any later release?

If yes, please ensure that an up-to-date Minimal Reproduction Project (MRP) is included in this report (a MRP is a zipped Godot project with the minimal elements necessary to reliably trigger the bug). You can upload ZIP files in an issue comment with a drag and drop.

KoBeWi commented 3 years ago

Closing due to lack of update. Please comment if you can still reproduce this issue in the latest stable version of Godot.

electricwig commented 3 years ago

Hello, I believe that I have this issue. You will have to excuse me if I get something wrong in the way I present the information, or don't include something - I am a beginner at Godot and am still learning the program. Have also never contributed to this or any other github, so again apologies in advance if I get something wrong that seems obvious to a more experienced user.

I am using Godot V.3.2.2.stable (and GLES2) on a Macbook Pro 13, 2020 - Catalina 10.15.6 I was following this YouTube Godot/RPG tutorial: https://youtu.be/mAbG8Oi-SvQ And in trying to replicate it, I have noticed that my Player character 'stutters' ever second or so when moving. I've read the definitions and believe that Stutter is the most accurate.

Here is a video of my screen and what I believe to be the stutter issue: https://youtu.be/xRppHw8LrZg I've also attached what I hope to be a working zipped MRP as instructed above, but again if I have forgotten to include something or done it in the wrong format or whatever, please excuse my lack of knowledge! Happy to share any other info relevant to getting this issue solved!

StutterExample.zip

Calinou commented 3 years ago

@electricwig Does the stutter go away if you install, enable and configure the smoothing-addon?

electricwig commented 3 years ago

I'm embarrassed to say that right now I can't figure out how to actually copy the folder across from the github page you've linked to my project! There seems to be no download/save option on the folder that I can find. Quite possible it's right under my nose and I'm just being really stupid though?!

Calinou commented 3 years ago

@electricwig Use this link: https://github.com/lawnjelly/smoothing-addon/archive/master.zip

Extract the ZIP, move the addons folder to your project folder, open the Project Settings, go to Plugins and enable the smoothing-addon there. Then configure it according to the README in that repository.

electricwig commented 3 years ago

Thank you for giving me much more in depth instructions - really appreciate it. I've managed to install the smoothing addon and enable it as instructed in the Readme ... but, I'm afraid to report that on reopening the project and adding this plugin, if anything the stutter seems even more pronounced/apparent than in my first video example, and turning the smoothing on/off doesn't seem to affect things at all?

Here's a video of how it's looking now, first without smoothing plugin turned on, then again WITH: https://youtu.be/OucqcJknG0E

Calinou commented 3 years ago

@electricwig Did you add a Smoothing2D node besides your RigidBodies/KinematicBodies and set a target node on each one of them? This is required for physics interpolation to work.

electricwig commented 3 years ago

Sorry, I'm a little lost by what you just said ... As I explained in the first post that re-opened this thread, I'm a beginner at Godot and am still trying to get my head around it. i've only been following along to a few beginner YouTube tutorials, trying to understand how everything works, and this stutter issue is something I'm running up against right off the bat.

With regards to adding the smoothing plugin, all I've done is follow these steps in the Readme (which I assumed was all I needed to do?):

  1. Copy the 'addons' folder from this repository to your Godot project folder.
  2. Go to 'Project Settings' plugins tab.
  3. Find the smoothing plugin and set status to 'Active'.

I haven't "added a Smoothing2D node besides my RigidBodies/KinematicBodies and set a target node on each one of them" and to be honest I'm not 100% sure how I'd even do this! Just being honest about my total beginner status.

I'm aware of the basic Node structure of Godot, but are you suggesting that in order for me to get my super simple beginner 2d pixel art game off the ground and not stutter, I'm going to have to be adding in extra "Smoothing Nodes" and "setting targets" to ... what exactly? All Rigid/Kinematic bodies in each/every scene I create?

Calinou commented 3 years ago

@electricwig I configured your project with the smoothing-addon, give it a try: StutterExample.zip

electricwig commented 3 years ago

@Calinou Thanks for trying to help me with this, realise it must be kind of frustrating for you if I'm not really that well versed in the engine and I appreciate your help! All that said, I've just tried out the configured project you posted and ... it's still stuttering I'm afraid! Not as bad as in the second clip I posted, but kind of the same as the very first post I made. Here's a video of what it looks like currently: https://youtu.be/FExr6h4XCIg

It's not a huge deal, but yeah, there's a noticeable skip/stutter after the character moves for a little while ... I'm starting to think that in following along to the tutorial, I've somehow either made an error in the player code? Or that some other setting just isn't compatible with Mac? But have no clue what that is, being a total beginner!

KoBeWi commented 3 years ago

I'm starting to think that in following along to the tutorial, I've somehow either made an error in the player code?

I tried the project and couldn't reproduce the problem, so this is some hardware-specific issue.

Calinou commented 3 years ago

To solve this, I think we'll have to stop the editor from redrawing entirely when the project is running and the editor window isn't focused. (OS::can_draw() can be overridden in the 3.2 branch for this.)

akien-mga commented 3 years ago

To solve this, I think we'll have to stop the editor from redrawing entirely when the project is running and the editor window isn't focused. (OS::can_draw() can be overridden in the 3.2 branch for this.)

It should still redraw if you use the Remote scene tree.

sagarjauhari commented 3 years ago

I was pretty impressed with Godot until I started having this problem a few months ago - tried different solutions but eventually gave up. Have a similar setup and was trying to do something exactly as @electricwig

I am using Godot V.3.2.2.stable (and GLES2) on a Macbook Pro 13, 2020 - Catalina 10.15.6 I was following this YouTube Godot/RPG tutorial: https://youtu.be/mAbG8Oi-SvQ

The frame stutter was just a deal breaker

Calinou commented 3 years ago

@sagarjauhari The stuttering will most likely be gone in the exported project (since the editor won't be rendering at the same time as the project). This means it won't affect potential players.

sagarjauhari commented 3 years ago

Sure, but even from a development POV, it was really difficult to time events or figure out the parameters I should set for different Kinematic2D bodies - the stutter was very jarring

starry-abyss commented 3 years ago

Feedback from Reddit linked in original message is interesting... Maybe Godot could try to render not at max possible CPU usage, but slightly less (possibly waiting for a few frames to be sure it's time to try to increase FPS), so FPS is smoothened?

Also it might have something to do with compositing similar to #19783.

And another idea is Godot thinks (and reports in profiler) current FPS always equals monitor's rate when V-sync is enabled, while actually it cannot serve this FPS due to other processes taking some resources. I remember I experienced this on Windows.

Calinou commented 3 years ago

Maybe Godot could try to render not at max possible CPU usage, but slightly less (possibly waiting for a few frames to be sure it's time to try to increase FPS), so FPS is smoothened?

This can already be done in the Project Settings by setting a frame delay (or using the --frame-delay command line argument), but it will introduce stuttering since the engine will always sleep by a fixed amount of milliseconds between each frame.

You can also set a FPS limit using Debug > Force Fps in the Project Settings, which will sleep a variable amount of time if the FPS limit is exceeded (or not at all if it's not exceeded). That said, setting a default FPS limit is not very useful when V-Sync is already doing its job.

Also it might have something to do with compositing similar to #19783

Compositing is always enabled on macOS; you can't turn it off like on some Linux window managers. On Windows 10, it can be disabled by using exclusive fullscreen or sometimes a borderless fullscreen window.

Cheeseness commented 3 years ago

To solve this, I think we'll have to stop the editor from redrawing entirely when the project is running and the editor window isn't focused. (OS::can_draw() can be overridden in the 3.2 branch for this.)

Probably doesn't need saying, but just in case, there are a bunch of things that are specifically useful to see updating when the editor doesn't have focus - the output tab, debugger tab's errors, monitors, and profiler tabs, the audio tab, etc.. My workflows would be negatively impacted if that functionality went away.

sergeypdev commented 2 years ago

You can also set a FPS limit using Debug > Force Fps in the Project Settings, which will sleep a variable amount of time if the FPS limit is exceeded (or not at all if it's not exceeded). That said, setting a default FPS limit is not very useful when V-Sync is already doing its job.

This helped me a lot on Mac OS 12.0.1 and Godot 3.4

Cyangmou commented 10 months ago

These problems are not exclusive to Mac and Linux, but tied to V-Sync.

So basically we also can say the problem persists on Windows, probably the person had a 60hz screen, as my series of tests showed that with a 60hz screen the stutter is there, although barely noticeable. Anyways this also plays in the same problem.

You can find my test results here: Issue #6389

jvanmourik commented 10 months ago

These problems are not exclusive to Mac and Linux, but tied to V-Sync.

The original issue did persist with V-Sync disabled. It did not occur on the same device with Windows installed however.

I can’t confirm if the stutters are still present, since I do not have access to the same hardware any longer. There are no stutters at all on my M1 Macbook Air if that is of any help.