Sequal32 / simconnect-rust

SimConnect bindings for rust.
MIT License
32 stars 13 forks source link

implement drop for SimConnector #3

Closed ryanstew closed 4 years ago

ryanstew commented 4 years ago

I get occasional crashes when using SimConnector in a process that creates/tears down multiple SimConnectors over its lifetime. I wonder if the crashes stem from the dangling handles here, but even if not the handle leak is not ideal.

I realize losing Copy/Clone has some implications here. I could just expose close() instead and handle this externally, but still wouldn't be safe because copies would be left with invalid handles.

Sequal32 commented 4 years ago

Perhaps a reference counter can help here to be able to implement copy/clone and drop. Once all the references are dropped, then SimConnect_Close() can be called.

Have you confirmed that the crashes are resolved after implementing drop?

ryanstew commented 4 years ago

Seems to me it would make more sense to wrap SimConnector in Arc/Rc if ref counting is desired vs. forcing it even in use cases where copy is not used, what do you think?

I have not seen a crash since I started testing this change, but the crash was very infrequent and generally after long idle times so I wouldn't take that as definitive data.

Sequal32 commented 4 years ago

That's fair enough, thanks!