Project Air Breathing Turbojet Engine Model for Orbiter

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,327
Reaction score
3,248
Points
138
Location
Massachusetts
You should be able to set a breakpoint in the debugger before even starting Oribter.exe -- check out https://docs.microsoft.com/en-us/visualstudio/debugger/using-breakpoints?view=vs-2022. Try putting a breakpoint at the start of clbkSetClassCaps, for example. Then once you start Orbiter.exe in the debugger and load your scenario, you should still see a solid red dot on far left of the line where you put the breakpoint. If, however, it turns into a hollow red dot, that means that DLL containing that code was either not loaded by Orbiter.exe or the debugger can't find symbols for that code. If that happens, make sure you're building your code with full debug information for Debug builds; this is the default, but if you're sure that code is being hit and the breakpoint still won't activate, that points to the symbols not being loaded.
I did exactly this, and even if I put the breakpoint at one of the first lines of the main code the breakpoint is not reached after running Orbiter. exe. I am getting warnings all over the place saying symbols not being loaded.
One other thing to check is that you are building the Debug version of your vessel's DLL into the proper Orbiter folder (e.g., C:\Orbiter\Modules) so that Orbiter loads that debug version. This is set in the linker properties for your project, or you can use a post-build event (which is the method I prefer) to copy your vessel DLL to your Orbiter\Modules folder -- check out https://docs.microsoft.com/en-us/vi...om-build-events-in-visual-studio?view=vs-2022 for details.
Yes, I am manually copying the debug DLL to the modules folder.
 

kuddel

Donator
Donator
Joined
Apr 1, 2008
Messages
2,064
Reaction score
507
Points
113
So I think the best way would be to give you a set of "better" Project files (.vcxproj & .sln)
Could you post your current versions (as ZIP)? Just the two files xxxxxxx.vcxproj & xxxxxxx.sln (Whatever their actual name is)

So I can possibly change them to work better - That is: you could just build a debug version and hit F5 to debug your code.

I once posted a project (not 100% ready) named slngen somewhere, that might help to create them, ...but I would not bet high amounts of money on that ;)

Please also note what version of Visual Studio you are using (2019?).
If I can find some time tomorrow I'd be happy to create a new set of project files for you - at least I would like to try.
Explaining all the things you might have to change in a thread like this would probbaby take days. Explaining what changed after we got it working might be easier (and could be completely skipped if it doesn't work ;) )
 

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,327
Reaction score
3,248
Points
138
Location
Massachusetts
So I think the best way would be to give you a set of "better" Project files (.vcxproj & .sln)
Could you post your current versions (as ZIP)? Just the two files xxxxxxx.vcxproj & xxxxxxx.sln (Whatever their actual name is)

So I can possibly change them to work better - That is: you could just build a debug version and hit F5 to debug your code.

I once posted a project (not 100% ready) named slngen somewhere, that might help to create them, ...but I would not bet high amounts of money on that ;)

Please also note what version of Visual Studio you are using (2019?).
If I can find some time tomorrow I'd be happy to create a new set of project files for you - at least I would like to try.
Explaining all the things you might have to change in a thread like this would probbaby take days. Explaining what changed after we got it working might be easier (and could be completely skipped if it doesn't work ;) )
I have already done this.
 

kuddel

Donator
Donator
Joined
Apr 1, 2008
Messages
2,064
Reaction score
507
Points
113
Ooops, then I have to look for it further up ;) Time to go to bed I think :D

Addendum:
On a quick look up this thread I could only find ZIPs containing python code ?‍♂️ Are you shure we are on the same page?
 

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,327
Reaction score
3,248
Points
138
Location
Massachusetts
Yes. That was my initial math model for the engine. Now I'm trying to get that math into an Orbiter add-on.
 

kuddel

Donator
Donator
Joined
Apr 1, 2008
Messages
2,064
Reaction score
507
Points
113
Exactly! You (@Thunder Chicken) try to debug a Module (either a Vessel or an MFD I think). That is what I like to inspect. In the whole Thread you mentioned "[...]Kev's code[...]" and mentioned @hagiasophia420 giving you some (MFD-)code.
Whatever Module you try to debug, that project I would like to be shared with me ;)
Probably best to provide the ZIPs that were given to you - In case they are not meant to be made public (authors choice): Send to me as PM.
 

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,327
Reaction score
3,248
Points
138
Location
Massachusetts
I'm stepping through the code in the debugger and it seems the instant that it steps out of clbkPostStep I get the following exceptions:

