API Question Why shouldn't you delete an oapi::Module?

AeroSpatial

New member
Joined
Aug 2, 2018
Messages
4
Reaction score
0
Points
0
I'm a bit perplexed by the following note in the API documentation for oapiRegisterModule:

"The DLL should not delete the module instance in ExitModule. Orbiter destroys all registered modules automatically
when required."

1. How can Orbiter destroy the module instance, with no knowledge of how it is allocated?

2. At the point that ExitModule is called, what use does Orbiter have for any remaining module instances?
 

martins

Orbiter Founder
Orbiter Founder
Joined
Mar 31, 2008
Messages
2,448
Reaction score
462
Points
83
Website
orbit.medphys.ucl.ac.uk
Orbiter simply deletes the module instance on unloading the library. A cleaner method may have been to provide an "oapiUnregisterModule" function that unhooks the module instance from Orbiter's internal module table, after which the module instance could be deleted in the library.

While the rationale for the current method is somewhat lost in the mist of time, one potential reason was that legacy modules don't create any oapi::Module instance at all and communicate with Orbiter by top-level callback functions. For these, Orbiter internally creates a Module instance whose default methods link to these callback functions. This is so Orbiter doesn't need to distinguish between legacy and "new" plugins for communication. For the legacy modules, Orbiter has to delete the Module instances anyway, so for simplicity I am doing the same for all the other modules as well.

I don't know if this explanation makes much sense, but it's the best I can reconstruct for now from a brief look at the code ;)
 
Top