Jump to content

Codelab debug


WarrickF

Recommended Posts

Not normally.

BUT, here's something I've done before:

void Render(Surface dst, Surface src, Rectangle rect)
{
   ColorBgra CurrentPixel;
   for (int y = rect.Top; y < rect.Bottom; y++)
   {
       for (int x = rect.Left; x < rect.Right; x++)
       {
           CurrentPixel = src[x,y];
           if (x == 0 && y == 0) // only call this ONCE per run!
           {
               MessageBox.Show(
                     "R = " + CurrentPixel.R.ToString() + "; " +
                     "G = " + CurrentPixel.G.ToString() + "; " +
                     "B = " + CurrentPixel.B.ToString()
               );
           }
           dst[x,y] = CurrentPixel;
       }
   }
} 

Link to comment
Share on other sites

I've filed a v4 bug for this because I think it's a good idea.

In the meantime, you can try this.

1) Get a hold of aprogram called DebugView. It's by Mark Russonovich, http://technet.micro...s/bb896647.aspx

2) You'll note that in the description for DebugView it says it works with output that is directed at the Win32 function "OutputDebugString". So, we need to get access to that function.

Here's how:

using System.Runtime.InteropServices; // at top of file, of course

// put this wherever it's convenient for you
// http://msdn.microsoft.com/en-us/library/aa363362(VS.85).aspx
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = false)]
public static extern void OutputDebugStringW(
   [in] [MarshalAs(UnmanagedType.LPWStr)] string lpOutputString);

There may be a way to use something like Console.Error.WriteLine(), but I haven't tried to verify that it'll work.

So what you would do is 1) make sure DebugView is running, and 2) make sure your plugin is using OutputDebugStringW. (btw the 'W' suffic means Unicode text, which is what C#/.NET use. there is also an 'A' version for ANSI/ASCII text but nobody uses that stuff anymore, not since like win95/98)

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

Actually, in reference to #2 above, there may be a simpler (and more "official") way.

Create an instance of System.Diagnostics.DefaultTraceListener() and use its Write(string) method. If you look at its code with Reflector, it (eventually) sends your string to OutputDebugString anyway.

(BTW I was able to find this very quickly by doing a search, with Reflector, for members named "OutputDebugString", across the .NET Framework DLLs. I then used right click -> Analyze and then right click -> Used By to trace back towards a public method that used it.)

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

Can't put "using" lines in a CodeLab script.

Nope, true. In that case you'll have to fully quality attributes like DllImport and MarshalAs with a System.Runtime.InteropServices prefix.

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

  • 5 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...