> [JDK-8185862](https://bugs.openjdk.org/browse/JDK-8185862) introduced several 
> behavioral changes:
> 
> 1. `CountMonitors()` started counting only those `HMONITOR` from 
> `EnumDisplayMonitors` for which `CreateDC` was successful.
> 2. A new state `0 valid monitors` appeared, which did not exist before.
> 3. In `Devices::GetDevice`, the lower bound check was insufficient (`index < 
> 0` instead of `index <= 0`,  this was not introduced by 
> [JDK-8185862](https://bugs.openjdk.org/browse/JDK-8185862) though). 
> Thus, we could attempt to read the first element of a zero-length array, 
> which caused a crash in `sun.awt.Win32GraphicsDevice.initNativeScale`.
> 3. Invalidation only occurres for devices whose indices were removed from the 
> end of the array.
> In RDP scenarios, a device may be replaced at the same index without changing 
> the total number of screens, which bypassed invalidation.
> 
> ---
> 
> Changes in this fix:
> 
> 1. Combined `CountMonitors()` and `CollectMonitors()`. Monitors are now 
> collected into a dynamic array in a single pass.
> 2. The working list of devices is no longer replaced by an empty one.
> 3. `displayChanged()` is called only after a successful native update.
> 5. Added RDP transient states handling (retries by timer and by session 
> connect).
> 6. `GetDevice()` now returns `NULL` if `numDevices <= 0`.
> 7. Improved device comparison logic: comparisons are now performed using 
> display data (`dwFlags`, `szDevice`).
> Changed devices are invalidated, unchanged ones receive transferred Java 
> references to the new native device.
> 
> ---
> 
> Testing:
> 
> The fix seems to be stable over various scenarios of changing display 
> configurations, locally and over RDP.
> CI testing is also green.
> 
> 
> 
> ---------
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

Alexander Zvegintsev has updated the pull request incrementally with one 
additional commit since the last revision:

  explanatory comment

-------------

Changes:
  - all: https://git.openjdk.org/jdk/pull/31238/files
  - new: https://git.openjdk.org/jdk/pull/31238/files/edc2af64..a9c1053e

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=31238&range=01
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=31238&range=00-01

  Stats: 13 lines in 1 file changed: 10 ins; 0 del; 3 mod
  Patch: https://git.openjdk.org/jdk/pull/31238.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/31238/head:pull/31238

PR: https://git.openjdk.org/jdk/pull/31238

Reply via email to