FunkinCrew / Funkin

A rhythm game made with HaxeFlixel
https://www.newgrounds.com/portal/view/770371
Other
2.97k stars 2.29k forks source link

Bug Report: Experiencing huge lag spikes when playing week 5 erect songs #3161

Closed JackXson-Real closed 1 month ago

JackXson-Real commented 1 month ago

Issue Checklist

What platform are you using?

Itch.io (Downloadable Build) - Windows

If you are playing on a browser, which one are you using?

None

Version

0.5.0

Context (Provide images, videos, etc.)

Read title. It also seems to continue after exiting the song and going to a different one. I have a really good PC, and this wasn't happening in 0.4.1. I seem to get the most lag issues with Cocoa Erect. The lag spikes are so bad that they cause me to lose my combo every time. They last for 1 or 2 seconds usually.

Steps to reproduce (or crash logs, errors, etc.)

Play week 5 erect songs.

ItIsIWeeg commented 1 month ago

Can confirm, this mainly happens during Cocoa Erect on my end. Definently caused by the stage script, which is calling a new instance of the shader every frame, as opposed to when the stage is finished loading.

JackXson-Real commented 1 month ago

Can confirm, this mainly happens during Cocoa Erect on my end.

Definently caused by the stage script, which is calling a new instance of the shader every frame, as opposed to when the stage is finished loading.

Lmao

JackXson-Real commented 1 month ago

Update: This seems to only happen on desktop version, NG browser version ran perfectly smooth.

kawuchuu commented 1 month ago

Try replacing assets/scripts/stages/mallXmasErect.hxc with the following:

import flixel.FlxG;
import flixel.FlxSprite;
import flixel.addons.display.FlxRuntimeShader;
import flixel.sound.FlxSound;
import funkin.Conductor;
import funkin.Paths;
import funkin.modding.base.ScriptedFlxRuntimeShader;
import funkin.graphics.shaders.AdjustColorShader;
import funkin.play.PlayState;
import funkin.play.stage.Stage;
import funkin.graphics.adobeanimate.FlxAtlasSprite;
import funkin.modding.base.ScriptedFlxAtlasSprite;

class MallXmasErectStage extends Stage
{
    function new()
    {
        super('mallXmasErect');
    }

    var colorShader:AdjustColorShader;

    function buildStage()
    {
        super.buildStage();

        colorShader = new AdjustColorShader();
        colorShader.hue = 5;
        colorShader.saturation = 20;
    }

    function onUpdate(event:UpdateScriptEvent):Void
    {
        super.onUpdate(event);

        if (PlayState.instance.currentStage.getBoyfriend() != null && PlayState.instance.currentStage.getBoyfriend().shader == null) {
            PlayState.instance.currentStage.getBoyfriend().shader = colorShader;
            PlayState.instance.currentStage.getGirlfriend().shader = colorShader;
            PlayState.instance.currentStage.getDad().shader = colorShader;
            getNamedProp('santa').shader = colorShader;
        }
    }
}

Instead of creating a new shader instance every frame, this should only create it once. It seems to have improved the performance on my end. This is actually similar to how other stages create the same shader, so I'm a bit confused why they wrote it the way they did.

AbnormalPoof commented 1 month ago

does it really make a new AdjustColorShader every frame? damn

JackXson-Real commented 1 month ago

Try replacing assets/scripts/stages/mallXmasErect.hxc with the following:

import flixel.FlxG;
import flixel.FlxSprite;
import flixel.addons.display.FlxRuntimeShader;
import flixel.sound.FlxSound;
import funkin.Conductor;
import funkin.Paths;
import funkin.modding.base.ScriptedFlxRuntimeShader;
import funkin.graphics.shaders.AdjustColorShader;
import funkin.play.PlayState;
import funkin.play.stage.Stage;
import funkin.graphics.adobeanimate.FlxAtlasSprite;
import funkin.modding.base.ScriptedFlxAtlasSprite;

class MallXmasErectStage extends Stage
{
    function new()
    {
        super('mallXmasErect');
    }

    var colorShader:AdjustColorShader;

    function buildStage()
    {
        super.buildStage();

        colorShader = new AdjustColorShader();
        colorShader.hue = 5;
        colorShader.saturation = 20;
    }

    function onUpdate(event:UpdateScriptEvent):Void
    {
        super.onUpdate(event);

        if (PlayState.instance.currentStage.getBoyfriend() != null && PlayState.instance.currentStage.getBoyfriend().shader == null) {
            PlayState.instance.currentStage.getBoyfriend().shader = colorShader;
            PlayState.instance.currentStage.getGirlfriend().shader = colorShader;
            PlayState.instance.currentStage.getDad().shader = colorShader;
            getNamedProp('santa').shader = colorShader;
        }
    }
}

Instead of creating a new shader instance every frame, this should only create it once. It seems to have improved the performance on my end. This is actually similar to how other stages create the same shader, so I'm a bit confused why they wrote it the way they did.

I tried this and it definitely improved the performance a little. I still do get lag spikes often, they just don't last as long as they did before. Im sure there is another factor that causes it to lag.

EliteMasterEric commented 1 month ago

I just discovered the root cause of this issue by myself only to return to this issue and find that @kawuchuu found it for me already. Welp.