{"id":19586,"date":"2013-05-06T00:51:06","date_gmt":"2013-05-06T05:51:06","guid":{"rendered":"http:\/\/www.shamusyoung.com\/twentysidedtale\/?p=19586"},"modified":"2013-05-06T11:11:22","modified_gmt":"2013-05-06T16:11:22","slug":"the-bug-is-there-is-no-bug","status":"publish","type":"post","link":"https:\/\/www.shamusyoung.com\/twentysidedtale\/?p=19586","title":{"rendered":"The Bug is, There is no Bug"},"content":{"rendered":"<p><table   class=\"\" cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/splash_keyboard.jpg' class='insetimage'   alt='splash_keyboard.jpg' title='splash_keyboard.jpg'\/><\/td><\/tr><\/table><\/p>\n<p>I&#8217;ve mentioned before that I used to make comics using <a href=\"?p=9562\" title=\"Comic Press\">a program I wrote myself<\/a>. I wrote Comic Press back in 2007 or so, back when I still worked at Activeworlds. When I left the company, I left behind the nice professional version of Developer Studio 6 that came with the job. That was my programming environment of choice, and I have to admit that it was an admirable piece of software. How many other commercial software products are still working fine twelve years later? Not many, I&#8217;d wager. Well, maybe server-side. But the turnover rate is usually pretty high for stuff used by individuals. Doubly so for stuff from Microsoft.<\/p>\n<p>I switched over to using Visual Studio Express 2010, which is actually twelve years newer, but missing some key features. (The two programs are of the same product line and lineage. Microsoft just re-branded Developer Studio to Visual Studio at some point.) So I went from using a very old but feature-rich toolset to a modern but stripped-down version. The key feature I lost was the ability to use resource files. In the world of Microsoft, resource files are containers for dialog interfaces, menus, and window layouts. You design a dialog box in a nice little drag-and-drop interface, and then use it in your program. Visual Studio Express (the &#8220;express&#8221; edition is the stripped-down version for freeloaders like me) can&#8217;t use resource files. The result was that I could no longer compile Comic Press.<\/p>\n<p>If I ever wanted to make any changes to Comic Press, I&#8217;d have to strip out all the resource file usage and painstakingly re-create the dialogs in code. That&#8217;s a lot of hassle, so I never bothered. The existing version of Comic Press did everything I needed it to, so I just backed up the source code and forgot all about it.<\/p>\n<p>Then I moved to Windows 7, and Comic Press broke. <\/p>\n<p><!--more--><table   class=\"\" cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/comic_press4.jpg' class='insetimage'   alt='comic_press4.jpg' title='comic_press4.jpg'\/><\/td><\/tr><\/table><\/p>\n<p>Word bubbles became giant black rectangles, and nothing I did would fix them.  I tried running the program in every compatibility and display mode available. Nothing worked. I wanted to make the above comic for <a href=\"?p=19537\">the end of our Dishonored season<\/a> and I realized if I was going to do that, I&#8217;d need to fix Comic Press First. <\/p>\n<p>So I bite the bullet and dig the code out of mothballs. I half-ass it and basically rip out all the dialogs. The program no longer asks what you want to name the final image or where you want to save them. It just saves it as &#8220;image1.bmp&#8221; and dumps it to the <code>E:\\<\/code> drive, overwriting whatever might be there without warning or confirmation. Also without making sure there <em>is<\/em> an <code>E:\\<\/code> drive, heh. That&#8217;s a perfectly reasonable user interface, right?<\/p>\n<p>Now that the program runs again, we can see about what might be causing these black rectangles. What is it about the move from Windows XP to Windows 7 that could possibly break the program in this way?<\/p>\n<p>For the record, the black rectangles are texture maps. The program makes word bubbles by analyzing the text and figuring out how to arrange the words into the smallest possible oval.  Then it draws the words onto a texture. The texture is transparent, except for the letters. So you end up with a texture that looks like this:<\/p>\n<p><table   class=\"\" cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/comic_press5.jpg' class='insetimage'   alt='comic_press5.jpg' title='comic_press5.jpg'\/><\/td><\/tr><\/table><\/p>\n<p>Then it draws a word bubble using flat polygons, and arranges them together in the scene. Looking at the program, I can see all of that is still working, but for some reason the final texture is coming out solid black.  I can see the bubble-building code is running fine. It THINKS it&#8217;s making a word bubble, but the final product is solid black.  Why?<\/p>\n<p>Hm. Actually, is it drawing anything at all? The text is black and the final texture is black.  What happens if I change the text to green?<\/p>\n<p><table   class=\"\" cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/comic_press6.jpg' class='insetimage'   alt='comic_press6.jpg' title='comic_press6.jpg'\/><\/td><\/tr><\/table><\/p>\n<p>Okay, that clears things up a bit. It&#8217;s drawing the words just fine, and the only problem is that the texture is black and not transparent. <\/p>\n<p>I really don&#8217;t see why the move from Windows XP to Windows 7 should do anything to impact this. It makes no sense. Let&#8217;s just ignore this and pretend that we don&#8217;t know that it works on XP. Let&#8217;s look at the program objectively. What could cause it to fail to make a transparent texture?<\/p>\n<p>When you&#8217;re using OpenGL under Windows, there&#8217;s usually some fussing you have to do at the start. You have to create an OpenGL rendering context, and to do that you have to tell Windows about how you want to use OpenGL. What color depth do you want, how detailed you want the z-buffer to be, that sort of thing. Here&#8217;s mine:<\/p>\n<pre lang=\"c\" line=\"1\">\r\nstatic\tPIXELFORMATDESCRIPTOR pfd =\t\t\t\r\n{\r\n  sizeof(PIXELFORMATDESCRIPTOR),\t\t\t\r\n  \/\/ Version Number\r\n  1,\t\t\t\t\t\t\t\t\t\t\t  \r\n  PFD_DRAW_TO_WINDOW |  PFD_SUPPORT_OPENGL |\tPFD_DOUBLEBUFFER,\t\r\n  \/\/ Desired RGBA Format\r\n  PFD_TYPE_RGBA,\t\t\t\t\t\t\r\n  \/\/ Desired RGBA bit depth\r\n  32,\t\t\t\t\t\t\t\t\t\t    \r\n  \/\/ glRgbaBits Ignored\r\n  0, 0, 0, 0, 0, 0,\t\t\t\t\t\r\n  \/\/ Alpha Buffer\r\n  0,\t\t\t\t\t\t\t\t\t\t\t  \r\n  \/\/ Shift Bit Ignored\r\n  0,\t\t\t\t\t\t\t\t\t\t\t  \r\n  \/\/ Accumulation Buffers\r\n  0,\t\t\t\t\t\t\t\t\t\t\t  \r\n  \/\/ Accumulation Bits Ignored\r\n  0, 0, 0, 0,\t\t\t\t\t\t\t\t\r\n  \/\/ Z-Buffer bit depth\r\n  16,\t\t\t\t\t\t\t\t\t\t\t  \r\n  \/\/ Stencil Buffers\r\n  1,\t\t\t\t\t\t\t\t\t\t\t  \r\n  \/\/ Auxiliary Buffers\r\n  0,\t\t\t\t\t\t\t\t\t\t\t  \r\n  \/\/ Main Drawing Layer\r\n  PFD_MAIN_PLANE,\t\t\t\t\t\t\r\n  \/\/ Reserved\r\n  0,\t\t\t\t\t\t\t\t\t\t\t  \r\n  \/\/ Layer Masks Ignored\r\n  0, 0, 0\t\t\t\t\t\t\t\t\t\t\r\n};\r\n<\/pre>\n<p>The interesting thing here is line #14, where I have Alpha Buffer set to zero. I&#8217;m telling Windows \/ OpenGL that I will never care about alpha channels and that I don&#8217;t want to use them.  Meaning no transparency. <\/p>\n<p>Side note: It&#8217;s really odd how we have these yes \/ no values being defined with one and zero. Today you&#8217;d expect to do this with with a bool. <\/p>\n<pre lang=\"c\" line=\"1\">\r\n\/\/So instead of doing this:\r\nchar UseAlpha = 0;\r\n\r\n\/\/You would do it this way:\r\nbool UseAlpha = false;\r\n<\/pre>\n<p>We&#8217;re using this archaic way of setting up yes \/ no values because that&#8217;s how both Windows and OpenGL expect the values. And they expect the values like this because they were written back in the days of regular vanilla C, before the C++ language had caught on. <\/p>\n<p>Anyway. Apparently I&#8217;m explicitly telling OpenGL not to set aside memory for an alpha channel. This distinction probably made sense in 1992 when OpenGL was written. Back then, memory was precious. Now I can&#8217;t think of any situation where you would gain anything from excluding the alpha channel. It&#8217;s like if you&#8217;re a plumber trying to save gasoline by not bringing your wrench when you drive to a job. The van will be slightly lighter, sure. But even if you&#8217;re SURE you&#8217;re not going to need it, it&#8217;s so useful and the cost of bringing it is so low it&#8217;s not worth leaving behind. <\/p>\n<p>Which makes me wonder why I did leave it behind in this case. <\/p>\n<p>Anyway, I change the zero to a one and sure enough&#8230;<\/p>\n<p><table   class=\"\" cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/comic_press7.jpg' class='insetimage'   alt='comic_press7.jpg' title='comic_press7.jpg'\/><\/td><\/tr><\/table><\/p>\n<p>Okaaaay.  That fixes the problem, I guess.  But now the question is: <strong>Why did this ever work in the first place?<\/strong> The entire point of this program is to make transparent textures, and yet I specifically told OpenGL I never wanted to do anything with transparency. And then it worked anyway, on multiple machines, for years. This is a bug for sure, but it&#8217;s a bug I should have caught twenty seconds after writing it, because the program shouldn&#8217;t have worked.<\/p>\n<p>I dunno. <\/p>\n<p>For the curious, here is the final comic I was trying to make:<\/p>\n<p><table   class=\"\" cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/dishonored_outsider.jpg' class='insetimage'   alt='dishonored_outsider.jpg' title='dishonored_outsider.jpg'\/><\/td><\/tr><\/table><\/p>\n<p><strong>Not<\/strong> worth the hours I dumped into getting Comic Press working again, but it&#8217;s something I should have gotten done ages ago. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve mentioned before that I used to make comics using a program I wrote myself. I wrote Comic Press back in 2007 or so, back when I still worked at Activeworlds. When I left the company, I left behind the nice professional version of Developer Studio 6 that came with the job. That was my [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[66],"tags":[],"class_list":["post-19586","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/19586","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=19586"}],"version-history":[{"count":0,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/19586\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=19586"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=19586"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=19586"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}