Fix weather flicker 4803#4870
Merged
Merged
Conversation
… WER and logging, avoid TerminateThread
…into crash-handler-polish
…rBlended/setTime Re-apply MTA's blended weather state in PreWorldProcessHandler, which runs after the engine's CWeather::Update() (0x53BFC2) but before CTimeCycle::CalcColoursForPoint() (via sub_561760 at 0x53C0DA) reads the weather globals for rendering. Root cause: When setTime() jumps the clock past InterpolationValue, the engine's CWeather::Update() detects a time wrap and overwrites OldWeatherType (0xC81320) / NewWeatherType (0xC8131C) with its own weather-list selection. MTA's CBlendedWeather::DoPulse() previously only ran in DoPulses() during Render2dStuff -- AFTER CalcColoursForPoint had already consumed the wrong values for that frame's sky/ambient/fog colors. The existing DoPulse() call in DoPulses() is kept as the function is idempotent and serves as a safety net for late-frame consistency. Fullscreen-only because exclusive mode uses hardware page-flipping without DWM composition, exposing every frame including the 2 glitch frames that windowed mode's triple buffering absorbs.
Lpsd
approved these changes
May 1, 2026
This was referenced May 4, 2026
Zephkek
added a commit
to Zephkek/mtasa-blue
that referenced
this pull request
May 4, 2026
…te hook Follow-up to multitheftauto#4870. PR4870 hooks at CWorld::Process (0x53C095) to re-apply MTA's blended weather before CTimeCycle::CalcColoursForPoint reads the weather globals at 0x53C0DA — that fixes sky/ambient. But CWeather::Update itself runs earlier (0x53BFC2), and on the clock-wrap branch it derives Rain, Foggyness, CloudCoverage, ExtraSunnyness, SunGlare, HeatHaze, Sandstorm, WetRoads, Wind and Rainbow from a freshly-picked weather pair. Those globals drive cloud, fog and night-time building light rendering, so building lights still flickered after multitheftauto#4870. Add a HookInstallCall over the call site at 0x53BFC2 and route a new PreWeatherUpdateHandler through CMultiplayerSA -> CClientGame, calling CBlendedWeather::DoPulse before CWeather::Update. DoPulse re-applies Old/New via Set and re-syncs InterpolationValue with the game clock, so CWeather::Update takes the non-wrap branch and derives every weather global from MTA's intended pair. The PreWorldProcessHandler hook from multitheftauto#4870 is kept as a defensive idempotent re-apply. CBlendedWeather::DoPulse now also calls CWeather::ResyncInterpolationWithGameClock after Set so the InterpolationValue used by CalcColoursForPoint matches the clock — fixes residual flicker on glass/reflective materials that the sky-only fix in multitheftauto#4870 left behind.
FileEX
pushed a commit
that referenced
this pull request
May 5, 2026
#### Summary Follow-up to #4870. Move the weather re-apply earlier in `CGame::Process` so the engine's clock-wrap branch in `CWeather::Update` also runs against MTA's intended weather pair. #### Motivation #4870 fixed the sky/ambient flicker by re-applying MTA's weather in `PreWorldProcessHandler` (`0x53C095`), ahead of `CTimeCycle::CalcColoursForPoint` (`0x53C0DA`). Cloud cover, fog and night-time building lights still pop for the same frames, because `CWeather::Update` itself runs earlier (`0x53BFC2`) and on the wrap branch derives `Rain`, `Foggyness`, `CloudCoverage`, `ExtraSunnyness`, `SunGlare`, `HeatHaze`, `Sandstorm`, `WetRoads`, `Wind` and `Rainbow` from its own freshly-picked pair before `PreWorldProcessHandler` gets a chance to fix things. This PR adds a `HookInstallCall` over the `call CWeather::Update` site at `0x53BFC2` and a new `PreWeatherUpdateHandler` that runs `CBlendedWeather::DoPulse` before the engine update. With Old/New/`InterpolationValue` already aligned, `CWeather::Update` takes the non-wrap branch and derives every weather global from MTA's pair. The existing `PreWorldProcessHandler` re-apply from #4870 is kept as an idempotent safety net for the colour-set path. `CBlendedWeather::DoPulse` also calls `CWeather::ResyncInterpolationWithGameClock` after `Set`, so `InterpolationValue` matches the clock also fixes residual flicker on glass/reflective materials that #4870 left behind. #### Test plan 1. Join a server running the default race resource 2. Set fullscreen (any mode) 3. Use `setWeatherBlended` + `setTime` via script, then restart the race resource to respawn 4. Observe no sky/lighting flicker on respawn 5. Repeat at night so building/streetlight glow and cloud cover are visible they should not pop either #### Checklist * [x] Your code should follow the [coding guidelines](https://wiki.multitheftauto.com/index.php?title=Coding_guidelines). * [x] Smaller pull requests are easier to review. If your pull request is beefy, your pull request should be reviewable commit-by-commit.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Re-apply MTA's blended weather state in
PreWorldProcessHandlerso it runs after the engine'sCWeather::Updatebut beforeCTimeCycle::CalcColoursForPointreads the weather globals for rendering.Motivation
Fixes #4803. When
setWeatherBlended/setTimeare used (e.g. race resource restart/respawn), the sky and ambient lighting flicker for 1-2 frames in fullscreen.The engine's
CWeather::Update(at0x53BFC2inCGame::Process) detects a clock wrap whensetTimejumps the game clock past its internalInterpolationValue. It then overwritesOldWeatherType/NewWeatherTypewith its own weather-list pick.CalcColoursForPoint(at0x53C0DA) reads these wrong values and computes incorrect sky/ambient colors for that frame. MTA'sCBlendedWeather::DoPulsepreviously only ran inDoPulsesduringRender2dStuff, which is after the frame was already rendered with the wrong state.Fullscreen-only because exclusive mode bypasses DWM composition, so every frame including the glitch frames is presented directly. Windowed mode's DWM triple buffering absorbs them.
Test plan
setWeatherBlended+setTimevia script, then restart the race resource to respawnChecklist