4.23.2020

Visual Debugger 1

TLDR; My latest programming project is a visual debugger plug-in for Visual Studio. The intent is to make it easier to visualize 3D spatial math while debugging. Here's a picture:



Like many programmers, or probably anybody with much experience in a field, I roll my eyes at the inaccuracies when I see my area of expertise portrayed in film. But one film about a programmer that stuck with me, and this may be a false memory, was Chappie: I remember being inspired by the amount of time Dev Patel's character apparently invested in custom hardware and software to accelerate his workflow.

The problem:
Debugging issues like "why are my effects being created over there?", "what does that quaternion rotation actually look like?", and "why aren't these objects colliding?" has always been a challenge for me.

The context:
I write C++ code using Visual Studio at work (2017) and at home (2015), and while I'm aware it has a plug-in system I had never considered writing one until recently. I think I decided to try to learn how because I thought it might pay dividends in my long term productivity.

The process (so far):
Installing the Visual Studio Extensibility SDK was pretty painless, although I did have to fix one small thing in the SDK headers to get the tool window plug-in to compile. Every night I set a goal that I could achieve (or at least make significant progress on) in an hour or two - this was a lot easier at the beginning. Once I got a tool window showing up in Visual Studio and figured out how to get a handle to it, I just needed to set up an OpenGL context and draw a test shape (read: copy-paste an OpenGL tutorial code for umpteenth time). Then some windows message processing code to control the camera (along with some multithreading and synchronization to ferry data between the input and the rendering), followed by adding a library of object types that could be rendered (e.g. vector, point), and finally actually trying to get real data out of Visual Studio to render.

The biggest challenges have been:

  1. 1. Learning how to use COM. It's not a system I've ever used before 
  2. 2. Finding documentation for how to do something in the extensibility framework. The remarks are pretty sparse and the examples are all in C# (which means everything is slightly different)
  3. 3. Getting information out of the watch window. My MVP (minimum viable product) goal was being able to right-click on a variable in the watch window, select a command from a context menu, and see the variable visualized in 3D in a window. From all of my Googling thus far, I haven't found an interface for this (see challenge #2). The current implementation executes the Copy command and then tries to consume the data from the clipboard; it hurts my soul as much as I'm sure it hurts yours (which is to say both a lot and a little). I did explore trying to restore the clipboard, but stackoverflow suggests that path is tedious at best and fraught with peril.
  4. 4. Iteration is pretty slow: running requires launching a separate instance of Visual Studio and loading all of the associated symbols. It takes a couple minutes on my laptop.
The biggest wins have been:
  1. 1. It actually works. It's far from complete, though (see my todo list below).
  2. 2. I've learned some new skills and gained new competence in existing areas
    1. a. COM: I'm the farthest thing from an expert and I'm probably not going to use it unless I have to, but I know what it is and I appreciate the value that it offers for interoperability between unrelated pieces of software.
    2. b. DLL's: I've never written a DLL before or learned much about how they work. Challenge #4 above (iteration speed) encouraged me to explore making a DLL (and a standalone application) for faster iteration on features not related directly to Visual Studio integration.
    3. c. 3D Math (especially quaternions): Every time I go back to (re)write some 3D math code I think I learn a little more. I know about 0.1% more about quaternions than I did when I started and I found more bugs in my math library code.
My todo list, as promised:
-re-open window
-improved camera controls (arrow key input: base class is swallowing arrows keys because it's a dialog, mouse click & drag?)
-object labels
-object list tree view (dearIMGUI?)
-parent objects to other objects
-customize coordinate system
-add-as sub menu (e.g. vector4 -> point3)
-pointer objects?
-use shaders instead of legacy OGL?
Back to work! 

No comments:

Post a Comment