• Welcome to Valhalla Legends Archive.
 

Unhandled Exception Error with VB.NET

Started by Smurfling, July 23, 2003, 09:50 AM

Previous topic - Next topic

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:


   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

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?

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.

Smurfling

#3
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

Adron

Have you checked your handlïng of ïncomplete packets?

Smurfling

Quote from: Adron on July 24, 2003, 06:37 AM
Have you checked your handlïng of ïncomplete packets?

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...

Camel

Quote from: Andreas Strobl on July 24, 2003, 06:45 AM
Quote from: Adron on July 24, 2003, 06:37 AM
Have you checked your handlïng of ïncomplete packets?

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...

Breakpoint wherever you're adding items to the listview and check all of the paramaters you're sending.