New Release D3D9Client Development

JDat

Member
Joined
Sep 6, 2010
Messages
92
Reaction score
49
Points
18
You are almost THERE!

Font releasing happens in wrong function.
Code:
oapiReleaseFont(Atlantis::font3);

The idea is following:
1) When you initialize your vessel Atlantis you also initialize additional resources including font. Than is reason why oapiCreateFont() happen in function clbkPostCreation()
2) Then you use this font in RedrawPanel_MFDButton(). This is called on every frame update. You don't need to allocate/deallocate/create/destroy/release font resource here.
3) When you don't need font anymore you must release/destroy it. Let me see in what function you need to release unneeded font.
So far I suggest to release font here (Atlantis class destructor):
Code:
Atlantis::~Atlantis () {
oapiReleaseFont (Atlantis::font1);
}

But, maybe there is better place (function) where to deallocate/release/remove font. I will check it in sample code, but little later.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
6,696
Reaction score
956
Points
203
Location
Dallas, TX
Thanks. now getting this in debug
yPprqCw.jpg

I have this:
void Atlantis::RedrawPanel_MFDButton(SURFHANDLE surf, int mfd) { // oapi::Font* font3 = oapiCreateFont(-11, true, "Arial"); //g_Param.font[0] = CreateFont (-11, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 0, "Arial"); oapi::Sketchpad* skp = oapiGetSketchpad(surf); //skp->SetTextColor(BBGGRR) skp->SetFont(Atlantis::font3); skp->SetTextColor(0x00FF00); skp->SetTextAlign(oapi::Sketchpad::CENTER); if (oapiGetMFDMode(mfd) == MFD_NONE) { RECT r = { 0, 0, 255, 13 }; //skp->Rectangle(0, 0, 255, 13); //skp->SetBrush(gBlackBrush); // Enable shape filling auto Old = skp->SetPen(NULL); // Disable outline skp->Rectangle(0, 0, 255, 13); skp->SetBrush(NULL); // Disable shape filling skp->SetPen(Old); } else { // MFD powered on const char* label; int x = 24; for (int bt = 0; bt < 5; bt++) { if (label = oapiMFDButtonLabel(mfd, bt)) { skp->Text(x, 1, label, strlen(label)); x += 42; } else break; } skp->Text(234, 1, "PG", 2); } oapiReleaseSketchpad(skp); } and this:
// -------------------------------------------------------------- // Destructor // -------------------------------------------------------------- Atlantis::~Atlantis () { // UnregisterMFDMode (ascapMfdId); // if (ascentApDlg) delete ascentApDlg; // delete ascap; delete plop; int i; for (i = 0; i < 6; i++) delete rms_anim[i]; oapiReleaseFont(Atlantis::font3); }
 

JDat

Member
Joined
Sep 6, 2010
Messages
92
Reaction score
49
Points
18
Wow! This is THE ERROR!

What about ExitModule from Orbiter2016/Orbitersdk/doc/API_Guide.pdf page 2:
Code:
DLLCLBK void ExitModule (HINSTANCE hModule)
{
// perform module cleanup here
oapiReleaseFont (Atlantis::font1);
}

or this from page3:
Code:
DLLCLBK void ovcExit (VESSEL *vessel)
{
if (vessel) delete (MyVessel*)vessel;

oapiReleaseFont (Atlantis::font1);
}

But do oapiReleaseFont (Atlantis::font1); only in one function and not in all.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
6,696
Reaction score
956
Points
203
Location
Dallas, TX
Thanks.
so I did this:
DLLCLBK void ExitModule (HINSTANCE hModule) { oapiUnregisterCustomControls (hModule); oapiDestroySurface (g_Param.tkbk_label); // deallocate GDI resources DeleteObject (g_Param.font[0]); oapiReleaseFont(Atlantis::font3); }
but get this:
Severity Code Description Project Path File Line Suppression State Error C2597 illegal reference to non-static member 'Atlantis::font3' SPACESHUTTLE2016EARLYMET D:\Orbiter2016\Orbitersdk\samples\SPACESHUTTLE2016E4evaearlyvccammoveEVAnewmfd MET D:\Orbiter2016\Orbitersdk\samples\SPACESHUTTLE2016E4evaearlyvccammoveEVAnewmfd MET\Atlantis.cpp 9335
it says that font3 is inaccessible. Is this because it is private?

Not sure what you meant by do the release font in one function and not all. I think you mean but it in the destructor and not all the redraw functions?
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
6,696
Reaction score
956
Points
203
Location
Dallas, TX
// -------------------------------------------------------------- // Vessel cleanup // -------------------------------------------------------------- DLLCLBK void ovcExit (VESSEL *vessel) { if (vessel) delete (Atlantis*)vessel; oapiReleaseFont(Atlantis::font3); }

same font3 inaccessible
 

JDat

Member
Joined
Sep 6, 2010
Messages
92
Reaction score
49
Points
18
Can you put whole code on gihub if your project is open source, or put at least Atlantis.h and Atlantis.cpp on pastebin? I want to see "whole picture".
 

jarmonik

Well-known member
Orbiter Contributor
Addon Developer
Beta Tester
Joined
Mar 28, 2008
Messages
2,330
Reaction score
376
Points
83
Website
users.kymp.net
When a pen, brush or font is created as global or class wide there is no need to release it, the client will release it for you. Some cases there are no proper callback for a release to occur. Release will crash if you try to release graphics stuff after the graphics engine it-self been shutdown.

Don't use "Altantis::" when accessing variables.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
6,696
Reaction score
956
Points
203
Location
Dallas, TX
When a pen, brush or font is created as global or class wide there is no need to release it, the client will release it for you. Some cases there are no proper callback for a release to occur. Release will crash if you try to release graphics stuff after the graphics engine it-self been shutdown.

Don't use "Altantis::" when accessing variables.
Confused:( so no need to release? I guess then where to create the font?
 

JDat

Member
Joined
Sep 6, 2010
Messages
92
Reaction score
49
Points
18
Hmm. If jamonik said: "no need to release font", then... comment out oapiReleaseFont() from you code.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
6,696
Reaction score
956
Points
203
Location
Dallas, TX
removed the release line. I get a CTD/ when running the debug
bl3Li4S.jpg

skp->Text(x, 1, label, strlen(label));
 

JDat

Member
Joined
Sep 6, 2010
Messages
92
Reaction score
49
Points
18
Hmm. Why your RedrawPanel_MFDButton is so different from original Atralntis.cpp RedrawPanel_MFDButton

Code:
// Original Atlantis.cpp

void Atlantis::RedrawPanel_MFDButton (SURFHANDLE surf, int mfd)
{
    HDC hDC = oapiGetDC (surf);

    // D. Beachy: BUGFIX: if MFD powered off, cover separator lines and do not paint buttons
    if (oapiGetMFDMode(mfd) == MFD_NONE) {
        RECT r = { 0,0,255,13 };
        FillRect(hDC, &r, (HBRUSH)GetStockObject(BLACK_BRUSH));
    } else {   // MFD powered on
        HFONT pFont = (HFONT)SelectObject (hDC, g_Param.font[0]);
        SetTextColor (hDC, RGB(0,255,216));
        SetTextAlign (hDC, TA_CENTER);
        SetBkMode (hDC, TRANSPARENT);
        const char *label;
        int x = 24;

        for (int bt = 0; bt < 5; bt++) {
            if (label = oapiMFDButtonLabel (mfd, bt)) {
                TextOut (hDC, x, 1, label, strlen(label));
                x += 42;
            } else break;
        }
        TextOut (hDC, 234, 1, "PG", 2);
        SelectObject (hDC, pFont);
    }

    oapiReleaseDC (surf, hDC);
}

See the "TextOut" ? No Sketchpad and other differences...

Maybe you need to go back to original code (not all 10k lines, but some parts) and then implement your addition by small steps. step by step, then test/debug and again and again, until your get your result.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
6,696
Reaction score
956
Points
203
Location
Dallas, TX
I thought the idea was not to have HDC?

So I tried to convert the hdc to sketchpad

I went back to the orginal Atlantis code and no issues. So use HDC or sketchpad or a mixture?
 

jarmonik

Well-known member
Orbiter Contributor
Addon Developer
Beta Tester
Joined
Mar 28, 2008
Messages
2,330
Reaction score
376
Points
83
Website
users.kymp.net
If you create fonts, pens and brushes in vessel constructor then it's possible that the graphics engine is not yet "fully" running and the font creation fails. I have never created a vessel for the orbiter, so, my knowledge of internal timings is not the best possible. It would be nice the have a chart showing the timing/calling order of initialization and shutdown callbacks.

Could you try clbkPostCreation() and clbkVisualCreated() for creating Fonts, Pens and Brushes. In a case of the later doing the release stuff in clbkVisualDestroyed() would not hurt.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
6,696
Reaction score
956
Points
203
Location
Dallas, TX
Thanks.
void Atlantis::RedrawPanel_PANELRCSstatus(SURFHANDLE surf, int part) { char cbuf[20]; //oapi::Font* font1 = oapiCreateFont(50, true, "*Seven Segment"); oapi::Sketchpad* skp = oapiGetSketchpad(surf); skp->SetFont(Atlantis:: font1); skp->SetTextColor(0x0000FF); skp->SetTextAlign(oapi::Sketchpad::LEFT); sprintf(cbuf, "%2.0f", RCSQTY); skp->Text(0, 100, cbuf, strlen(cbuf)); skp->Text(210, 100, cbuf, strlen(cbuf)); skp->Text(105, 100, cbuf, strlen(cbuf)); oapiReleaseSketchpad(skp); }

and in the
void Atlantis::clbkPostCreation () { oapi::Font* font1 = oapiCreateFont(50, true, "*Seven Segment"); oapi::Font* font2 = oapiCreateFont(40, true, "*Seven Segment"); oapi::Font* font3 = oapiCreateFont(-11, true, "Arial");

NO errors. but when I run it the font is wrong
 

jarmonik

Well-known member
Orbiter Contributor
Addon Developer
Beta Tester
Joined
Mar 28, 2008
Messages
2,330
Reaction score
376
Points
83
Website
users.kymp.net
void Atlantis::clbkPostCreation () { oapi::Font* font1 = oapiCreateFont(50, true, "*Seven Segment"); oapi::Font* font2 = oapiCreateFont(40, true, "*Seven Segment"); oapi::Font* font3 = oapiCreateFont(-11, true, "Arial");
Here you assign the fonts to a local variables/pointers those doesn't exists beyond the clbkPostCreation();

It's supposed to be like this:

C++:
void Atlantis::clbkPostCreation ()
{
    font1 = oapiCreateFont(50, true, "*Seven Segment");
    font2 = oapiCreateFont(40, true, "*Seven Segment");
    font3 = oapiCreateFont(-11, true, "Arial");
    ...
}

Have you considered buying a book about C++ programming.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
6,696
Reaction score
956
Points
203
Location
Dallas, TX
Thanks.
That worked. I started add them back
Now I get causes it to lock up nothing in the log:
000000.000: D3D9: [Scene Initialized] 000000.000: Finished initialising panels 000032.877: D3D9: [Session Closed. Scene deleted.] 000032.877: D3D9: [Destroy Render Window Called] D3D9: ERROR: [Failed to Reset DirectX Device] (Likely blocked by undeleted resources) 000032.877: **** Closing simulation session
 
Last edited:

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
6,696
Reaction score
956
Points
203
Location
Dallas, TX
Thanks. I think i got her to work no ctd the log entry is this:
000000.000: D3D9: [Scene Initialized] 000000.000: Finished initialising panels 000003.195: D3D9: [Session Closed. Scene deleted.] 000003.195: D3D9: [Destroy Render Window Called] D3D9: ERROR: [Failed to Reset DirectX Device] (Likely blocked by undeleted resources) 000003.195: **** Closing simulation session
 
Top