Skip to content

Fix ListView no longer displays images#4184

Merged
RussKie merged 2 commits intodotnet:masterfrom
RussKie:fix_4169
Nov 12, 2020
Merged

Fix ListView no longer displays images#4184
RussKie merged 2 commits intodotnet:masterfrom
RussKie:fix_4169

Conversation

@RussKie
Copy link
Contributor

@RussKie RussKie commented Nov 2, 2020

Fixes #4169

Proposed changes

Changes in ImageList ownership model in #3601 means that very are now two instances of imagelists - one instance is tracked by Windows Forms (i.e. managed) side, and another one tracked by the underlying Win32 (unmanaged) side. This was done due to an observed ownership disconnect between the managed and unmanaged code, that led to situations where the unmanaged code would effectively destroy and instance of an imagelist, which the managed code was oblivious to.

However with the above change changes to images in an imagelist on the managed side, i.e. a user adding or replacing an image in the imagelist, would not be reflected in the imagelist on the unmanaged side, and thus would not be reflected in the UI (which is drawn by the Win32).

The fix reuses the established infrastructure that notifies the managed imagelist implementation of changes to the images collection, and once a notification of a chance is received, the unmanaged imagelist is re-created, thus ensuring the UI has all the correct images to display.

Customer Impact

  • A control that references an ImageList that gets its images dynamically modified will render the images correctly.

Regression?

  • Yes

Risk

  • Minor

@ghost ghost assigned RussKie Nov 2, 2020
@RussKie RussKie requested a review from JeremyKuhne November 2, 2020 08:22
@RussKie RussKie changed the title Fix 4169 Fix ListView no longer displays images Nov 2, 2020
Copy link
Contributor

@weltkante weltkante left a comment

Choose a reason for hiding this comment

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

I don't think this fix is safe, ownership is transferred to the native control, the native image list can be deleted at arbitrary points in time.

@ghost ghost added the waiting-author-feedback The team requires more information from the author label Nov 2, 2020
@ghost ghost removed the waiting-author-feedback The team requires more information from the author label Nov 3, 2020
Copy link
Contributor

@weltkante weltkante left a comment

Choose a reason for hiding this comment

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

@RussKie Is this a clean rollback of the original workaround-PR now, or is there something to review? I'll look which issues need to be reopened (or followed up) for a rollback and link them.

I was apparently misremembering some designer issue being resolved by this PR, or I can't find it. The other issue was #3531 and is still open. It will need to be adressed, or you have to remove that usage pattern from all your tests, otherwise tests go back to flaky upon reverting. (I think they'll still be flaky anyways from other mishandled ownership scenarios, but it might be worth trying to see if avoiding that particular usage pattern can significantly reduce the amount of flakyness.)

Also test failures here may be related to assertions introduced in separate PRs, you'll have to remove assertions that verify no double-free happens on the ImageList.

@RussKie
Copy link
Contributor Author

RussKie commented Nov 4, 2020

Yes, there have been a few things done that reduced the amount of issues we have with the ImageList. I'm still testing and exploring what needs to be done.

@RussKie
Copy link
Contributor Author

RussKie commented Nov 4, 2020

@weltkante I think I may have finally found a reasonable fix, thanks to your suggestions. We have a plumbing to alert the ImageList about changes in the collection, and we can use the same mechanism to force it re-create native handles.

@codecov
Copy link

codecov bot commented Nov 4, 2020

Codecov Report

Merging #4184 (a42415b) into master (dac8607) will decrease coverage by 0.00772%.
The diff coverage is n/a.

@@                 Coverage Diff                 @@
##              master       #4184         +/-   ##
===================================================
- Coverage   97.97005%   97.96233%   -0.00773%     
===================================================
  Files            497         497                 
  Lines         258972      258972                 
  Branches        4566        4566                 
