Valhalla Legends Forums Archive | General Programming | Unhandled Exception Error with VB.NET

AuthorMessageTime
Smurfling
Ok i tried to figure this out now for a really long time and i don't get what could be wrong...

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
at System.Windows.Forms.RichTextBox.EditStreamProc(IntPtr dwCookie, IntPtr buf, Int32 cb, Int32& transferred)
at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
at System.Windows.Forms.Control.DefWndProc(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.TextBoxBase.WndProc(Message& m)
at System.Windows.Forms.RichTextBox.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.PeekMessage(MSG& msg, IntPtr hwnd, Int32 msgMin, Int32 msgMax, Int32 remove)
at System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at eXgBot.frmMainForm.Main() in C:\Dokumente und Einstellungen\AStrobl\Desktop\new\frmMain.vb:line 15
The program '[2208] eXgBot.exe' has exited with code 0 (0x0).

vb .net is telling me i got a nullreference... when it stops it marks my class from the mainform (Public Class frmMainForm). Can anybod help me out / do you need more info?

Edit: I have a tabpage with a richtextbox called rtbChat on my form. when there is text added to the rtb after some time (always different) theres the above exception... I have the try...catch ex as exception in all of my sub's and nowhere i get an error...
I tried the following code and now it almost suddenly prints out the nullreference when i add some text:

[code]
Private Sub rtbChat_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rtbChat.TextChanged
rtbChat.SelectionStart = Len(rtbChat.Text)
rtbChat.Focus()
cbSend.Focus()
cbSend.SelectionStart = Len(cbSend.Text)
End Sub
[/code]
July 23, 2003, 2:50 PM
Smurfling
Ok i found out something new:

The RichTextBox output goes through events - if i get a bnet chat packet the event is fired up, catched on my mainform and then performs the output through a sub.
Now if i am within a private channel with almost none/very few chat packets (not that much output to add to the rtb) it works fine. But if i change now into a channel like brood war usa-1 with lots of users in it and a lot of chat packets after a short amount of time i get the nullreference error...

Could it be my form (the event handler) can't handle too many events in a short amount of time? Does anyone know of a limitation like that?
July 24, 2003, 8:09 AM
Adron
I don`t know īf you`re usīng some ocx or toolset that handles thīs for you, but īt seems to me līke you`re gettīng an īncomplete packet. Thīs happens normally whenever you go to a channel wīth lots of traffīc. The solutīon īs to keep readīng more data from your b.net connectīon and combīnīng wīth what you already got untīl you have a complete packet.
July 24, 2003, 9:44 AM
Smurfling
hmm really weird: now i do get the nullreference even if i am not displaying the chat - just connecting... Looks like if there has to be anything done on the form the nullreference occurs.

An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
at System.Windows.Forms.RichTextBox.EditStreamProc(IntPtr dwCookie, IntPtr buf, Int32 cb, Int32& transferred)
at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
at System.Windows.Forms.Control.DefWndProc(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.TextBoxBase.WndProc(Message& m)
at System.Windows.Forms.RichTextBox.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.PeekMessage(MSG& msg, IntPtr hwnd, Int32 msgMin, Int32 msgMax, Int32 remove)
at System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at eXgBot.frmMain.Main() in C:\Dokumente und Einstellungen\AStrobl\Desktop\new\frmMain.vb:line 19

It's always highligting me the class of my main form:
Public Class frmMain

Could it be that a reference to the class is set wrong? I check everything in the windows form designer generated code but all looks ok, pointing straight to frmMain...

Edit: Adron, i am using a self-written packet buffer class - it was working now for about a month and since about 4 days (after i added a chat mode to my bot - richtextbox, textbox, new tabpage) i get the nullreference. Well i already had it before but it was only in about 1 of 10 days once...

Edit2: I changed frmMain to mainForm, changed all references too and still i do get this annoying nullreference... I would post my code but it's about 3.000 lines and i don't think anyone would like to look at that to help me find out what's wrong
July 24, 2003, 9:57 AM
Adron
Have you checked your handlīng of īncomplete packets?
July 24, 2003, 11:37 AM
Smurfling
[quote author=Adron link=board=5;threadid=2029;start=0#msg15897 date=1059046678]
Have you checked your handlīng of īncomplete packets?
[/quote]

Yes i did, but i don't think incomplete packets are the cause. I just had the nullreference when adding a item to a listview...
July 24, 2003, 11:45 AM
Camel
[quote author=Andreas Strobl link=board=5;threadid=2029;start=0#msg15898 date=1059047123]
[quote author=Adron link=board=5;threadid=2029;start=0#msg15897 date=1059046678]
Have you checked your handlīng of īncomplete packets?
[/quote]

Yes i did, but i don't think incomplete packets are the cause. I just had the nullreference when adding a item to a listview...
[/quote]

Breakpoint wherever you're adding items to the listview and check all of the paramaters you're sending.
July 24, 2003, 5:36 PM

Search