Page 1 of 1

Red cross will be drawn sometimes

Posted: Mon Jun 25, 2012 10:05 am
by 15660558
I get a very unclear error.
Sometimes in a chart appears a red cross. The chart is running over a long time, but after hours or days the red cross will be drawn.
Theres is no exception, the software is still running, but the chart does not work after this red-cross-error.
It seems, that the chart will be drawn two times, one time on right position on the underlying tabcontrol, and one time it moved a little bit outside the tabcontrol.

Description of the chart:
The chart contains 5 fast line series and 1 point series. The fast lines series will be drawn only one time and will never be updated.
The point series will be updated every 3 seconds and includes only 1 point. The point will be deleted with .Clear() and then a new point will be added with .add(x, y).
The left axis is a logaritmic axis.

This is the code for the point update:

Code: Select all

series_PC_cross.Clear();
if ((MCR_RPM_min > 0) & (MCR_power_kW > 0))
{
   RPM_Percent = RPM / MCR_RPM_min * 100;
   kW_Percent = Power_kW / MCR_power_kW * 100;
   series_PC_cross.Add(RPM_Percent, kW_Percent);
}
The application runs over month on a few PCs without any error.
On 1 PC we get this error since last week.

Is it possible that the error will be caused outside the update procedure?

Re: Red cross will be drawn sometimes

Posted: Mon Jun 25, 2012 2:11 pm
by 15661493
This response is from a user, not Steema...

In Sub New in the main window in your program add handlers for the events shown below. Send the stack trace to a file when either fires. You will most likely see the type of error and the subroutine in TeeChart that caused it. With that info, Steema will be more easily able to troubleshoot it.

My solution is in VB.net, but C# should be an easy change.

Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf UnhandledExceptionEventRaised
AddHandler Application.ThreadException, AddressOf MYThreadHandler
End Sub

Protected Overrides Sub Finalize()
MyBase.Finalize()
RemoveHandler AppDomain.CurrentDomain.UnhandledException, AddressOf UnhandledExceptionEventRaised
RemoveHandler Application.ThreadException, AddressOf ThreadHandler
End Sub

Sub UnhandledExceptionEventRaised(ByVal sender As Object, ByVal e As UnhandledExceptionEventArgs)
If e.IsTerminating And ProgramTerminating = False Then
Dim o As Object = e.ExceptionObject
Dim msg As String = o.ToString.ToUpper
WriteErrorLog("Unhandled Exception - Program Is being terminated by Windows: " & vbCrLf & msg.ToString & vbCrLf & vbCrLf)
End If
End Sub

Private Sub ThreadHandler(ByVal sender As Object, ByVal e As Threading.ThreadExceptionEventArgs)
WriteErrorLog(e.Exception.StackTrace)
End Sub

This has proven very helpful to me in identifying such errors.

Re: Red cross will be drawn sometimes

Posted: Tue Jun 26, 2012 7:29 am
by 15660558
Thank you for your reply.
As I understand the procedures log unhandled exceptions, which will be displayed on screen and lead to the termination of the application.
In my case no exception will be thrown.
Is there a way to find out whether the TeeChart methods work correct/lead to internal errors?

Re: Red cross will be drawn sometimes

Posted: Wed Jun 27, 2012 3:27 pm
by 10050769
Hello Delphi,

The rendering of the Chart as a red cross normally means that an exception has occurred. The advice of DaveR might be a useful start approach to see if an error, though not outwardly apparent, is being generated. We could take a look at your project but you mention that the same application is working correctly on other pcs. Is the setup format (Winodws, CPU, memory) siilar on all machines? It may be (or may not) be a hardware error, it can't be ruled out at this stage.

Thanks,

Re: Red cross will be drawn sometimes

Posted: Thu Jun 28, 2012 7:21 am
by 15660558
Hello Sandra, hallo DavR,

thanks for your replys. I logged Threadexceptions now as DavR recommend and I got the following stack trace, a few times:

at System.Drawing.Graphics.FromHdcInternal(IntPtr hdc)
at System.Drawing.BufferedGraphicsContext.CreateBuffer(IntPtr src, Int32 offsetX, Int32 offsetY, Int32 width, Int32 height)
at System.Drawing.BufferedGraphicsContext.AllocBuffer(Graphics targetGraphics, IntPtr targetDC, Rectangle targetRectangle)
at System.Drawing.BufferedGraphicsContext.Allocate(IntPtr targetDC, Rectangle targetRectangle)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at DevExpress.Utils.Controls.ControlBase.WndProc(Message& m)
at DevExpress.XtraEditors.BaseEdit.WndProc(Message& m)
at DevExpress.XtraEditors.TextEdit.WndProc(Message& msg)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