===================================================
- Hits          253715      253695         -20     
- Misses          4457        4473         +16     
- Partials         800         804          +4     
Flag Coverage Δ
Debug 97.96233% <ø> (-0.00773%) ⬇️
production 100.00000% <ø> (ø)
test 97.96233% <ø> (-0.00773%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

@RussKie

This comment has been minimized.

@weltkante
Copy link
Contributor

weltkante commented Nov 4, 2020

Those failures are probably just #3898 again. could't reproduce those yet so not sure what they are.

@RussKie
Copy link
Contributor Author

RussKie commented Nov 4, 2020

Yes, they feel very random. Subsequent builds succeeded.

@dotnet dotnet deleted a comment from azure-pipelines bot Nov 5, 2020
@dotnet dotnet deleted a comment from azure-pipelines bot Nov 5, 2020
@RussKie RussKie added the priority-1 Work that is critical for the release, but we could probably ship without label Nov 10, 2020
Changes in `ImageList` ownership model in dotnet#3601 means that very are now two
instances of imagelists - one instance is tracked by Windows Forms (i.e. managed)
side, and another one tracked by the underlying Win32 (unmanaged) side.
This was done due to an observed ownership disconnect between the managed and unmanged
code, that led to situations where the unmanaged code would effectively destroy
and instance of an imagelist, which the managed code was oblivious to.

However with the above change changes to images in an imagelist on the managed
side, i.e. a user adding or replacing an image in the imagelist, would not be reflected
in the imagelist on the unmanaged side, and thus would not be reflected in the UI
(which is drawn by the Win32).

The fix reuses the established infrastructure that notifies the managed imagelist
implementation of changes to the images collection, and once a notification of
a chance is received, the unmanaged imagelist is re-created, thus ensuring the UI
has all the correct images to display.

Fixes dotnet#4169
@RussKie RussKie removed the priority-1 Work that is critical for the release, but we could probably ship without label Nov 12, 2020
@RussKie RussKie marked this pull request as ready for review November 12, 2020 04:00
@RussKie RussKie requested a review from a team as a code owner November 12, 2020 04:00
@dotnet dotnet deleted a comment Nov 12, 2020
@dotnet dotnet deleted a comment from azure-pipelines bot Nov 12, 2020
@dotnet dotnet deleted a comment from azure-pipelines bot Nov 12, 2020
@RussKie RussKie merged commit d0608e7 into dotnet:master Nov 12, 2020
@RussKie RussKie deleted the fix_4169 branch November 12, 2020 04:24
@ghost ghost added this to the 6.0 Preview1 milestone Nov 12, 2020
@RussKie RussKie linked an issue Nov 25, 2020 that may be closed by this pull request
RussKie added a commit to RussKie/winforms that referenced this pull request Nov 27, 2020
Revert "Explicit ImageList ownership management. (dotnet#3601)"
This reverts commit 03db3fb.

Revert "Fix `ListView` no longer displays images (dotnet#4184)"
This reverts commit d0608e7.

We have observed an instability of tests under stress (and reasonably
high degree of concurrency) presumably caused by ImageList lifetime
handling (notably dotnet#3358).
The changes introduced in dotnet#3601 have helped with tests stability,
however resulted in a number of regressions, such as dotnet#4169 and dotnet#4275.

Restore the original implementation given it worked reasonably well for
the past so many years.
RussKie added a commit that referenced this pull request Dec 2, 2020
Revert "Explicit ImageList ownership management. (#3601)"
This reverts commit 03db3fb.

Revert "Fix `ListView` no longer displays images (#4184)"
This reverts commit d0608e7.

We have observed an instability of tests under stress (and reasonably
high degree of concurrency) presumably caused by ImageList lifetime
handling (notably #3358).
The changes introduced in #3601 have helped with tests stability,
however resulted in a number of regressions, such as #4169 and #4275.

Restore the original implementation given it worked reasonably well for
the past so many years.
RussKie added a commit to RussKie/winforms that referenced this pull request Dec 2, 2020
Revert "Explicit ImageList ownership management. (dotnet#3601)"
This reverts commit 03db3fb.

Revert "Fix `ListView` no longer displays images (dotnet#4184)"
This reverts commit d0608e7.

We have observed an instability of tests under stress (and reasonably
high degree of concurrency) presumably caused by ImageList lifetime
handling (notably dotnet#3358).
The changes introduced in dotnet#3601 have helped with tests stability,
however resulted in a number of regressions, such as dotnet#4169 and dotnet#4275.

Restore the original implementation given it worked reasonably well for
the past so many years.

(cherry picked from commit b0ee5da)
RussKie added a commit that referenced this pull request Dec 9, 2020
Revert "Explicit ImageList ownership management. (#3601)"
This reverts commit 03db3fb.

Revert "Fix `ListView` no longer displays images (#4184)"
This reverts commit d0608e7.

We have observed an instability of tests under stress (and reasonably
high degree of concurrency) presumably caused by ImageList lifetime
handling (notably #3358).
The changes introduced in #3601 have helped with tests stability,
however resulted in a number of regressions, such as #4169 and #4275.

Restore the original implementation given it worked reasonably well for
the past so many years.

(cherry picked from commit b0ee5da)
@ghost ghost locked as resolved and limited conversation to collaborators Jan 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ListView redraws when images are added to its ImageList net5.0 System.Windows.Forms.ListView no longer displays LargeIcon

3 participants