C++ Question Help debugging

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,860
Reaction score
2,832
Points
203
Location
Dallas, TX
I need some to guide me to fix this.
I have run this 3 times with no CTD and then on the 4th. I get no source file found.
This is my Artemis.

Any clue on how to fix?

I can post the cpp,....

I was debugging by attaching to process.

But I tried to debug and get that is can't find it.
I was thinking it was in the load scn part. I commented out most and ctd of the 3 or 4 load.
Code:
void ARTEMIS2::clbkLoadStateEx(FILEHANDLE scn, void* status)
{
    char* line;
    int value;
    while (oapiReadScenario_nextline(scn, line))
    {
       
        {
            /*
            if (!_strnicmp(line, "MODE", 4)) {
                sscanf_s(line + 4, "%d", &value);
                mode = (int)value;
            }

             else if (!_strnicmp(line, "FAIRING", 7)) {
                fairing = 1;
            }
           
             else if (!_strnicmp(line, "BEACON", 6)) {
                    sscanf(line + 6, "%d", &BEACON);
                }
           
            else if (!_strnicmp(line, "CHAIR", 5)) {
                sscanf(line + 5, "%d", &CHAIRDEPLOY);
            }

            else if (!_strnicmp(line, "BLOWNFAIRING", 12)) {
                sscanf(line + 12, "%d", &BLOWNFAIRING);
            }

            else if (!_strnicmp(line, "HATCH", 5)) {
                sscanf(line + 5, "%d %lf", &HATCH_status, &HATCH_proc);
            }

            else if (!_strnicmp(line, "TABLE", 5)) {
                sscanf(line + 5, "%d %lf", &TABLE_status, &TABLE_proc);
            }

            else if (!_strnicmp(line, "PANELFOLD", 9)) {
                sscanf(line + 9, "%d %lf", &SPANELFOLD_status, &SPANELFOLD_proc);
            }

            else if (!_strnicmp(line, "JOINT1", 6)) {
                sscanf(line + 6, "%lf", &JOINT1_proc);
            }

            else if (!_strnicmp(line, "WING1ROTATE", 11)) {
                sscanf(line + 11, "%lf", &WING1ROTATE_proc);
            }

            else if (!_strnicmp(line, "WING2ROTATE", 11)) {
                sscanf(line + 11, "%lf", &WING2ROTATE_proc);
            }
            else if (!_strnicmp(line, "WING3ROTATE", 11)) {
                sscanf(line + 11, "%lf", &WING3ROTATE_proc);
            }
            else if (!_strnicmp(line, "WING4ROTATE", 11)) {
                sscanf(line + 11, "%lf", &WING4ROTATE_proc);
            }

            else if (!_strnicmp(line, "SOLP", 4)) {
                sscanf(line + 4, "%d %lf %d %lf", &solp_status, &solp_proc, &solp_rot_status, &solp_rot_proc);
            }

           
            switch (mode) {
            case 0:
                SetConfig0_Ready();
                break;
            case 1:
                SetConfig1_Orbit();
                break;
            case 2:
                SetConfig2_Reentry();
                break;
            case 3:
                SetConfig3_Drogue();
                break;
            case 4:
            case 5:
                SetConfig4_Chute();
                break;
            case 6:
                SetConfig6_Land();
                break;
             case 10:
                SetConfig10_Launch0();
                break;
            case 11:
                SetConfig11_Launch1();
                break;
            }
            */
            ParseScenarioLineEx(line, status);
        }

    //    SetAnimation(anim_SPANELFOLD, SPANELFOLD_proc);
    //    SetAnimation(anim_HATCH, HATCH_proc);
    //    SetAnimation(anim_TABLE, TABLE_proc);
    //    SetAnimation(anim_SPANEL1ROTATE, WING1ROTATE_proc);
    //    SetAnimation(anim_SPANEL2ROTATE, WING2ROTATE_proc);
    //    SetAnimation(anim_SPANEL3ROTATE, WING3ROTATE_proc);
    //    SetAnimation(anim_SPANEL4ROTATE, WING4ROTATE_proc);
    //    SetAnimation(anim_SPANEL, JOINT1_proc);
    }

}
and the scn:
Code:
BEGIN_DESC
Current scenario state


Contains the latest simulation state.
END_DESC

BEGIN_ENVIRONMENT
  System Sol
  Date MJD 45285.7568112807
  Context SpaceX
  Help CurrentState_img
END_ENVIRONMENT

BEGIN_FOCUS
  Ship Artemis2
END_FOCUS

