Jump to content
Sign in to follow this  
Guest Patrick_Waugh

Possible FS X bugs causing CTDs

Recommended Posts

Guest Patrick_Waugh

Hey all,We may have identified some bugs.This code:wstring RadioPage::GetAdf1Active(){ FLOAT64 freq; WCHAR freqStr[7] = {0}; execute_calculator_code("(A:ADF ACTIVE FREQUENCY:1, KHz)", &freq, NULL, NULL); swprintf_s(freqStr, 6, L"%06.1f", freq); return freqStr;}crashes FS X. At first, I suspected it was our code, but it seems Bill Learning has been able to replicate it, and has similar problems:

This works just fine in a simple N-Registration gauge used in both FS9 and FSX:case PANEL_SERVICE_PRE_UPDATE: execute_calculator_code("(A:atc id, string)",NULL,NULL,&n_number);break;However, this causes FSX to crash while loading:execute_calculator_code("(A:ADF ACTIVE FREQUENCY:1, KHz)",&adf1_frequency,NULL,NULL);as does this:execute_calculator_code("(A:atc flight number,string)",NULL,NULL,&atc_flight_number);
Just wanted to post this so MS might see it.

Share this post


Link to post
Share on other sites
Guest JeanLuc_

Well the declaration of the function is:BOOL (FSAPI *format_calculator_string) (PSTRINGZ result, UINT32 resultsize, PCSTRINGZ format);a PCSTRINGZ is not a WCHAR* at all.Could this be the nature of the problem if your project settings are set to wide char? if so, I suspect any "xxxx" is a wide char string, not a char string in you code.

Share this post


Link to post
Share on other sites

Actually, the prototype declaration is:BOOL (FSAPI *execute_calculator_code) (PCSTRINGZ code, FLOAT64* fvalue, SINT32* ivalue, PCSTRINGZ* svalue);In the case of the atc_id, note the following:PCSTRINGZ atc_flight_number; execute_calculator_code("(A:atc flight number,string)",NULL,NULL,&atc_flight_number);swprintf(buf,L"%S", atc_flight_number);Clearly, there isn't a problem with this, yet it crashes FSX. Commenting out the second line eliminates the crash...In the case of the ADF frequency:FLOAT64 adf1_frequency = 0;execute_calculator_code("(A:ADF ACTIVE FREQUENCY:1, KHz)",&adf1_frequency,NULL,NULL);The same applies to the following as the above. Clearly the variable is constructed per the prototype.Completely aside from which... this exact same code works in FS9 with no problems whatsoever.


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites
Guest Patrick_Waugh

Thanks for pointing that out, I had overlooked this, and it explains something else I was dealing with, however, as Bill points out below there is still a problem.I'll look at this again, but I am thinking that I can't get to the ADF2 freq due to that macro crashing FS X.

Share this post


Link to post
Share on other sites

>Actually, the prototype declaration is:>>BOOL (FSAPI *execute_calculator_code) (PCSTRINGZ code,>FLOAT64* fvalue, SINT32* ivalue, PCSTRINGZ* svalue);>>In the case of the atc_id, note the following:>>PCSTRINGZ atc_flight_number; >execute_calculator_code("(A:atc flight>number,string)",NULL,NULL,&atc_flight_number);>swprintf(buf,L"%S", atc_flight_number);>>Clearly, there isn't a problem with this, yet it crashes FSX. >Commenting out the second line eliminates the crash...>This is crashing because FSX is returning a NULL pointer. Change your code to this:execute_calculator_code("(A:atc flight number,string)",NULL,NULL,&atc_flight_number);if (atc_flight_number){ swprintf(buf,L"%S", atc_flight_number);}else{// clear the buf here so nothing displays swprintf(buf,L"%S", "");}That will at least prevent the crash.


Ed Wilson

Mindstar Aviation
My Playland - I69

Share this post


Link to post
Share on other sites
Guest Patrick_Waugh

Ok, I tried this:wstring RadioPage::GetAdf1Active(){ FLOAT64 freq; WCHAR freqStr[10] = {0}; execute_calculator_code("(A:ADF ACTIVE FREQUENCY:1, KHz)", &freq, NULL, NULL); if(freq) { swprintf_s(freqStr, 6, L"%06.1f", freq); return freqStr; } else { return L""; }}and it still crashes FS9 or FS X. So, I'm thinking this is a bug. Those are not wide-charaters (that would be L"(A:ADF ...)".What surprises me is that I can't get it to work even in FS9.Any ideas?

Share this post


Link to post
Share on other sites

Patrick,As noted in the FSDeveloper Forum,The A:ADF ACTIVE FREQUENCY:1 variable is not immediately available on aircraft load. You can either check for the passage of sim time before asking for this variable, or you can wrap it in an if statement: if ( execute_calculator_code("(A:ADF ACTIVE FREQUENCY:1, KHz)", &freq, NULL, NULL)) {} else freq = -1;Doug

Share this post


Link to post
Share on other sites
Guest Patrick_Waugh

Doug,>As noted in the FSDeveloper Forum,>The A:ADF ACTIVE FREQUENCY:1 variable is not immediately>available on aircraft load. You can either check for the>passage of sim time before asking for this variable, or you>can wrap it in an if statement:>> if ( execute_calculator_code("(A:ADF ACTIVE FREQUENCY:1,>KHz)", &freq, NULL, NULL))> {}> else freq = -1;Yes, as I posted there, this didn't fix it. FS 9 and FS X still crash on the execute_calculator_code.The only thing I can think of that is wrong now is the .h I'm using.

Share this post


Link to post
Share on other sites
Guest Patrick_Waugh

The .h is not the problem, as I compiled with the old known good .h and it crashes too.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...