Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DMenuOptionCVar tripping over itself #2084

Closed
wants to merge 2 commits into from

Conversation

Tenrys
Copy link
Contributor

@Tenrys Tenrys commented May 4, 2024

RunConsoleCommand does set the CVar a frame later, but the panel's Think runs right after OnChecked, and by that point the CVar hasn't been updated yet, so it sets itself back to its previous value.

This works but I feel like it's a bit too dirty?

Also remove deprecated use of GetConVarString

RunConsoleCommand does set the CVar a frame later,
but the panel's Think runs right after OnChecked,
and by that point the CVar hasn't been updated yet,
so it sets itself back to its previous value.

This works but I feel like it's a bit too dirty?

Also remove deprecated use of GetConVarString
Copy link
Collaborator

@robotboy655 robotboy655 left a comment

Choose a reason for hiding this comment

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

Are you able to present a case where this issue actually happens?

I have tried adding some print()s when the convar value is being set and read, and I am not noticing any issues with the spawnmenu menubar setting the cvar, either by clicking the option to set cvar, or by setting the cvar from the console.

image


end

local justChecked = false
Copy link
Collaborator

Choose a reason for hiding this comment

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

You really can't be using local out-of-scope variables for objects that can have multiple instances present at the same time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, just to be sure, would PANEL.JustChecked work out better then? I do feel like the solution I presented is a bit dirty, but I can't think of anything better on the spot.

@Tenrys
Copy link
Contributor Author

Tenrys commented May 21, 2024

With the following code:

local frame = vgui.Create("DFrame")
frame:SetSize(300, 300)
frame:SetPos(ScrW() - 350, 50)

local panel = vgui.Create("DPanel", frame)
panel:Dock(FILL)
panel:DockPadding(10, 10, 10, 10)
panel.OpenSubMenu = function() end

local option = vgui.Create("DMenuOptionCVar", panel)
option:SetConVar("cl_showfps")
option:SetText("Show FPS")

I doubt the way I'm using this control has anything to do with how it functions, but here's how it works for me on x86-64, and there is also a comparison with my fix.

gmod_swAP9c7yyV_fix.mp4

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