LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Second Thread running under RunUserInterface generates sporadic GPF

I have built an application that curently uses one main thread the does ProcessSystemEvents in a loop for 5 panels and a secondary thread that loads a panel and runs under RunUserInterface, processing the events only  for one panel.
From time to time the secondary thread creates a General protection fault.  After a very long testing i found out what was the reason for that. One of the panels from the main thread is displayed shortly at the beginning of the application and afterwards it is discarded . It seems that this discarding a panel from the main thread somehow affects the panelHandle of the panel that runs in the second thread. I looked at the values of the panelHandles for all panels and they do not overlap. If i comment out the DiscardPanel and add a HidePanel the application never crashes but still the panel that should be hidden is still on  the screen. This strange behavior doesn't occurr all the time.
 
Does anyone have a solution to this problem?
 
System was running under WinXP SP2 with CVI 8.5.
 
 
0 Kudos
Message 1 of 20
(5,141 Views)
Hi Danut81,

A few rules to remember when working with panels and multiple threads include the following:

- You must discard a panel in the same thread in which you load or create it
- Before a thread terminates, explicitly discard all panels you loaded or created in that thread.
- If you create a child panel, you must do so in the same thread in which you create or load the top-level panel.

Now my first question of course is if you are following those rules. If so and you are still getting those GPFs, I would ask the following questions:

1) Can you provide a screenshot of the GPF error message?
2) Are you loading any panels in your main thread that are parent panels to panels in your secondary thread? Basically I just want to know what relationship there is between the panel you discard in the main UI thread and the panel in the secondary thread that calls DiscardPanel. The reason I am asking this is because if you discard the parent panel in the main thread, then your child panels should also be discarded. Thus if you then try and discard the child panel again, you would most likely receive an error since that panel doesn't exist anymore. This may not be the case, but just wanted to throw that out there.
3) Is the address you see in the GPF message the same ever time you receive a GPF?
4) Would it be possible to post a small application that demonstrates this GPF?
5) If you can't post code, maybe showing some pseudo-code of your application flow?

Best Regards,
Jonathan N.
National Instruments
0 Kudos
Message 2 of 20
(5,103 Views)

First of all thank you for the reply.

 

I will answer to your questions now:

 

The rules you mentioned at first are in use meaning that the panels are loaded and discraded in the same thread where they were created.

Regarding any child -parent relationships between the panels i have no such panels defined. This will answer to question number (2) also.

(1) Please see attachment called gpf.bmp.

Also Debug1 contains the code that generated the gpf (an attempt to read from address D9016936 with it's out of the addressable space for the process)

and Debug2  to see the calling function for the code that generated the GPF.

(3) Yes the address is every time the same.

(4) Unfortunately it is very difficult for me to post here the application.

(5) See attachment in the next reply called Flow.jpg

0 Kudos
Message 3 of 20
(5,085 Views)
additional attachments:
Download All
0 Kudos
Message 4 of 20
(5,085 Views)

The GPF message box identifies line 575 of interface.c as causing the problem - can you post a bit of the code around this area? It might show something interesting, or at least provoke some more questions.

JR

0 Kudos
Message 5 of 20
(5,074 Views)
code of the thread function:
 
 iLogPanelHandle = LoadPanel (0, "AppLog.uir", PANELLOG);
 DisplayPanel(iLogPanelHandle);
 SetBreakOnLibraryErrors (0);
 MakeDir(szLogDir);
 SetBreakOnLibraryErrors (1);
 RunUserInterface();               line 575  . Here it crashes
 DiscardPanel(iLogPanelHandle);
 iLogPanelHandle = 0;
0 Kudos
Message 6 of 20
(5,072 Views)
Hi Danut81,

Do any of your panels have tab controls?

When you select Break upon receiving that GPF, can you go to Run >> Threads and tell me for each thread, what function it is currently at?

Best Regards,
Jonathan N.
National Instruments
0 Kudos
Message 7 of 20
(5,019 Views)
Hi,
 
No tab controls are used on my panel. i only have a listbox  a textbox and a few buttons.
 
When the gpf occurs in the secondary thread i'm in RunUserInterface, in the main thread unfortunately the main function is encapsulated in a static library and i do not have access to that part of the code. But with an external debuger i founf myself in call of EnterCriticalSection (KERNEL32.EnterCriticalSection  -> ntdll.RtlEnterCriticalSection) made by cvirte.dll at address: 68504AA6.
 
 
0 Kudos
Message 8 of 20
(5,008 Views)

Finally i managed to remove a very big part of the project and only to keep the parts where it still generates GPF.

I modified the main function in such way that the code runs only one time.

You must try to run a few times (sometime i run about 20 times) until it generates the GPF.

See attachment

 

0 Kudos
Message 9 of 20
(4,953 Views)
I add some aditional information i recently discovered.
 
It seems that the root cause at first is DisplayPanel function. When GPF is generated although the the function DisplayPanel returns 0 as OK the panel is not displayed.
If DiscardPanel function will be called for that panel handle the GPF will occur when main thread reaches ProcessSystemEvents(). If DiscardPanel will not be called, the panel will stil not be displayed but the application no longer crashes.
 
I 've did some tests removing the DisplayPanel from the main thread and the application never crashed.
 
If someone has some suggestion how should i continue please post.
0 Kudos
Message 10 of 20
(4,918 Views)