sparcians / map

Modeling Architectural Platform
Apache License 2.0
165 stars 59 forks source link

Define custom copy/move constructors/operators for SharedData and GlobalEvent #493

Closed bdutro closed 6 months ago

bdutro commented 6 months ago

I ran into a segfault when I tried to create an std::vector of SharedData. There were two underlying causes for this:

  1. When GlobalEvent is moved/copied, it doesn't update ev_handler_lifetime_ to point to the new instance of event_handler_. If the original GlobalEvent was later destroyed, the copy would segfault when it tried to fire its handler.
  2. When SharedData is moved/copied, its ev_update_ receives a copy of the handler in the original SharedData. If the original was later destroyed, the copy would segfault when it tried to perform its state update.

This PR defines copy/move constructors and assignment operators for both classes so that everything gets updated properly and the copies can continue to function after the originals are destroyed.

klingaard commented 6 months ago

Good catch. This has been plaguing me for quite some time!