June 24, 200322 yr Hi, Has anyone had any great success with running two different gdi+ gauges at the same time? If so where and how often did you put the gdi+ startup and shutdown gauges. Arne is already on this one but I wanted to see if other people had any opinions.ThanksJon
June 25, 200322 yr Hey Jon.Yes, Ettiene and I are building two gauges at the same time, the PFD and the MFD. Each is a separate gauge file, and both have the startup of GDI+ in CONNECT_TO_WINDOW and the shutdown in DISCONNECT.They work fine for us, and you can go to our forum to spy on them if you'd like, I posted some pics a little bit ago.
June 25, 200322 yr If you want to put two GDI+ gauges into the same gauge file, you have to call the startup and shutdown functions only once. The best place is the callback function of the *first* GDI+ gauge in your file. Use CONNECT_TO_WINDOW and DISCONNECT, just as Fabio said above.EDIT: There's no problem when the GdiPlusShutdown() function is called in the first GDI+ gauge because all other gauge are in the DISCONNECT phase too at that time and won't try to repaint themselves.
June 25, 200322 yr Linkage table have links to module_init() and module_deinit() functionsSo I put startup and shutdown calls to these functions and all works fine without concerning how many gauges there and which is first
June 25, 200322 yr Hans,I did exactly what you said in my intial attempt but got no luck. Any other ideas?ThanksJon
June 25, 200322 yr i have seen these functions in the gauges.h file but im not sure where to put them although Im guessing just by the name that they are called in similar fashion to panel connect and disconnect. Perhaps you can shed some light on this for me.
June 26, 200322 yr Look:#define GAUGE_TABLE_BEGIN() extern GAUGEHDR gauge_header; void FSAPI module_init(void){} void FSAPI module_deinit(void){} In stock gauges.h module_init and deinit soes nothingYou are free to add something between {}Like this:void FSAPI module_init(void) {GdiplusStartup(&token, &input, NULL); } void FSAPI module_deinit(void) {GdiplusShutdown (token);} token and input are global variablesdon't forget include required headers there :)
June 26, 200322 yr after I click the "FLY NOW" button, the loading screen comes up but nothing loads. It just sits there until I force it to exit. Then it says the cause of the problem is gdiplus.dll. I didn't have this problem when it was just my one gauge though. A few other things that may affect it are that A: I have used static for just about everythingB: I placed ULONG_PTR token variable in the main .cpp file and in the gauge .cpp file with out any change.Both gauges call rendering functions instead of drawing straight from the pre draw routine. Anyway There is nothing ingenious in the code so I would be willing to show people who have an idea as to what could be wrong.ThanksJon
June 28, 200322 yr This test gauge works with two GDI+ gauges in the same maingauge (they are identical, just for test). No problem on my machine (AMD 2400+ W98SE) with using both subgauges (and even one multiple times) on the same panel. The module_..init() functions aren't touched, all initializations via the gauge callback. It made no difference if a "token" variable was globally,locally or static declared, or pgauge->user_data was used for GdiplusStartup/GdiplusShutdown.Arne Bartels
December 3, 200619 yr >Look:>>#define GAUGE_TABLE_BEGIN() > extern GAUGEHDR gauge_header; > void FSAPI module_init(void){} > void FSAPI module_deinit(void){} >>In stock gauges.h module_init and deinit soes nothing>You are free to add something between {}>>Like this:>>void FSAPI module_init(void) {GdiplusStartup(&token, &input,>NULL); } >void FSAPI module_deinit(void) {GdiplusShutdown (token);} >>token and input are global variables>>don't forget include required headers there :)How can you do this when all Gdiplus stuff is C++???? Are you using a .cpp main gauge file in your multi-gauge? Mine have always been .c, and therefore the above won't work as it is C++.Could you be more specific on how you are doing this? I've always had to have the one main file be .c.With this singleton, you can init GdiPlus, but you have to avoid the dreaded "order of initialization" problem by making sure you put the Instance() call in the right place.// GdiPlusManager.cpp//// Copyright © 2006 Benchmark Avionics Corporation. All rights reserved.#include "GdiPlusManager.h"namespace Helpers{ GDIPlusManager* GDIPlusManager::m_pInstance = 0; GDIPlusManager* GDIPlusManager::Instance() { if(m_pInstance == 0) m_pInstance = new GDIPlusManager(); return m_pInstance; } GDIPlusManager::GDIPlusManager() { gdiplusToken = 0; // Instantiate class to initialize GDI+ Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); } GDIPlusManager::~GDIPlusManager() { // Destructor will shutdown GDI+ when class goes out of scope on termination Gdiplus::GdiplusShutdown(gdiplusToken); }}
December 4, 200619 yr Moderator Seeing as how I'm a simple man, I seek out simple, universal solutions. The following allows me to not worry about gauge loading sequence, and creates ONE set of "drawing tools" that may be used by any GDI+ gauges that need 'em... ;)case PANEL_SERVICE_CONNECT_TO_WINDOW: gdiPlusUsers++; if(!init_gdiPlus) { GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); init_gdiPlus = true; } if(init_gdiPlus && !objects_created) { img_attr = new ImageAttributes(); CreateTools(); //create Pens, Brushes and Fonts bool objects_created = true; }break;case PANEL_SERVICE_DISCONNECT: gdiPlusUsers--; if (init_gdiPlus && gdiPlusUsers == 0) { GdiplusShutdown(gdiplusToken); init_gdiPlus = false; } if(objects_created) { DeleteTools(); //delete Pens, Brushes and Fonts objects_created = false; }break; Fr. Bill AOPA Member: 07141481 AARP Member: 3209010556 Avsim Board of Directors | Avsim Forums Moderator
December 5, 200619 yr Commercial Member The line "bool objects_created = true;" isn't a good thing. It defines the variable "objects_created" right at that point. It is not guaranteed to always have the correct value on each cycle.You would be better off declaring it in the main .h file for your gauge package. Ed Wilson Mindstar AviationMy Playland - I69
December 5, 200619 yr Moderator >The line "bool objects_created = true;" isn't a good thing. >It defines the variable "objects_created" right at that point.> It is not guaranteed to always have the correct value on each>cycle.>>You would be better off declaring it in the main .h file for>your gauge package.Ah! Quite right... moved now... Thanks for the quick eye, Ed! ;) Fr. Bill AOPA Member: 07141481 AARP Member: 3209010556 Avsim Board of Directors | Avsim Forums Moderator
December 5, 200619 yr That approach doesn't work when you are using statically created Gdi+ stuff instantiated in another object, which is why I had to deviate from it in the first place.But, no worries, my singleton class works fine.Really, I was trying to figure out why I couldn't compile the master .c file as .cpp, but as you know Bill from my email, something else was mucking that up and is solved.So, I could now use the mod_init thing if I wanted also.Again, good to see how others are doing things as options are always nice.The advantage to having static colors, pens, and brushes made it worthwhile for me to figure out how to do it.
Create an account or sign in to comment