BEGIN_CAMERA
  TARGET Artemis2
  MODE Extern
  POS 5.236671 81.567956 -6.628279
  TRACKMODE TargetRelative
  FOV 40.00
END_CAMERA

BEGIN_HUD
  TYPE Surface
END_HUD

BEGIN_MFD Left
  TYPE Map
  REF Earth
  POS 0.00 0.00
END_MFD

BEGIN_MFD Right
  TYPE Orbit
  PROJ Frame
  FRAME Ecliptic
  REF Earth
END_MFD

BEGIN_SHIPS
Artemis2:ARTEMIS2
  MODE 0
  BEACON 0
  BLOWNFAIRING 0
  CHAIR 0
  HATCH 0 0.0000
  TABLE 0 0.0000
  PANELFOLD 0 0.0000
  JOINT1 0.5000
  WING1ROTATE 0.5000
  WING2ROTATE 0.5000
  WING3ROTATE 0.5000
  WING4ROTATE 0.5000
  SOLP 0 0.000000 1 0.079275
  STATUS Orbiting Earth
  RPOS -6071932.655 -10.363 3500080.285
  RVEL -3766.4366 -0.0039 -6533.5397
  AROT 94.122 -78.271 175.790
  AFCMODE 7
  PRPLEVEL 0:1.000000 1:1.000000
  NAVFREQ 0 0
  XPDR 0
END
END_SHIPS

BEGIN_Attachment Manager
END
[\code]
 

Attachments

  • debugsourcenotfound.jpg
    debugsourcenotfound.jpg
    42.4 KB · Views: 6
  • artemisdebug2.jpg
    artemisdebug2.jpg
    62 KB · Views: 5
Last edited:

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,752
Reaction score
2,497
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Can you set a break point right at the beginning and right at the end of clbkLoadScenarioEx and check if there are uninitialized variables, especially afterwards?
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,860
Reaction score
2,832
Points
203
Location
Dallas, TX
So I set up a break here
And looked at the values . I removed some variables that were not used. Still CTD but after 4 reloads.

when compiling I get this:
D:\Orbiter2016\Orbitersdk\samples\ARTEMIS2\ARTEMIS2.CPP(3295,28): warning C4838: conversion from 'int' to 'double' requires a narrowing conversion

but if I make mode a double then a lot more issues
 

Attachments

  • artemisdebug3.jpg
    artemisdebug3.jpg
    58.1 KB · Views: 2
Last edited:

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,752
Reaction score
2,497
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Why is mode not an int anyway?
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,860
Reaction score
2,832
Points
203
Location
Dallas, TX
I changed it to a double

