PavelTorgashov / FastColoredTextBox

Fast Colored TextBox for Syntax Highlighting. The text editor component for .NET.
Other
1.21k stars 463 forks source link

[SQL] Entering BEGIN throws NullReference Exception #165

Closed Nikoshi closed 5 years ago

Nikoshi commented 5 years ago

Environment:

Steps to reproduce:

Expected result:

Actual result:

System.NullReferenceException
  HResult=0x80004003
  Message=Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
  Source=FastColoredTextBox
  StackTrace:
   at FastColoredTextBoxNS.FastColoredTextBox.DrawMarkers(PaintEventArgs e, Pen servicePen)
   at FastColoredTextBoxNS.FastColoredTextBox.OnPaint(PaintEventArgs e)
   at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
   at System.Windows.Forms.Control.WmPaint(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.UserControl.WndProc(Message& m)
   at FastColoredTextBoxNS.FastColoredTextBox.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Hexman768 commented 5 years ago

I was unable to recreate this issue, can you post some additional details (perhaps some of your code) so that I can get a better idea of what is causing this issue?

Nikoshi commented 5 years ago

I've created the textbox with the following properties and the only thing I do besides this is getting and setting the text.

Me.tbSQLCode.AutoCompleteBracketsList = New Char() {Global.Microsoft.VisualBasic.ChrW(40), Global.Microsoft.VisualBasic.ChrW(41), Global.Microsoft.VisualBasic.ChrW(123), Global.Microsoft.VisualBasic.ChrW(125), Global.Microsoft.VisualBasic.ChrW(91), Global.Microsoft.VisualBasic.ChrW(93), Global.Microsoft.VisualBasic.ChrW(34), Global.Microsoft.VisualBasic.ChrW(34), Global.Microsoft.VisualBasic.ChrW(39), Global.Microsoft.VisualBasic.ChrW(39)}
Me.tbSQLCode.AutoIndentCharsPatterns = ""
Me.tbSQLCode.AutoScrollMinSize = New System.Drawing.Size(27, 14)
Me.tbSQLCode.BackBrush = Nothing
Me.tbSQLCode.BackColor = System.Drawing.SystemColors.Control
Me.tbSQLCode.CharHeight = 14
Me.tbSQLCode.CharWidth = 8
Me.tbSQLCode.CommentPrefix = "--"
Me.tbSQLCode.Cursor = System.Windows.Forms.Cursors.IBeam
Me.tbSQLCode.DisabledColor = System.Drawing.Color.FromArgb(CType(CType(100, Byte), Integer), CType(CType(180, Byte), Integer), CType(CType(180, Byte), Integer), CType(CType(180, Byte), Integer))
Me.tbSQLCode.Dock = System.Windows.Forms.DockStyle.Fill
Me.tbSQLCode.IsReplaceMode = False
Me.tbSQLCode.LeftBracket = Global.Microsoft.VisualBasic.ChrW(40)
Me.tbSQLCode.Location = New System.Drawing.Point(0, 0)
Me.tbSQLCode.Name = "tbSQLCode"
Me.tbSQLCode.Paddings = New System.Windows.Forms.Padding(0)
Me.tbSQLCode.RightBracket = Global.Microsoft.VisualBasic.ChrW(41)
Me.tbSQLCode.SelectionColor = System.Drawing.Color.FromArgb(CType(CType(60, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(255, Byte), Integer))
Me.tbSQLCode.ServiceColors = Nothing
Me.tbSQLCode.Size = New System.Drawing.Size(537, 517)
Me.tbSQLCode.TabIndex = 40
Me.tbSQLCode.Zoom = 100
Hexman768 commented 5 years ago

From your error, it appears as though something is null and an NPE is being thrown but not handled anywhere. Do you happen to know what line is causing the exception to be thrown?

Nikoshi commented 5 years ago

Visual Studio is only showing the stacktrace which I have attached. It looks like the exception is thrown in FastColoredTextBox.DrawMarkers

Hexman768 commented 5 years ago

Alright, is this project hosted on your github account? I am unable to recreate this issue on the latest version of the component.

Nikoshi commented 5 years ago

Sorry the project is not hosted online, because it's an internal project.

Hexman768 commented 5 years ago

Gotcha, makes sense lol, sorry I asked, I'll have a look at the function and see what's getting nulled out.

Hexman768 commented 5 years ago

Well actually there's not a ton of info in that stack trace, do you happen to know what is null? Or do you know any line number information?

Nikoshi commented 5 years ago

Actually I don't know more than what the stack trace told me, but I've looked in the function where the exception was thrown

private void DrawMarkers(PaintEventArgs e, Pen servicePen)
{
    foreach (VisualMarker m in visibleMarkers)
    {
    if(m is CollapseFoldingMarker)
            using(var bk = new SolidBrush(ServiceColors.CollapseMarkerBackColor))
            using(var fore = new Pen(ServiceColors.CollapseMarkerForeColor))
            using(var border = new Pen(ServiceColors.CollapseMarkerBorderColor))
            (m as CollapseFoldingMarker).Draw(e.Graphics, border, bk, fore);
    else if (m is ExpandFoldingMarker)
            using (var bk = new SolidBrush(ServiceColors.ExpandMarkerBackColor))
            using (var fore = new Pen(ServiceColors.ExpandMarkerForeColor))
            using (var border = new Pen(ServiceColors.ExpandMarkerBorderColor))
        (m as ExpandFoldingMarker).Draw(e.Graphics, border, bk, fore);
    else
            m.Draw(e.Graphics, servicePen);
    }
}

I could try to debug the dll, maybe I get a line number or something else telling me where the exception happended

Nikoshi commented 5 years ago

I made progess 😄. ServiceColors.CollapseMarker* is null. After looking again through my properties I saw that (I don't know why) ServiceColors is set to null.
I will fix it in my code, but it might be a good idea to check if ServiceColors is set to null.

grafik

Hexman768 commented 5 years ago

If you look at the code you posted before, you are setting the servicecolors to null. This is what is causing the exception. The following line should be removed from your code: Me.tbSQLCode.ServiceColors = Nothing

Nikoshi commented 5 years ago

That's what I said, but I can't tell how that instruction ended up there, because this was generated by the vs gui builder and I didn't toch this

Hexman768 commented 5 years ago

That code was generated by the vs gui builder? What version of vs are you using?

Nikoshi commented 5 years ago

Visual Studio 2015

Hexman768 commented 5 years ago

Try updating to visual studio 2019, I've always compiled the application on vs 2017 and it still worked fine, could be an issue with the way 2015 handles component initialization.

Nikoshi commented 5 years ago

We're currently switching to 2019, I will try this^^ I guess the issue can be closed for now

Hexman768 commented 5 years ago

Sounds good, if the issue persists, feel free to reopen.

Nikoshi commented 5 years ago

Thanks for your help ^^