Fix crashing when trying to change FPS mode in classic options menu, fixes #402 (Thanks mwspiker)

This commit is contained in:
UnknownShadow200 2017-03-27 12:38:20 +11:00
parent e542015a69
commit 54ec28136f
3 changed files with 16 additions and 13 deletions

View File

@ -50,9 +50,7 @@ namespace ClassicalSharp.Gui.Screens {
MakeOpt(1, 0, "FPS mode", OnWidgetClick,
g => g.FpsLimit.ToString(),
(g, v) => { object raw = Enum.Parse(typeof(FpsLimitMethod), v);
g.SetFpsLimitMethod((FpsLimitMethod)raw);
Options.Set(OptionsKey.FpsLimit, v); }),
(g, v) => { }),
!game.ClassicHacks ? null :
MakeBool(0, 60, "Hacks enabled", OptionsKey.HacksEnabled,
@ -67,6 +65,11 @@ namespace ClassicalSharp.Gui.Screens {
MakeBack(400, "Done", 25, titleFont, (g, w) => g.Gui.SetNewScreen(new PauseScreen(g))),
null, null,
};
// NOTE: we need to override the default setter here, because changing FPS limit method
// recreates the graphics context on some backends (such as Direct3D9)
ButtonWidget btn = (ButtonWidget)widgets[7];
btn.SetValue = SetFPSLimitMethod;
}
void MakeValidators() {

View File

@ -57,16 +57,6 @@ namespace ClassicalSharp.Gui.Screens {
btn.SetValue = SetFPSLimitMethod;
}
void SetFPSLimitMethod(Game g, string v) {
object rawFps = Enum.Parse(typeof(FpsLimitMethod), v);
g.SetFpsLimitMethod((FpsLimitMethod)rawFps);
Options.Set(OptionsKey.FpsLimit, v);
// NOTE: OpenGL backend doesn't recreate context, so cheat and act like recreated anyways
ContextLost();
ContextRecreated();
}
void SetSmoothLighting(Game g, bool v) {
g.SmoothLighting = v;
ChunkMeshBuilder builder = g.MapRenderer.DefaultMeshBuilder();

View File

@ -254,5 +254,15 @@ namespace ClassicalSharp.Gui.Screens {
widgets[okayIndex].Dispose();
widgets[okayIndex] = null;
}
protected void SetFPSLimitMethod(Game g, string v) {
object rawFps = Enum.Parse(typeof(FpsLimitMethod), v);
g.SetFpsLimitMethod((FpsLimitMethod)rawFps);
Options.Set(OptionsKey.FpsLimit, v);
// NOTE: OpenGL backend doesn't recreate context, so cheat and act like recreated anyways
ContextLost();
ContextRecreated();
}
}
}