The thread 0x12e8 has exited with code 0 (0x0).
The thread 0x22c0 has exited with code 0 (0x0).
The thread 0x1444 has exited with code 0 (0x0).
Exception thrown at 0x0050C594 in orbiter.exe: 0xC0000005: Access violation reading location 0x00000000.


I also get a console message stating "No symbol file loaded for orbiter.exe"

I'm not seeing any problems with the calculations up to that point, watched values look fine.

Ideas?
 

N_Molson

Addon Developer
Addon Developer
Donator
Joined
Mar 5, 2010
Messages
9,272
Reaction score
3,244
Points
203
Location
Toulouse
Looks awfully like memory access errors. Pointers are the usual suspects. Symbols like & and * have to be used with extreme caution.
 

Linguofreak

Well-known member
Joined
May 10, 2008
Messages
5,017
Reaction score
1,254
Points
188
Location
Dallas, TX
I'm stepping through the code in the debugger and it seems the instant that it steps out of clbkPostStep I get the following exceptions:

The thread 0x12e8 has exited with code 0 (0x0).
The thread 0x22c0 has exited with code 0 (0x0).
The thread 0x1444 has exited with code 0 (0x0).
Exception thrown at 0x0050C594 in orbiter.exe: 0xC0000005: Access violation reading location 0x00000000.


I also get a console message stating "No symbol file loaded for orbiter.exe"

I'm not seeing any problems with the calculations up to that point, watched values look fine.

Ideas?

An access violation accessing address zero means some code tried dereferencing a null pointer.

The fact that Orbiter tried dereferencing a null pointer (indicated by the fact that the "thrown at" location is in orbiter.exe) indicates that a bug exists in Orbiter (failure somewhere to check that a pointer is valid), the fact that it happens immediately upon return from a callback indicates a bug in your callback code (you likely handed Orbiter a bad pointer that it then failed to check for validity). You likely have a pointer that is uninitialized or otherwise null that is being handed to Orbiter.
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,588
Reaction score
2,312
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
I also get a console message stating "No symbol file loaded for orbiter.exe"

Again, as reminder: This is perfectly as expected and no important message, except that the debugging will be much more technical, on disassembled machine language, and thus much less easy, especially if you have no clue about assembly language and call conventions. So you better ignore this: If life gives you lemons, make lemonade.

Orbiter.exe has no symbols and will likely never get symbols, unless you produce your own debug build of Orbiter locally. Its not helpful to publish debug builds.
 

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,327
Reaction score
3,248
Points
138
Location
Massachusetts
I'm not even sure what is happening anymore. It seems that every time I close the IDE and restart it I get different build behavior. Now I can't even get it to hit a breakpoint at the start of the code before an exception occurs.

Orbiter.exe has no symbols and will likely never get symbols, unless you produce your own debug build of Orbiter locally. Its not helpful to publish debug builds.
Can you explain this a bit more? I have been doing debug builds all along, because debugging. Is this wrong?
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,588
Reaction score
2,312
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
I'm not even sure what is happening anymore. It seems that every time I close the IDE and restart it I get different build behavior. Now I can't even get it to hit a breakpoint at the start of the code before an exception occurs.


Can you explain this a bit more? I have been doing debug builds all along, because debugging. Is this wrong?

For you, locally, its great and important to use debug builds. All correct.

But you should never provide Debug builds for download to the public, unless you tag it with a HUGE warning sign.

Also, important to remember: Debug and Release MAY have completely different behaviour. Debug for example does a lot of things with the memory of your program to make it easier to find usages of uninitialized memory. Release won't. In the best case, you can get blank memory from the OS to prevent any chances of memory contents leaking. But it doesn't have any effects on your program during runtime, while VC++ in Debug build has such effects.
 

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,327
Reaction score
3,248
Points
138
Location
Massachusetts
For you, locally, its great and important to use debug builds. All correct.

But you should never provide Debug builds for download to the public, unless you tag it with a HUGE warning sign.
I am aware of this.