it is used to change the stages,....
Code:
switch (mode) {
    case 0:
    case 1:
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:     //Fcapsule config
    case 10:
    case 11: dz = 0;    break;
    case 12: dz = -2;    break;
    }
    switch (mode) {
    case 2:        // Orbit config  SM JETTISONED
Severity Code Description Project Path File Line Suppression State
Error C2450 a switch expression of type 'double' is not valid ARTEMIS2 D:\Orbiter2016\Orbitersdk\samples\ARTEMIS2 D:\Orbiter2016\Orbitersdk\samples\ARTEMIS2\ARTEMIS2.CPP 400
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,860
Reaction score
2,832
Points
203
Location
Dallas, TX
I changed it back. It seems to work. Need to figure why the cameras are not correct though
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,752
Reaction score
2,497
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
I changed it back. It seems to work. Need to figure why the cameras are not correct though

Thats a new problem. Is the behavior deterministic (happens every time under the same conditions) or not?
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,860
Reaction score
2,832
Points
203
Location
Dallas, TX
Thanks. Yes. it like the camera is too high now. and really not moving.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,860
Reaction score
2,832
Points
203
Location
Dallas, TX
Thanks. I removed. the wing camera and getting closer. I got her to fly in space. the launch and jettison still have issues. Tracking it down
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,860
Reaction score
2,832
Points
203
Location
Dallas, TX
I am trying to figure the Fairing code. Using from Orion mpcv.
Code:
 double fairing;
created
Code:
 fairing = 0; {/code] init.
 load [code]
if (!_strnicmp (line, "FAIRING", 7)) {
             fairing = 1;   
        }
so if the line FAIRING is in the scn then faring is set to 1. This means to show the fairing
save
Code:
if (fairing && mode > 9)
        oapiWriteScenario_int (scn, "FAIRING", mode);
Confused. shouldn't this be if fairing==1 and mode greater than 9 write "FAIRING" or is it if ( fairing and mode both over 9) do something??
Code:
case 10:
            if (GetAltitude() > 108000 ) {    // Check if blow the fairings
                if (fairing)
                    blowFairing();
                SetConfig11_Launch1();
                ReloadMeshes();
            }
        break;
what does if (fairing) do?? what does it mean??
Code:
if (fairing) {
            AddMesh (fair1Mesh, &ofs);
            AddMesh (fair2Mesh, &ofs);
            AddMesh (fair3Mesh, &ofs);
        }
[\code] what does if (fairing) do??
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,752
Reaction score
2,497
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Why is fairing a double? Can you have 0.5 fairing?
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,860
Reaction score
2,832
Points
203
Location
Dallas, TX
Why is fairing a double? Can you have 0.5 fairing?
Not sure that is what it is in the orion Mpcv. But it looks like it matches the mode. What I do not understand what
Code:
 if (fairing) [\code] does?
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,860
Reaction score
2,832
Points
203
Location
Dallas, TX
One difference is how meshes are seen.
In Orion mpcv. meshes are added as needed.
In mine they are all loaded. and then based off conditions they are set to be be seen or not.
Code:
FAIR1MESH = oapiLoadMesh("ARTEMIS\\ARTEMISFAIR_1");//13
    FAIR2MESH = oapiLoadMesh("ARTEMIS\\ARTEMISFAIR_2");//14
    FAIR3MESH = oapiLoadMesh("ARTEMIS\\ARTEMISFAIR_3");//15
    SetMeshVisibilityMode(AddMesh(FAIR1MESH), MESHVIS_NEVER);
    SetMeshVisibilityMode(AddMesh(FAIR2MESH), MESHVIS_NEVER);
    SetMeshVisibilityMode(AddMesh(FAIR3MESH), MESHVIS_NEVER);

Code:
case 10:        // Orbit config
        SetMeshVisibilityMode(3, MESHVIS_EXTERNAL | MESHVIS_VC);
        SetMeshVisibilityMode(2, MESHVIS_EXTERNAL | MESHVIS_VC);
        SetMeshVisibilityMode(12, MESHVIS_ALWAYS);//las
        if (fairing) {
            SetMeshVisibilityMode(13, MESHVIS_EXTERNAL | MESHVIS_VC);//fairing
            SetMeshVisibilityMode(14, MESHVIS_EXTERNAL | MESHVIS_VC);//fairing
            SetMeshVisibilityMode(15, MESHVIS_EXTERNAL | MESHVIS_VC);//fairing
        }
       
        break;
[\code]
So if mode/case =10 in orbit.   set the mesh 3 and 2 MESHVIS_EXTERNAL | MESHVIS_VC); and  mesh 12 always.   And if (fairing) show the 3 fairing meshes.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,860
Reaction score
2,832
Points
203
Location
Dallas, TX
Working on the launch, fairing, LAS,....
Running debugger. At the beginning of the scenario.
FAIRING 10 which is the mode number
I have break setup when the flaring blow. In the debugger fairing is 1.00000
but then get this symbol file not found.
 

Attachments

  • orion3.jpg
    orion3.jpg
    53.2 KB · Views: 0
  • orion2.jpg
    orion2.jpg
    54.9 KB · Views: 0
  • orion1.jpg
    orion1.jpg
    21.7 KB · Views: 0

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,752
Reaction score
2,497
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
If it is really a part of the structural state machine, fairing should be superfluous and much less needs to be a double. Thats just one more error source more. What will you do if fairing is not 0 or 1.000 but +1E-49?
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,860
Reaction score
2,832
Points
203
Location
Dallas, TX
Thanks. Just following the Orion MPCV code. I guess I expected a statement like if
Code:
((fairing)>0  do something)
not
Code:
 if (fairing) do something
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,752
Reaction score
2,497
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Thats OK with C or C++, just bad style. Any value that is not 0 is interpreted as true in a if statement (or similar).

Thats why I warn of doubles. a infinitesimal small number above zero is still non-zero.

Much better is using enums or at least named constants for a state machine, like:

Code:
if (state == FAIRING_SEPARATION) {
  //eject the fairing
 //do something else
state = AFTER_FAIRING_SEPARATION;
}

As you can see, its easier to read already.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,860
Reaction score
2,832
Points
203
Location
Dallas, TX
Thanks
SO I did this:
Code:
 enum FAIRINGStatus { SEPARATE,NOT_SEPARATE } FAIRING_status;
