LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

General protection fault with tabs and toolbars on application exit

Solved!
Go to solution

Hi,

 

It seems that if you have a tab control

...and that tab control has a tab with a child panel 

...and that child panel has a panel callback function

...and that same child panel also has a toolbar

...and you don't discard the toolbar when the application exits

...and you don't discard the child panel when the application exits

...and you don't discard the panel with the tab control when the application exits

...the application will crash with a general protection fault after the main function returns.Smiley Surprised

 

Granted, I don't really consider this a bug so much as there was several things wrong with the code I was working with in order to hit this (and once I fixed the application everything was fine), but this still took me a bit of time to track down, so hopefully this post may save someone else some time in the future.

 

I've attached a small sample application that shows this issue on my PC in case an NI engineer wants to take a look at it.  I'm running CVI 2012 SP1 on Windows 7 64-bit.  Thanks.

0 Kudos
Message 1 of 5
(3,237 Views)

Having taken a look at your sample code, I found that using InstallPanelCallback to install the callback on the child panel instead of ChainPanelCallback solves the issue.

One possible cause of problems when using panel/control chaining functions is when some code alters panel/control callbackData value: now you are installing the toolbar on the panel, which is likely to manipulate panel callbackData parameter; unfortunately tollbar instrument is not distributed with source code.

 

If you effectively need in actual application to use ChainPanelCallback there are 2 workarounds that can avoid that type of error: installing the toolbar on the tab page instead of the child panel or chaining the callback after installing the toolbar. Both solutions permit clean program termination.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 5
(3,223 Views)
Solution
Accepted by topic author tstanley

I see I was a bit involuted in my previous answer. To be telegraphic and hopefully more clear:

 

  • As stated in the help, after chaining the callback function to the panel, panel callbackData must not be modified
  • (solution 1) If you simply install a callback instead of chaining a new one this problem is not present
  • I suspect that the toolbar instrument manipulates panel callbackData parameter; if this is true, you can either:
  • Install the toolbar to a panel that hasn't a callback chained (workaround 1), or
  • Install the toolbar BEFORE chaining the callback (workaround 2): as you can see in the code for ChainPanelCallback, the instrument takes care of existing callbackData and properly handle it in all situations, including panel discard


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 3 of 5
(3,218 Views)

I see what you're saying.  In the sample code I posted, obviously chaining the callback to a panel I just created using NewPanel is rather silly, but in my application I'm loading panels out of .uir files and some of them already have callbacks.  Obviously I have some more work to do to make sure everything gets sorted out properly.  Thanks for the insights.

0 Kudos
Message 4 of 5
(3,190 Views)

Looking at what's going on, at least in the toolbar.c file from CVI 7.1 (later versions of the instrument I have access to don't include the source) it looks like that toolbar instrument creates a threadsafe variable, which it then frees upon the application exit using a callback function that was set up earlier using the atexit(...) function.  After this happens, the callback functions for the toolbar panel get called with the EVENT_DISCARD event, and when it tries to get the pointer to the threadsafe variable it instead gets a null pointer which causes the general protection fault when it tries to use it (the function does not check for NULL first).  If the panel is discarded before the application exit, this calls the toolbar panel callback functions when the threadsafe variable is still valid and everything is okay.  At least this is my interpetation of what's happening, based upon a much older version of the instrument.  I also don't see any place where the toolbar library is changing the panel's callback data, but once again this is an old version of the library.

0 Kudos
Message 5 of 5
(3,160 Views)