Apr 29, 2007

SumatraPDF 0.6 released

I’ve just released another version of SumatraPDF. This version mostly fixes bugs. The changes in this release are:

  • enable opening password-protected PDFs
  • don’t allow printing in PDFs that have printing forbidden
  • don’t automatically reopen files at startup
  • fix opening PDFs from network shares
  • new, better icon
  • reload the document when changing rendering engine
  • improve cursor shown when dragging
  • fix toolbar appearance on XP and Vista with classic theme
  • when MuPDF engine cannot load a file or render a page, we fallback to
    poppler engine to make rendering more robust
  • fixed a few crashes
Category:  — Permalink

A debugging story

or how a debugger sometimes works against you.

SumatraPDF was crashing on some PDF files and I didn’t know why. On Windows you can have just-in-time debugging i.e. tell the system to automatically launch a debugger (Visual Studio or WinDBG) when a program crashes but the clues I could get at the time of a crash (callstack and other current state of the program) were not enough to figure out the cause (especially given that it was in core PDF rendering code that I didn’t write).

Usually I would just set a breakpoint just before the place of the crash and work backwards from that. Unfortunately, when running under the debugger (either Visual Studio or WinDBG) the crash didn’t happen. The only good thing about that was that it offered another clue: apparently something about the system changes when the app is executed from within the debugger and it hides the problem.

That stumped me for a while until I made a breakthrough: I figured out that if I put DebugBreak() call in my app, it’ll break into the debugger after the app has started so I’ll be able to debug.

With a few well-placed conditional breakpoints I was able to figure out that the cause of the problem was uninitialized reference count on an object.

My theory is that when an app was executed from within a debugger, memory allocator was using different flags and always zeroing malloc()ed memory (which masked the refcount problem) while without the debugger it was random data which exposed bad refcounting logic.

Lessons learned:

  • sometimes unexplained and very perplexing has an explanation
  • the debugger can work against you
  • WinDBG is awesome - it puts to shame anything I’ve used on Unix, especially gdb. Learn how to use as it can come very handy when debugging hard problems. Visual Studio is also a good debugger - I use both depending on the kind of issue I’m debugging (for example WinDBG is faster to launch, has good support for conditional breakpoints and an array of useful extensions)
  • refcounting is evil and don’t let anyone tell you otherwise. You’ll meet people telling you that “refcounting makes programming easier”. “Ha, ha, ha” should be your response.

Category:  — Permalink

Apr 13, 2007

Few things I’ve learned when writing Sumatra PDF.

1. Good software takes ten years - get used to it. Version 0.1 had 573 trickling downloads. Version 0.2 - about 7k, 0.3 - 7.5k, 0.4 - 15k. It wasn’t until version 0.5 when the downloads took off (relatively to previous versions) and as of today reached 80k. It took several months and several program revisions before it was noticed, linked to and got a decent ranking in google.

2. As this is Windows software, I focused on providing an easy installation program. I only added a zip archive because it was easy to do. I expected that a majority of people will get the installer but it turns out that about 30% of downloads are of zip archive. Even though those numbers are a bit inflated (see below), it’s still an unexpectedly big percentage.

3. There are many websites that catalog software for Windows. They write a little blurb and point to a program.

It’s a win-win situation: software gets additional exposure, the website provides a service to users and can make some money from ads. Except that those websites sometimes get overboard in their focus on keeping users on their website (so that they can make more money from ads).

One practice that I don’t like is download link directly pointing to the file instead of the home page for my program. It doesn’t serve the program author since it cuts people off from product and, for example, they won’t find out that they can leave a comment in the forum that will help me improve the program in the future.

It’s also not good for the users. I carefully designed my website to provide useful information about the program. My website always has the latest version (while others might link to an older version). One website linked only to a zip version of my program so people didn’t even know that they could download an easier to use installer (and as stats show, at least 70% of them would choose installer if given the choice).

I have little faith that an appeal to moral values can change behavior of cowboys in our World Wild West, but there is a simple technical solution to this problem. A little bit of mod_rewrite magic based on referrer field and now all request to older versions and all requests not originating from my own websites are redirected to a generic download page. Fortunately most of those operator are too cheap and lazy to host the downloads themselves.

Category:  — Permalink

Apr 11, 2007

2 great books and one not so great.

A good book grips you and forces you  to keep reading until you’re done. Steve Wozniak’s “iWoz” and Jessica Livingston’s “Founders at work” are such books.

Wozniak’s book is inspirational for an engineer and shows how passion and hard work leads to creating great products and making lots of money.

Livingston’s book is inspirational for an entrepreneur and shows how passion and hard work (sometimes) leads to creating great products and making lots of money.

The book I was disappointed by is Scott Rosenberg’s “Dreaming in code“. I bought it because it promised to describe the behind-the-scenes story of Chandler, a project I was interested in. And the parts that did that - I liked. However, it also had large sections on tangential issues about the business of creating software that might be interesting to some but weren’t to me (mostly because I already knew about all that other stuff).

Category:  — Permalink