Visual Studio .Net Debugging... DOH... Not fun at times...

For all coding issues - MODers and programmers, HTML and more.

Moderators: Jeff250, fliptw

Post Reply
User avatar
SirWinner
DBB Fleet Admiral
DBB Fleet Admiral
Posts: 2700
Joined: Thu Nov 05, 1998 12:01 pm
Location: Oklahoma City, Oklahoma, United States of America
Contact:

Visual Studio .Net Debugging... DOH... Not fun at times...

Post by SirWinner » Mon Jul 17, 2006 10:37 pm

Have a commercial grade program that I've written that uses 2 different 3rd party DLL's built into it.

One of the calls to one of the DLL libraries \"seemed\" to have a problem with a \"system.drawing.dll\"...

Message box had this information in it:

---
- An unhandled exception of type 'System.ArgumentException' occurred in
- system.drawing.dll
-
- Additional information: Invalid parameter used.
-
- [Break] [Continue] <Ignore> [Help]
---

*** Note *** Ignore button disabled above.

5 different message boxes most relating to system.drawing.dll would randomly occur.

... \"Try... End Try\" was not able to trap the error... DOH!... looked further into the problem...

... The \"real\" problem was a timing issue on the child form that was used by the main form.

What happened was the main form was attempting to update the child form before the initialization of that form was complete.

Just thought this \"experience\" might be helpful to someone trying to track down a Visual Studio .Net bug.

Happy Programming to you all!

:)
User avatar
DCrazy
DBB Alumni
DBB Alumni
Posts: 8826
Joined: Wed Mar 15, 2000 3:01 am
Location: Seattle

Post by DCrazy » Mon Jul 17, 2006 10:40 pm

Right now I'm actually wrangling with event timing issues myself. I'm writing a 3D engine using Managed DirectX and I need to figure out exactly when things get disposed so I don't try and render to a window that doesn't exist anymore.

I love .NET but sometimes the (lack of) documentation makes me want to cry.
User avatar
SirWinner
DBB Fleet Admiral
DBB Fleet Admiral
Posts: 2700
Joined: Thu Nov 05, 1998 12:01 pm
Location: Oklahoma City, Oklahoma, United States of America
Contact:

Post by SirWinner » Tue Jul 18, 2006 1:55 pm

D,

Here's an idea...

- Create a boolean (true / false) flag defaulted as \"false\" when the program loads. (Call it \"ItemLoaded\")

- Set \"ItemLoaded = True\" when the item is there.

- Set \"ItemLoaded = False\" when the item is about to be disposed.

Perhaps that might help.

Happy Coding,
SirWinner
User avatar
DCrazy
DBB Alumni
DBB Alumni
Posts: 8826
Joined: Wed Mar 15, 2000 3:01 am
Location: Seattle

Post by DCrazy » Tue Jul 18, 2006 9:39 pm

Well, I essentially wound up doing that, but using the Device.Disposed property to determine if I should bail out of my loop.

The bad thing about using Managed DirectX is that it wants to use System.Windows.Forms for everything, which would be great if System.Windows.Forms didn't require you to use Application.DoEvents() to process the message pump. Combine that with the lack of a PeekMessage() equivalent and you're running in a tight loop that calls Render and then DoEvents, preventing the garbage collector from running and therefore bloating your program's RAM usage, not to mention using 100% of your time slice and thus 100% CPU usage (or in my case 50% on a P4 with HyperThreading, and limited to that because WinForms requires your application to be [STAThread]. GRR!)
User avatar
SirWinner
DBB Fleet Admiral
DBB Fleet Admiral
Posts: 2700
Joined: Thu Nov 05, 1998 12:01 pm
Location: Oklahoma City, Oklahoma, United States of America
Contact:

Post by SirWinner » Wed Jul 19, 2006 5:34 pm

D,

I hear that!

Here's what we did to fix the \"system.drawing.dll\" issues in our program.

---
Dim frmABC As frmABC

frmABC = New ABC(Parm1,Parm2,Parm3)
frmABC.ShowDialog()

frmABC.Dispose() ' <-- This resolved the issue!
---

Otherwise, we'd see random \"system.drawing.dll\" error message boxes and occasionally GDI+ error messages while the running and exiting to windows!

*** Lesson learned: If the form is NOT disposed of properly during the normal running of the program, it will complain when program is exiting to windows!

---

Literally ONE week of programming time spent tracking down and fixing this \"bug\"!

---

Side point: Take code samples from someone and finely test them for issues like this and others before releasing your \"application\" for the \"Real World(tm)\" to use.

:oops:
User avatar
DCrazy
DBB Alumni
DBB Alumni
Posts: 8826
Joined: Wed Mar 15, 2000 3:01 am
Location: Seattle

Post by DCrazy » Wed Jul 19, 2006 8:36 pm

SW,

Got my app working like this (C# pseudocode):

Code: Select all

class FOCUSApplication
{
  Form mainForm;
  Device device;

  public static void Main()
  {
    using(FOCUSApplication app = new FOCUSApplication())
    {
      Application.Run();
    }
  }

  public FOCUSApplication()
  {
    Application.OnIdle += new EventHandler(Application_Idle);

    mainForm = new Form();
    //set up mainForm
    mainForm.Closed += new EventHandler(mainForm_Closed);
    mainForm.Disposed += new EventHandler(mainForm_Disposed);
    mainForm.Show();

    // create DirectX device
    device.Disposing += new EventHandler(device_Disposing);
  }

  private void Application_Idle()
  {
    // raise custom Update event
    // that subsystems will handle
  }

  private void mainForm_Closed(object o, EventArgs e)
  {
    mainForm.Dispose();
  }

  private void mainForm_Disposed(object o, EventArgs e)
  {
    device.Dispose();
  }

  private void device_Disposing(object o, EventArgs e)
  {
    Application.Exit();
  }
}
All the benefits of managed code, without taking up 100% CPU. A bit convoluted but it works flawlessly. :D
Post Reply