LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

"...handle is invalid" : Error only when closing the Application, at RunTime everything seems fine...

Solved!
Go to solution

HI,

 

first of all: I'm relatively new to LabWindows, working on it during some practical work as a Student

(yeah, and sorry for the bad english, I'm from Germany)

 

To the Problem:

 

The first important Information:

 

After having searched for a solution, I just don't know, what to do,

My Project consists of ONE Main.uir-File with a Tab, a "Main.c" that basically handles the main .uir-Stuff and some Initiating-Stuff and in addition to that Several Sub-Sourc-Files, one for each Tab-Panel of the Main.uir-Tab.

To use the UI-Items on the Main-Tab with the Sub-Sources, I am initiating Tab-Handles at startup, that can be used by the SubSource-Files, like:

 

GetPanelHandleFromTabPage (PANEL, PANEL_TAB, 2, &BALU);

 

With this Handle, I can identify every UI-Items, when working with the SubSources

 

The second important information:

 

In some of the TabPages of the .uir there are several ControlArrays. To use them I create a ControlArrayHandle, like:

 

MWSAverageHandle  = GetCtrlArrayFromResourceID (BALU, MWSAverageArray);

No, I am able to identify specific elements of the Arrays, like:

 

SetCtrlVal (BALU, GetCtrlArrayItem (MWSProgressHandle, ActiveBalun), ProgressString);

Now there is a Problem, I am not able to solve:

 

During runtime, everything works out fine, I can use every element of a ControlArray with this ControlArrayHandle ("MWSProgressHandle"), everything works perfect, no errors at all. BUT, when closing the programm, I get the following error-message:

 

NON-FATAL RUN-TIME ERROR:   "Baluns.c", line 313, col 16, thread id 0x00000AB8:  

Library function error (return value == -4 [0xfffffffc]). Panel, menu bar, or control array handle is invalid

 

But this seems somehow ridiulous to me, because at runtime every single line works perfect, every Array-Item can be used without Problems...

 

Is there anything I am just not able to see???

 

Thanks a lot for your help.

 

Greeting from Lübeck, Germany!

Mathias

 

 

 

 

0 Kudos
Message 1 of 13
(7,535 Views)

Hi Mathias,

 

it might help to also tell us line 313 of your code, the one giving the error,

 

Wolfgang

0 Kudos
Message 2 of 13
(7,530 Views)

ahh yeah, forgot that:

 

The lines that cause the errors, are like the following type:

 

SetCtrlVal (BALU, GetCtrlArrayItem (MWSProgressHandle, ActiveBalun), ProgressString);

and here, the error is caused specifically by:

 

GetCtrlArrayItem (MWSProgressHandle, ActiveBalun);

So when I am not "breaking" in debugging-mode but "continueing", the error will occurr in every line, that contains the GetCtrlArrayItem-function

0 Kudos
Message 3 of 13
(7,527 Views)

Hi,

 

in your first message you wrote that you receive the error message when closing the program... do you discard any panel / control when shutting down your program? From your invalid panel error I would suspect that you first discard your panel and then attempt to use MWSProgressHandle...

 

0 Kudos
Message 4 of 13
(7,517 Views)

You said that this happens when you want to close your application; it is uncommon that you want to populate a control while closing the app: may it happen that the handle and/or the control array have already been discarded when you reach this line of code?

Is this code in a callback function? In this case, which event are you handling in the moment of error?

Have you tried breaking the code and looking at the handle in the variable window or the watch window to see if it has the correct value?



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?
0 Kudos
Message 5 of 13
(7,516 Views)

Maybe I just figured something out:

 

First of all, most of the Functions, that cause the Error, are in Timer-Callbacks (at this state of development, ALL of them)

So I just added a Test-Function in a normal Button-Callback, which contains a "GetCtrlArrayItem"-Function, and this specific Line does NOT cause an Error... (Or at least it does not occur in the Error-List, when clicking "continue" in debugging-mode). Somehow the Timer-Callbacks seem to be called, when closing the Application...

 

BUT: this happens when I don't do anything in the Application, and the all Timers are Disabled, until some Buttons are pushed (so when I close the application right after opening it, they still should be disabled) 

 

@ Wolfgang:

 

After discarding I do not want to use one of the handles, or at least I'm not doing that purposely

 

@ Roberto:

 

Actually I am only discaring the MainPanel-Handle in the Main.uir (and one other Panel, but the error occurred before implementing that other panel). Do all Handles (PanelHandles as well as ControlArrayHandles, TabPageHandles and so on) need to be discarded?

 

And no, I did not check the Variable Window, I was not aware of this possibility, I will try to figure that out.

 

0 Kudos
Message 6 of 13
(7,510 Views)
Solution
Accepted by MacMatze

In your timer callback, do you check for ( event == EVENT_TIMER_TICK ) ? Callbacks might get called for various events, not just the one you have in mind...

0 Kudos
Message 7 of 13
(7,505 Views)

yeah, well.... Thanks a lot!

I totally got used to, that CVI creates the switch-cases automatically, unfortunately it does not so with Timer-Callbacks, that solved it!!!

 

Thanks again!!! 🙂

0 Kudos
Message 8 of 13
(7,500 Views)

You're welcome!

0 Kudos
Message 9 of 13
(7,497 Views)

Mathias,

 

When CVI generates the callback function skeleton, it only generates the switch statement if, in your default event preferences, you have at least one event that is applicable to that type of control.

 

The way you select the default events is by clicking Code>>Preferences>>Default Events in the UI Editor window.

 

For timer controls, you should make sure that you have EVENT_TIMER_TICK selected:

 

events.png

0 Kudos
Message 10 of 13
(7,491 Views)