Also, important to remember: Debug and Release MAY have completely different behaviour.
Neat. :rolleyes:
Debug for example does a lot of things with the memory of your program to make it easier to find usages of uninitialized memory.
I will have to find out where it tells me this. I can't even get a breakpoint to trigger right now and I don't know how this code is failing.
 

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,327
Reaction score
3,248
Points
138
Location
Massachusetts
There are a large number of variables associated with animations that are currently declared and initialized in main, and I am wondering if they should go in the vessel class or somewhere else.
 

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,327
Reaction score
3,248
Points
138
Location
Massachusetts
OK, I went back to Kev's original code and carefully reworked it and now I am not getting the exceptions. There are loads of pointers in the animation sections and I must have broken something. Anyway, it's compiling and building, and running in Orbiter, but I'm not getting any response from the throttle. This is the code in the clbkPostStep that is supposed to do this:


C++:
void K_Mirage2000::clbkPostStep(double simt, double simdt, double mjd)
{
...
//----JET ENGINE IMPLEMENTATION

    //Get throttle input from user from dummy thruster

    throttle = GetThrusterGroupLevel(THGROUP_MAIN);
  
    //determine afterburner status

    afterburner = false; //How is afterburner engaged in real jet?

    // Get local flight conditions from Orbiter

    M_0 = GetMachNumber();            //flight Mach number [-]
    T_0 = GetAtmTemperature();          //ambient static temperature [K]
    P_0 = GetAtmPressure();             //ambient static pressure [Pa absolute]
    rho = GetAtmDensity();             //ambient atmospheric density [kg/cubic meter]

    //Use inputs and flight conditions to calculate jet engine thrust and Isp

    std::pair<double, double> answer = GetJetEngineThrustIsp(throttle, afterburner, M_0, T_0, P_0, rho);

    thrust = answer.first;

    Isp = answer.second;

    //Update thrust and Isp of user-defined main engine

    SetThrusterIsp(th_main, max(Isp, 1));

    SetThrusterGroupLevel(THGROUP_USER, abs(thrust) / max(max_thrust, max_thrust_ab));

    //----END JET ENGINE IMPLEMENTATION
...
}
This calculates thrust and Isp correctly, but in Orbiter actuating the throttle does nothing. The idea is that there is a dummy thruster (th_dummy) in THGROUP_MAIN. The user-input main engine throttle setting is determined from this, passed into the thrust and Isp calculation, and the Isp gets set to the th_main thruster and the THGROUP_USER group thruster level is set with the new thrust.
 
Last edited:

Max-Q

99 40
Addon Developer
Joined
Jul 5, 2021
Messages
765
Reaction score
1,181
Points
108
Location
Cislunar Space
Website
www.orbiter-forum.com
You need to use GetManualControlLevel() instead of GetTrusterGroupLevel(). Look it up in Orbiter’s api documentation.
Since the dummy thruster is has a propellant resource of NULL, it’s level will always be zero. AFIK, with GetManualControlLevel(), you don’t need to define the dummy thruster at all.
 

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,327
Reaction score
3,248
Points
138
Location
Massachusetts
You need to use GetManualControlLevel() instead of GetTrusterGroupLevel(). Look it up in Orbiter’s api documentation.
Since the dummy thruster is has a propellant resource of NULL, it’s level will always be zero. AFIK, with GetManualControlLevel(), you don’t need to define the dummy thruster at all.
API reference states that that is for attitude control thrusters:

double VESSEL::GetManualControlLevel ( THGROUP_TYPE thgt, DWORD mode = MANCTRL_ATTMODE,
DWORD device = MANCTRL_ANYDEVICE ) const

Returns the thrust level of an attitude thruster group set via keyboard or mouse input.
 

Max-Q

99 40
Addon Developer
Joined
Jul 5, 2021
Messages
765
Reaction score
1,181
Points
108
Location
Cislunar Space
Website
www.orbiter-forum.com
API reference states that that is for attitude control thrusters:

double VESSEL::GetManualControlLevel ( THGROUP_TYPE thgt, DWORD mode = MANCTRL_ATTMODE,
DWORD device = MANCTRL_ANYDEVICE ) const

Returns the thrust level of an attitude thruster group set via keyboard or mouse input.
It works for any thruster group. Just set “thgt” to THGROUP_MAIN and it should work fine.
 

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,327
Reaction score
3,248
Points
138
Location
Massachusetts
It works for any thruster group. Just set “thgt” to THGROUP_MAIN and it should work fine.

I tried this and nothing happened:

throttle = GetManualControlLevel(THGROUP_MAIN, MANCTRL_ANYMODE, MANCTRL_ANYDEVICE);
 
Top