C++ Question clearing variable value in plugin

malisle

Donator
Donator
Joined
Jul 8, 2012
Messages
110
Reaction score
0
Points
16
I have a question about variable behaviour in Orbiter plugins - I noticed that variables will retain their last value even if the current simulation session has been closed, which leads to some problems in the next scenario. It will only clear completely when the Orbiter Launchpad has been closed as well. How can I make sure that the variables will be cleared, or set to default values even if the Launchpad has not been closed? Is this something that only happens with plugins or do I have to be careful with vessels and MFDs? I know this is something basic (page 2, API guide), but I still don't understand what exactly is going on.
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,641
Reaction score
2,356
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
You can change the shutdown behavior of Orbiter, so that all DLLs are unloaded. Otherwise, there are callbacks for the loading and unloading of DLLs as well.
 

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
If you registered it as a module with oapiRegisterModule then you can use the Module's clbkSimulationEnd callback to clear variables and deallocate resources allocated during simulation. If you don't use the Module interface, then you can use generic opcCloseRenderViewport DLL callback to do the same.

ExitModule is called only when plug-in module is unloaded from memory, i.e. the process loading it was terminated, or when it was unchecked on the Modules tab (similarly InitModule, but only when the module is loaded, either when you execute Orbiter.exe when it is included in Orbiter.cfg, or when you check it on the Modules tab).

For pure vessel only modules, InitModule and ExitModule are called at simulation start and simulation end, because they are loaded only for the scenario, and unloaded when scenario ends (or when the vessel is first created and last deleted).
 

malisle

Donator
Donator
Joined
Jul 8, 2012
Messages
110
Reaction score
0
Points
16
ExitModule is called only when plug-in module is unloaded from memory, i.e. the process loading it was terminated (...)

And when does that happen, on closing the simulation or closing the Orbiter altogether? Urwumpe mentioned shutdown options; is there a way to unload variables using ExitModule from memory regardless of those?
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,641
Reaction score
2,356
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
And when does that happen, on closing the simulation or closing the Orbiter altogether? Urwumpe mentioned shutdown options; is there a way to unload variables using ExitModule from memory regardless of those?

You can make Orbiter do a full restart of itself. All modules unloaded, Orbiter terminated and then started again.

But better is, like orb said, to look for the events that relate to the simulation.
 

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
And when does that happen, on closing the simulation or closing the Orbiter altogether?
The Orbiter process is terminated when you close the launchpad or when the simulation ends with either respawn or terminate shutdown option.

Urwumpe mentioned shutdown options; is there a way to unload variables using ExitModule from memory regardless of those?
No. Use Module::clbkSimulationEnd or opcCloseRenderViewport instead. Shutdown options are user specific, and you can't make everybody change them to "respawn" or "terminate".
 

malisle

Donator
Donator
Joined
Jul 8, 2012
Messages
110
Reaction score
0
Points
16
Is just calling:

Code:
DLLCLBK void ExitModule (HINSTANCE hModule) 
{ 
    
}

enough to deallocate variables or do I have to specify something inside {}?

---------- Post added at 22:17 ---------- Previous post was at 22:15 ----------

No. Use Module::clbkSimulationEnd or opcCloseRenderViewport instead. Shutdown options are user specific, and you can't make everybody change them to "respawn" or "terminate".

Ah okey, thank you for the help. I will try the way you suggested.
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,641
Reaction score
2,356
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Is just calling:

Code:
DLLCLBK void ExitModule (HINSTANCE hModule) 
{ 
    
}
enough to deallocate variables or do I have to specify something inside {}?

C++ is very easy. If you don't tell it to do something, it won't do it.
 

fort

Active member
Joined
Mar 19, 2008
Messages
1,018
Reaction score
20
Points
38
C++ is very easy. If you don't tell it to do something, it won't do it.

Finally, all lights!

I never asked to c + + anything ( for this reason that I know nothing about c + + ); it probably is, by reciprocity, why c + + has never done anything for me. :facepalm:
 
Last edited:
Top