-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Make compared have a copy of the inventory_entry rather than a pointer to fix segfault when using multiple filters. #36139
Conversation
I'm getting a segfault. Steps:
Cannot reproduce on Windows with MS VS. |
I haven't been able to replicate this problem on MS VS19. The stack trace points to the item disappearing on linux for some reason. I did try a completely different approach of making the entries_unfiltered the master list and entries pointers to the inventory_entry's in that list. Ended up changing a ton of things and completely broke inventory as well as compare. I know KorGgenT is doing heavy work in this area at the moment so am going to pause doing any more work on this PR to see how those changes shake out. |
@ishtatann you got it backwards, the stuff i'm working on is low priority compared to this being a release blocker. |
Save a copy of the first selection before set_filter is called. Restore the first selection after set_filter finishes. I'm hoping this will fix the crash people were seeing on the linux side. |
…r to fix segfault when using multiple filters.
Restore the selection after set_filter has changed all the entries.
590c3df
to
4b923fe
Compare
I can still reproduce the crash with these changes.
Built with |
Fixes CleverRaven#34046. Using the search filter causes all the inventory_entry objects to be recreated, so it's not safe to store a pointer to them. A previous attempt to solve this (CleverRaven#36139) stored copies of the inventory_entry objects, but that was also unsafe. This attempt instead stores just pointers to the underlying items. This seems to prevent the crashes. The behaviour of the window is still not always exactly correct, because using the filter will violate the invariant that the items in the compared vector correspond to the selected entries. I don't see a way to fix that in general -- sometimes the compared item is filtered out, and thus you can't possibly select the entry (because it doesn't exist). We might want to add something that does its best to select the right entries when the filter changes, but this is a sufficiently niche use case that I'm not sure it's worth the complexity. I've settled for just fixing the crash for now.
I've posted an alternate attempted fix at #36606. Testing by others welcome. |
Fixes CleverRaven#34046. Using the search filter causes all the inventory_entry objects to be recreated, so it's not safe to store a pointer to them. A previous attempt to solve this (CleverRaven#36139) stored copies of the inventory_entry objects, but that was also unsafe. This attempt instead stores just pointers to the underlying items. This seems to prevent the crashes. The behaviour of the window is still not always exactly correct, because using the filter will violate the invariant that the items in the compared vector correspond to the selected entries. I don't see a way to fix that in general -- sometimes the compared item is filtered out, and thus you can't possibly select the entry (because it doesn't exist). We might want to add something that does its best to select the right entries when the filter changes, but this is a sufficiently niche use case that I'm not sure it's worth the complexity. I've settled for just fixing the crash for now.
Fixes #34046. Using the search filter causes all the inventory_entry objects to be recreated, so it's not safe to store a pointer to them. A previous attempt to solve this (#36139) stored copies of the inventory_entry objects, but that was also unsafe. This attempt instead stores just pointers to the underlying items. This seems to prevent the crashes. The behaviour of the window is still not always exactly correct, because using the filter will violate the invariant that the items in the compared vector correspond to the selected entries. I don't see a way to fix that in general -- sometimes the compared item is filtered out, and thus you can't possibly select the entry (because it doesn't exist). We might want to add something that does its best to select the right entries when the filter changes, but this is a sufficiently niche use case that I'm not sure it's worth the complexity. I've settled for just fixing the crash for now.
Obsoleted by #36606 |
SUMMARY: Bugfixes "Make compared have a copy of the inventory_entry rather than a pointer to fix segfault when using multiple filters"
Purpose of change
Fixes #34046
Describe the solution
Converted the compared vector to be a copy of the inventory_entry instead of a pointer.
Describe alternatives you've considered
I considered turning compared into an item* but that turned into something very invasive.
Testing
Verified that comparison works with and without filters after the change.