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.

Unhandled Exception when Using Execute Calculator Code

Featured Replies

  • Commercial Member

Anyone have an any insight into this error?Unhandled exception at 0x20b3e12e in fsx.exe: 0xC0000005: Access violation reading location 0x00000000.I have a block of code that triggers a bunch of Execute Calculator Code commands in sequence with a one second delay between each event. The section runs in its own separate thread (not sure if that's somehow a factor).Note that I'm writing, not reading stuff with these commands.execute_calculator_code("1 (>L:Blah1,bool)",NULL,NULL,NULL);*1 second delay*execute_calculator_code("1 (>L:Blah2 ,bool)",NULL,NULL,NULL);*1 second delay*execute_calculator_code("1 (>L:Blah3,bool)",NULL,NULL,NULL);*1 second delay*execute_calculator_code("1 (>L:Blah4 ,bool)",NULL,NULL,NULL);and so on all the way down to Blah10...The debugger in VS2008 always point to one of these Execute Calculator Code commands.The weird thing is that it doesn't point to the same one everytime.It's "random" as to which one will trigger the exception.Any ideas?Cheers,

Are you calling execute_calculator_code() anywhere else than in that thread?

Gerry Howard

Yes, but they're not called at the same time. Cheers,
What are you using to prevent them being called at the same time - semaphores, signals...?

Gerry Howard

  • Author
  • Commercial Member

It's definitely the thread that's causing the issue.I took the block of code that contains the execute calc code out of the separate thread and put it in the main (regular) section, and no more crashes.However, I'd really like to keep the Exec Calc Code stuff in a separate thread. Is there anyway of bullet proofing it somehow to prevent this odd crash?

What are you using to prevent them being called at the same time - semaphores, signals...?
Here's what the code looks like.... note I had to hide the L VAR names to protect the innocent :-)SafeSleep produces a pause of 1 second...if ( setup_cold_and_dark == 1) { if (Safe_Sleep(1000) != 0){return;} // MUTE BUTTON ON execute_calculator_code("1 (>L:XXXX,bool)",NULL,NULL,NULL); if (Safe_Sleep(1000) != 0){return;} execute_calculator_code("1 (>L:XXXXX,bool)",NULL,NULL,NULL); if (Safe_Sleep(1000) != 0){return;} execute_calculator_code("0 (>L:XXXXX,bool)",NULL,NULL,NULL); ... and so on

You could try using critical Section objects which can only be used by one thread at a time. This is perhaps(?) the simplest way but not necessarily the most effective depending on the application. Also, I think the function Sleep() which suspends the thread would be for efficient than your loop. I've only used threads in BorlandC++ Builder which provides wrappers for the Win API so there is the usual health warning.// Declare GLOBALLYCRITICAL_SECTION cs;// Called during initialisationInitializeCriticalSection(&cs);// In Thread 1...EnterCriticalSection(&cs);// Code to be protectedLeaveCriticalSection(&cs);// In Thread 2....EnterCriticalSection(&cs);// Code to be protectedLeaveCriticalSection(&cs);// Called during finalisationDeleteCriticalSection(&cs)

Gerry Howard

  • Commercial Member

Using critical sections has one drawback: It literally suspends access to the program's memory (code/data) for everything else except that thread while locked. If your thread has timing issues... it's going to show up in the primary thread as stutters and pauses.

Ed Wilson

Mindstar Aviation
My Playland - I69

Using critical sections has one drawback: It literally suspends access to the program's memory (code/data) for everything else except that thread while locked. If your thread has timing issues... it's going to show up in the primary thread as stutters and pauses.
Can you clarify? Do you mean, for example, that if a process has 3 threads and Thread 1 is in a critical section and Thread 2 is suspended waiting for the critical section that Thread 3 has no access to the program's memory?

Gerry Howard

  • Commercial Member
Can you clarify? Do you mean, for example, that if a process has 3 threads and Thread 1 is in a critical section and Thread 2 is suspended waiting for the critical section that Thread 3 has no access to the program's memory?
In essence, correct. A critical lock will suspend other process threads until it's removed.

Ed Wilson

Mindstar Aviation
My Playland - I69

In essence, correct. A critical lock will suspend other process threads until it's removed.
I don't understand. According to Microsoft:"When a critical section object is owned, the only other threads affected are the threads that are waiting for ownership in a call to EnterCriticalSection. Threads that are not waiting are free to continue running."http://msdn.microsoft.com/en-us/library/ms682530(VS.85).aspx

Gerry Howard

  • Commercial Member

Send me one year's worth of tuition fees for computer programming and I'll be more than happy to educate. Seriously.I know what the EnterCriticalSection does and what can go seriously wrong if you don't release it. Try it sometime. See how the main thread likes that.But then, you're using the Borland threading system... which isn't actually the proper method of using threads. It actually cheats.

Ed Wilson

Mindstar Aviation
My Playland - I69

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.