Skip to content
View in the app

A better way to browse. Learn more.

The AVSIM Community

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

GDI+ Cleanup Question

Featured Replies

  • Commercial Member

I've just recently started using GDI+ for a gauge. About 50% of the times, when I exit the simulator (in which the gauge works fine), I get a message about an unhandled exception in FS9.exe. Obviously, this is my gauge misbehaving, and I'm assuming it's something during cleanup. So 3 questions:----> Question 1. Is there anything more the following that needs to be done in order to properly clean up after using GDI+ functions?case PANEL_SERVICE_PRE_KILL:if (gdiPlusInitialized){ GdiplusShutdown(gdiplusToken); gdiPlusInitialized = false;}----> Question 2. I re-use quite a few variables, for example, in one case I declare an item:RectF clipRectF; // declare oncethen use this variable many times like this:clipRectF = RectF(...parameteres...);then later:clipRectF = RectF(...differentparameters...);Is this OK? Or am I leaking memory by doing this? Do these GDI+ objects need to be cleaned up afterwards in any way like we used to have to do in plain GDI32 with "DeleteObject", or is cleanup automatic?----> Question 3: Does the graphics.Dispose method need to be called? I've never seen this in any gauge examples, but it's in all the GDI+ examples in my book.

Hi,on question 1: That's basically OK, but it's better if you move GdiplusStartup() to PANEL_SERVICE_CONNECT_TO_WINDOW and GdiplusShutdown() to PANEL_SERVICE_DISCONNECT so GDI+ is initialized only when the panel is loading and not everytime you switch between windowed and full screen mode. It's not a problem though.on question 2:you don't leak any memory by using a variable like this. A cleanup is only necessary if you use pointers: RectF *clipRectF = new RectF(...) must always be followed by delete clipRectF since the Managed Extensions for C++ (in VS.NET) are not available in gauges.Hope that helps.

  • Commercial Member

Thanks....I was pretty sure I was safe there since I wasn't using a pointer, but 10 years into C++ and I still screw 'em up!Still doesn't help explain the occasional unhandled exception....and I'm not even sure if "real people" would see the exception, or if it's only visible to me due to the presence of the development environment on my machine.

Same here. 23 years into programming and you wouldn't believe how many stupid errors I make :-DI have no idea about that exception. Does it come up at a certain point? For example when unloading the aircraft?

  • Commercial Member

Geeeeeez, I found it, nevermind. I guess I have to admit that this was a stupid one too. I had totally forgotten that I was allocating some memory for a test string, but I never freed the pointer. And dummy me, I was allocating it at the top of the callback, not inside the deisred case, so it was getting allocated hundreds of times more than necessary, and never released.Funny, I was all worried about a memory leak with the way I was using GDI, and as it turns out, it was a memory leak using the most simplistic of pointers. Yikes, I must have been programming when I should have been getting some sleep!

  • Commercial Member

The frequency of the fs9.exe unhandled exception (during aircraft unload and/or simulator shutdown) error was reduced by my pointer correction, but hadn't gone completely away until I did as you had suggested, moving the GDI startup code into PANEL_SERVICE_CONNECT_TO_WINDOW and the shutdown code into PANEL_SERVICE_DISCONNECT. We'll see if that holds true, but for now, I've started and shutdown 50-60 times, and no crash.

  • Moderator

>The frequency of the fs9.exe unhandled exception (during>aircraft unload and/or simulator shutdown) error was reduced>by my pointer correction, but hadn't gone completely away>until I did as you had suggested, moving the GDI startup code>into PANEL_SERVICE_CONNECT_TO_WINDOW and the shutdown code>into PANEL_SERVICE_DISCONNECT. >>We'll see if that holds true, but for now, I've started and>shutdown 50-60 times, and no crash.Interesting, to say the least. I've never experienced any problems whatever with starting GDI+ from here:void FSAPI DF_gaugecall(PGAUGEHDR pgauge, int service_id, UINT32 extra_data){ if(!init_digitrack) { GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); init_digitrack = true; }nor have I experienced any problems with using PRE_KILL for shutdown...Perhaps I've just been lucky... ;)But, I'll certainly bow to Hans on this matter, and amend my wayward ways! *:-*

Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Bill,There's absolutely no problem in using POST_INSTALL/PRE_KILL. The only disadvantage is that it's called every time the FS windows is resized. If you use CONNECT/DISCONNECT this happens only once when the gauge is loaded. It's nothing more than a matter of efficiency and not really important.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.