I thing that this could have caused the error, but I'm not sure, because I did not saw when the error (red cross) occurred. I seems to me that another control 'TextEdit' has a relation to the error.
I have no more information at time.
The application works with a few threads.

Do you have any ideas or advices for me?

Many thanks

Re: Red cross will be drawn sometimes

Posted: Thu Jun 28, 2012 1:38 pm
by 15661493
When I have seen the TeeChart control throw an error, the stack trace usually includes references to the teechart object. In your case it is pointing to a different object, some DevExpress edit box or something. My first guess at the cause would be a cross threaded attempt to write text to a screen object. Confirm that you are on the GUI thread when you attempt to write text to the screen. If not, use Invoke or BeginInvoke.

In VB.Net you would declare a Delegate Sub in the declarations are of the code. Then your function would be a recursive call which checks that it is on the correct thread.

'This goes at the top of the class
Delegate Sub BasicStringDelegate(Msg as String)


Private Sub WriteTheText(Msg as String)
If Me.InvokeRequired Then
'We are not on the GUI Thread here. Call the function again, but on the right thread.
Me.Invoke(New BasicStringDelegate(AddressOf WriteTheText), New Object(){Msg})
Else
'We are on the right thread. Just assign the textbox.text.
TextBox.Text = Msg
End If

Re: Red cross will be drawn sometimes

Posted: Thu Jun 28, 2012 3:14 pm
by 15660558
Hello DaveR,

thanks for your help.

The problem is, I don't know whether the red-cross-error has a relation to the 'System.Drawing.Graphics.FromHdcInternal(IntPtr hdc)'-error (GDI-Error).
I searched for a possible reason for the red-cross-error and so I found - with your help - the GDI-error.
Last night the GDI-error occured many times, but not so the red-cross-error. But the teeChart-series was not be updated last night, maybe that was the reason.

Another question for my understanding: Why I see the GDI-error using the Application.ThreadException-event, in this way you descripted. Without the Application.ThreadException-event I have never seen this error before. I beleave that the error occured also before, but why in the background wihout any message? Do you have an explanation?

To the threads: I use in some cases delegates to write into text-controls in the way you wrote, because it was necessary. Other controls (e.g. even TextEdit) will be filled directly.
Do you think that it could possible, that the application runs 12hrs, every 3 seconds the controls will be filled without error, and after 12 hrs errors occure?
Would it be a good practice to fill ALL text-components with checking on InvokeRequired?

Re: Red cross will be drawn sometimes

Posted: Fri Jun 29, 2012 3:12 pm
by 15660558
Hello Sandra, hello DaveR,

I found a few TextEdit-controls which got data from another thread and I check they now with InvokeRequired etc.
The software is running now, after the weekend I will see the result.

@Sandra: How the teeChart series will re-act with date from another thread? In the code snippet RPM and Power_kW are from another thread.
Do I have to expect problems?

Have a nice weekend!

Delphi

Re: Red cross will be drawn sometimes

Posted: Fri Jun 29, 2012 5:37 pm
by 15661493
What I have found regarding writing to (or even reading from) the screen from a background thread is that it may work. The problem is, over time the system will slowly degrade and may ultimately fail. Even if such cross threaded ooperations appear to be working, one should really try to avoid them.

Re: Red cross will be drawn sometimes

Posted: Thu Jul 05, 2012 10:02 am
by 10050769
Hello DaveR and Delphi,
How the teeChart series will re-act with date from another thread? In the code snippet RPM and Power_kW are from another thread.
Do I have to expect problems?
I am not expert with multhreading, but you must know TeeChart isn't thread-safe and you should control it. For this reason, I recomend you taking a look in next threads, that can help you to avoid problems:

http://www.teechart.net/support/viewtop ... ing#p10982
http://www.teechart.net/support/viewtop ... 99&start=0
http://www.teechart.net/support/viewtop ... =threading
http://www.teechart.net/support/viewtop ... ing#p47454

If you still have problems, please try to arrange for us a simple project we run as-is, here and we can try to find a solution for you.

I hope will help.

Thanks,