LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Library error with toolbar custom control when not in the main thread?

Solved!
Go to solution

Hi,

 

I'm having a problem with a Library function error -129 at an unknown source position when I'm trying to use the toolbar custom control library (toolbar.fp) when not in the main thread.  I basically have another thread that is created, loads a panel, adds a toolbar, displays the panel, and calls RunUserInterface().  When QuitUserInterface() is called in the thread, it discards the toolbar (with no error) and the thread terminates.  When I exit the application, I then get the Library function error -129 at the unknown location (this is after the main function returns).  I don't know if it's related, but the Resource Tracker also indicates that Toolbar_New() created a a panel that had not been freed.  Any ideas?  Am I doing something incorrectly here?  The help for the toolbar custom control library says it is a multithreaded safe.

 

I've attached a small project that shows the problems I'm having.  I'm using CVI 2010 SP1.

 

Thanks. 

0 Kudos
Message 1 of 4
(3,352 Views)

Hi tstanley,

 

I found an explaination in one of our internal sources. According to this article "the problem was that the thread in which the error was being thrown was not the main thread where the panel was created. A panel or control can only be accessed in the thread it was created in and therefore can not be manipulated or called from a seperate thread".

 

It looks like there is a multithreading issue here even though your toolbar custom control library is multithreaded safe.

 

I hope this helps.

 

Josh L.

Applications Engineer
National Instruments
0 Kudos
Message 2 of 4
(3,332 Views)
Solution
Accepted by topic author tstanley

Hi Tstanley,

 

Josh is right. This is a multithreading issue. I dug through the code of toolbar and found that we attempt to discard data belonging to the toolbar upon exiting the main thread. This is a problem because this data was created by Toolbar_New in your second thread and Toolbar_Discard (toolbar) doesn't discard this data. The main thread does not have access to this data and thus throws an non-fatal run-time error. Since this data is failing to be discarded upon exit, it will be freed anyway when you application finishes exiting.

 

So unless your toolbar is part of a DLL then it should not be a problem. And if it is part of a DLL, then it is only a small memory leak. We are going to fix this for a future release of CVI, but in the meantime, your application should not have any ill effects and we can easily hide this error.

 

On the last line of main() before you return, call SetBreakOnLibraryErrors (0);. This will hide the non-fatal run-time errors for that thread.

National Instruments
0 Kudos
Message 3 of 4
(3,327 Views)

Hi,

 

Thanks for looking into this.  Since it's nothing serious, for now I'll just use the work around you suggested and await the fix in the next release of CVI. 

0 Kudos
Message 4 of 4
(3,314 Views)