Code:
FAIRING_status = NOT_SEPARATE;
initialize
then where the meshes are set up.
Code:
case 10:        // Orbit config
        SetMeshVisibilityMode(3, MESHVIS_EXTERNAL | MESHVIS_VC);//cover
        SetMeshVisibilityMode(2, MESHVIS_EXTERNAL | MESHVIS_VC);//sm
        SetMeshVisibilityMode(12, MESHVIS_ALWAYS);//las
        if (FAIRING_status== NOT_SEPARATE) {///show fairing
            SetMeshVisibilityMode(13, MESHVIS_EXTERNAL | MESHVIS_VC);//fairing
            SetMeshVisibilityMode(14, MESHVIS_EXTERNAL | MESHVIS_VC);//fairing
            SetMeshVisibilityMode(15, MESHVIS_EXTERNAL | MESHVIS_VC);//fairing
        }
        if (FAIRING_status == SEPARATE) {
            SetMeshVisibilityMode(13, MESHVIS_NEVER);//fairing
            SetMeshVisibilityMode(14, MESHVIS_NEVER);//fairing
            SetMeshVisibilityMode(15, MESHVIS_NEVER);//fairing
        }
        break;
and when the fairing are blown set the state to separate
Code:
void ARTEMIS2::blowFairing() {
    
        PROPELLANT_HANDLE ph_lhf_aux, ph_rhf_aux;
        THRUSTER_HANDLE th_lhf_aux, th_rhf_aux;

        VESSELSTATUS vs;
        char name[256] = { "" };
        //    THRUSTER_HANDLE th_att_lin[16];
        //    OBJHANDLE h;
        VESSEL* v;
        (FAIRING_status = SEPARATE);
        //    ReloadMeshes();
        CHANGESTATE();
    

        GetStatus(vs);
        vs.flag[0] = 3;
        ofs = _V(0, 0, 0);
        Local2Rel(ofs, vs.rpos);

        sprintf_s(name, "%s-fair1", GetName());
        Local2Rel(ofs, vs.rpos);
        fair1h = oapiCreateVessel(name, "ARTEMIS_FAIR1", vs);
        v = oapiGetVesselInterface(fair1h);

        v->SetEmptyMass(200);
        ph_lhf_aux = v->CreatePropellantResource(5, 5, 1.0);
        th_lhf_aux = v->CreateThruster(_V(0, 0.0, 1.0), _V(0, -0.95, 0.1), 5000.0, ph_lhf_aux, 300.0, 0.0, 0);
        v->SetThrusterLevel(th_lhf_aux, 1.0);
        v->SetEnableFocus(false);
        //******
        GetStatus(vs);
        vs.flag[0] = 3;
        ofs = _V(0, 0, 0);
        Local2Rel(ofs, vs.rpos);

        sprintf_s(name, "%s-fair2", GetName());
        Local2Rel(ofs, vs.rpos);
        //        vs.arot.z += PI;
        fair2h = oapiCreateVessel(name, "ARTEMIS_FAIR2", vs);
        v = oapiGetVesselInterface(fair2h);

        v->SetEmptyMass(200);
        ph_rhf_aux = v->CreatePropellantResource(5, 5, 1.0);
        th_rhf_aux = v->CreateThruster(_V(0, 0.0, 1.0), _V(-0.87, 0.5, 0.1), 5000.0, ph_rhf_aux, 300.0, 0.0, 0);
        v->SetThrusterLevel(th_rhf_aux, 1.0);
        v->SetEnableFocus(false);

        //******
        GetStatus(vs);
        vs.flag[0] = 3;
        ofs = _V(0, 0, 0);
        Local2Rel(ofs, vs.rpos);

        sprintf_s(name, "%s-fair3", GetName());
        Local2Rel(ofs, vs.rpos);
        //        vs.arot.z += PI;
        fair3h = oapiCreateVessel(name, "ARTEMIS_FAIR3", vs);
        v = oapiGetVesselInterface(fair3h);

        v->SetEmptyMass(200);
        ph_rhf_aux = v->CreatePropellantResource(5, 5, 1.0);
        th_rhf_aux = v->CreateThruster(_V(0, 0.0, 1.0), _V(0.87, 0.5, 0.1), 5000.0, ph_rhf_aux, 300.0, 0.0, 0);
        v->SetThrusterLevel(th_rhf_aux, 1.0);
        v->SetEnableFocus(false);
        
}
[\code]

ran the scenario.  the fairing separated then ctd.
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,752
Reaction score
2,497
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
So, you have to find out what else triggers the CTD, if the fairings still separate. Also, I would consider in your case, to modell all structural stages (first stage, second stage, with fairing, without fairing) and all transition states (Staging 1->2, fairing separation) in one int variable and define constants to name the values. This way, it should be fairly easy to debug and you can have transitions that can be longer lasting that instantly.
 
Top