-
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
Rewrite ownership to use faction_id to avoid pointer crashes #34217
Conversation
…f my_fac is not valid
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, you want to encapsulate all of this stuff. That means set_owner() should have a version that takes a player as an argument and does the right thing, and all of this
if( it.has_owner() ) {
const faction_id item_fac = it.get_owner();
if( item_fac != g->u.get_faction()->id ) {
should simply be
if( !it.owned_by_player( g->u, true ) ) {
I didn't go through line by line, but just about about time you changed a function parameter from faction *
to faction_id
was a time when you should have encapsulated the logic instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting better, but you need to encapsulate more. The only time you should dealing with faction->id() is inside the accessor functions or when you only have a faction *
.
Also, consistently use Character &
instead of player &
now that the g->u has a get_fac() function.
More encapsulation, not tested yet, need to sleep, will test tomorrow. |
Co-Authored-By: BevapDin <[email protected]>
Co-Authored-By: BevapDin <[email protected]>
…wn/Cataclysm-DDA into npc_death_faction_fix
Fixed vehicle owner name display.
All seems fine. |
Summary
SUMMARY: Bugfixes "Rewrite ownership to use faction_id to avoid pointer crashes"
Purpose of change
Fixes #34209
Fixes #34212
Ownership used pointers to factions, this all seemed fine before dynamic factions.
Now when a dynamic faction is deleted, then everything they ever touched now belongs to a dangling pointer.
This requires a rewrite of ownership to use ids for safety and less crashes ( hopefully )
Describe the solution
rewrite vehicle and item ownership to use faction_id , and edit the associated structure and functions to support that
Describe alternatives you've considered
Other solution was to potentially keep dead factions around forever, but that didnt seem viable.
Additional context
I am not quite happy with this solution, Ive had to rewrite a lot, and going by what ive done recently with factions, I expect lots more bugs. Im operating at the edge of what I know how to do, but the onus is on me to fix what I broke, so this is my best effort at that.
I would appreciate scrutiny on this, ive tested and it seems ok, but I cannot judge from the code alone if this is a suitable rewrite.