Woo woo woo… you know it!

One of the things I’ve been working on recently is an in app editor for the OGRE based 3D GUI that forms the front end of one of our main products. One of the features that I added was the ability to switch between scenes with the click of a button. I was able to get this working on Windows with little difficulty, but on Linux I constantly got the same assert.

ogre/RenderSystems/GL/src/OgreGLSupport.cpp:56: virtual void Ogre::GLSupport::initialiseExtensions(): Assertion `pcVer && "Problems getting GL version string using glGetString"' failed.

I have revisited this problem several times in recent months and each time my investigation faltered at the same point. The first time a scene was loaded, everything was fine, the second time a scene was loaded OGRE failed to initialize the OpenGL Context. Something wasn’t being released correctly when the first scene was shutdown. I tried everything. With OGRE it should really be as simple as calling shutdown() on the root node and then deleting the root node using OGRE_DELETE, but it just wouldn’t work.

This past Friday I finally got it working though. The following code snippet is from the second time that OGRE tried to initialize the OpenGL render system. The dimensions of the target render window are wrong. For whatever reason, Qt was not able to finish initializing the container widget before I was grabbing the X11 info and passing this onto the OGRE initialization code. A simple decouple using a 1ms timer sorted the issue.

******************************
*** Starting GLX Subsystem ***
******************************
GLRenderSystem::_createRenderWindow "SomeWidget", 1059x0 windowed  miscParams: parentWindowHandle=135727904:0:56624998
GLXWindow::create used FBConfigID = 117

I’m not going to lie, I fist bumped like The Long Island Iced Z when I saw that model reload! :D

echo “Oh shit!”

I spent the back end of last week sorting out the RPM creation process for some projects I’m working on. We tend to use CheckInstall to generate the first cut spec files and then manually update them. I had done all of the hard work; I had the spec files down for the various RPMs and I had bash scripts set up to generate them. I asked a colleague if he knew the switch to pass to CheckInstall to have it select RPM automatically, just to make the process completely fire and forget. He didn’t know off the top of his head, but said that he would look it up. I Ctrl+C’d the script and watched as CheckInstall cheerfully entered it’s clean up routine. Did I not mention that CheckInstall has a helpful clean up routine built in? It tidies up (deletes) everything in the $BuildRoot directory. Unfortunately CheckInstall hadn’t got far enough into it’s execution to reinitialise that variable, which I actually also use in my own scripts. It points to the root of my workspace. CheckInstall very cheerfully nuked the whole thing. You have been warned.

Post tune: Gold Cobra, Gold Cobra, Limp Bizkit.

I am a mutant

I am a mutant. I was bitten by a radioactive spider during a school trip and… I’m lying. I don’t have any superpowers, I’m just colour blind. I’m not full on grey scale colour blind, I am Tritanomalous and Deuteranomalous, or more simply I am red/green and blue/green colour blind. Being colour blind has a very negligible effect on my life, 99% of the time I don’t notice and it doesn’t matter when I confuse colours. Notable exceptions include the “green” light on new style temporary traffic lights which I perceive as blue, the coloured bands on resistors (again, apologies to the electronics lab tech during my time at uni) and my trainers with the “blue” strap on them – my Mum requested this one was added in after I had her spend an afternoon looking for trainers with a green strap.

Anyway, enough about me, this post is for you. Okay, a little bit more about me first… I am a software/web developer and because I am colour blind I am aware of certain issues/limitations which other folk will often completely fail to consider when designing User Interfaces.

Colour Choice: Lets start with the biggest potential mistake: colour choice, you need to consider where colours are in the spectrum. I found this website which allows you to generate and compare colour palettes, but it has the added bonus of allowing you to see how your colour scheme looks to people with the various flavours of colour blindness. What looks complementary to you may look incredibly odd, or worse still completely identical, to me.

Colour Mass: But it’s not just about colour swatches, you need to consider the amount of colour that is used because colour mass also effects perception. A thin line of a certain colour may actually appear as black to someone who is colour blind, whereas a slightly thicker line will be able to be perceived without problem. In exactly the same way, colours can get lost in the “noise” of other colours if too many are grouped together.

Texture: Another important point to consider is that the texture of an item can really effect how a colour blind person perceives it. A printed design mock up can look completely different to the design as viewed on a screen, and different again when viewed on a different screen. Textures and materials do effect colour perception.

Consider this post on “Better car brake lights” by Mark Cossey. Hopefully you can now see that using escalating colours to indicate how severely the car is decelerating would be dangerous, whereas flashing lights would be without problem to the majority of colour blind people. This is why in general, I don’t think that you should ever use colour alone to present information to users, an additional albeit slight change in appearance will make your design much more accessible to both colour blind and regular sighted users.

Armed with the information in this post, you should be able to appreciate the absolute best thing about being colour blind: some forms of camouflage are completely ineffective when used against colour blind people. If only this applied to Call of Duty!

So Fresh, So Clean

Once upon a time computers were slow. Really slow. Software developers had to make a really concerted effort to optimize their code, seeking to use as few CPU cycles and as little memory as possible, today’s developers are spoiled in comparison. I am genuinely grateful that the guys who took me on after University taught me the difference between writing code and developing software, that they took the time to show me why there was so much more to it then getting stuff to build and run. These days I am responsible for putting potential new recruits at $place_of_employment through their paces with a C++ test, and as much as I’m looking for working code, I am also looking at coding style and often find myself saying things that were once said to me (I guess it’s kind of like finding yourself complaining about your kids music like your Dad used to do). I never cease to be amazed at how people with apparently years of experience can produce answers to such simple questions that require me to sit and analyse each line for minutes at a time in an attempt to try and uncover their secrets.

My penchant for clean code is a gift and a curse though. I was genuinely startled to be told by a fellow developer that code efficiency was something that embedded software engineers needed to worry about, but not us!?!

Satisfaction is the death of desire.

QSpacerItem: Stretched to breaking point

My days of using the Qt Designer application have trained me to define all QSpacerItems with a size hint of 1 by 1, a habit that I’ve yet to drop even though I no longer use Qt Designer. This week I was working on a GUI which requried a large horizontal spacer, around 2000px, but I could not get QSpacerItem to behave the way I wanted it to, it would stretch so far across the screen and then just stop. Long story short, it seems that QSpacerItems will only stretch so far beyond their size hint – defining the width of the size hint to 10000px resolved the problem. Virtual fist bump to El Jefe for having previously suffered this problem and remembering the fix. (Qt 3.3.8)

public class FakeButtonFrame : public QPushButton

So today I found myself fighting against the short comings of Qt 3.3.8, I should point out right from the off that I am fully aware of the existence of Qt 4.5.x (Mr Pandy is performing a port to 4.5.1 as I type), but for the project I was working on I had to use 3.3.8. I wanted to draw some QWidgets on to a mainly black, but multi coloured background without losing the nice curved corners. I am sure some of you are thinking that this sounds easy, but it is not as simple as you think. Qt 3.3.8 doesn’t support transparent backgrounds; the way in which the curved corners are achieved in standard Qt 3.3.8 GUIs is to ensure that the background colour of the widget matches that of the widget it is being placed on to. Setting the background colour of the widget to black worked for the most part, but not for the non black parts of the GUI where the black pixels in the corner of each right angle alerted everyone to their presence.

I subsequently discovered the real kicker to this conundrum was that only QPushButtons support foreground and background colours properly, meaning that the background colour trick did not work on the other widgets: they turned completely black. My frustration at this point was reaching fever point  and my sighs were audible enough for El Jefe to hear them and ask me a question that still leaves me horrified, “I wonder if you can you add widgets to a QPushButton?”. I could see what he was thinking, but I didn’t like it… surely it wouldn’t work… but it did… sort of. The fact that a QPushButton is a QWidget meant that adding a layout and widgets to a QPushButton was cake, creating my own subclass of QPushButton with a custom method to eat any mouse events ( virtual void nomNomNom( QMouseEvent* e ) ) was cake too, but preventing the button from responding to mouse overs like a QPushButton was not so easy. I disabled the button to prevent it from responding, performed a switcheroo on the active and disabled colour palettes, compiled, ran the code and discovered that disabling the button had Haitianed it – it had forgotten how to perform the foreground-background trick and  it turned black too!

Talk to the palm (and other things)

This isn’t a particularly well thought out post, more a general meandering through my thoughts, an aggregated thought feed if you will…

I absolutely cannot see what Palm hoped to achieve by reporting Apple to the USB-IF. Why not just integrate with iTunes in the same way as every other mobile phone/MP3 player/random application manufacturer, it almost seems like it’s more about the publicity and less about, well… there isn’t anything else to it is there.

Still no Snow Leopard friendly Growl. Grr.

What happened to webchunks? I was in the middle of preparing a software release, just calculating the checksums for the Win32 and Linux versions (ready to be documented in the release note) and then I discovered that the owner of webchunks had failed to put enough coins in the meter and so I had to transfer the checksums via a combination of text file and USB pen drive! Luckily the owner is a friend of mine and once I reported the service outage, he was on it in a flash (well once he returned from Chessington ;-) ).

I’m getting more and more addicted to twitter. I think it is so cool to be able to access the uncensored thoughts of so many people, an online Ben & Jerry’s in a world so full of vanilla. Having opinions isn’t a crime. At the moment, I am particularly enjoying following Jason Bradbury (him off the Gadget Show); Chris Jericho (current WWE superstar); Ken AndersonAnderson (former WWE employee, still a superstar, creator of the CTM TLA) and Becky Kingston, who I only know of through one of Jason’s #followfriday tweets.

See I could have tweeted all of this in much less time than it took to write this post, but then I couldn’t have used the bitchin’ title that made me CTM. Anyway, I’m off to watch the footie…

Post tune: Velvet Revolver, Slither, Contraband

Open for business?

Since the turn of this year, the government in the Netherlands has been required to utilize open source software and the [ISO ratified] ODF format for reading, publishing and exchanging information, there is some flexibility, but when open source software is not used, special reasons have to be given. I think this is a really important and positive step to have taken, since forcing a move away from the closed world of Microsoft Office guarantees that the people, groups and organizations that cannot afford an expensive Microsoft Office license, or those who use an OS not supported by Microsoft are not forced to either miss out on the information or use a pirated version of the software. Open Office (OOo) is available free of charge to users of Windows, Mac OS X and the various flavours of Linux, both for personal and business use, supports all of your old .doc Word files and is at least as secure as Microsoft Office.

So why do so many businesses insist on using Microsoft Office? “Because our customers do.”, just isn’t a good enough reason, seize the initiative and be a leader for once. You might like it.

After thought: As a software developer, I can understand that if your customer specifically asks you to produce code that can be built using Microsoft Visual C++ that you are obliged to do so (-ish), but that doesn’t mean that you have to use Microsoft Visual Studio. Why not make use of a cross platform, open source, IDE like Eclipse or NetBeans and just use the Visual C++ compiler? Expanding your CV with such transferable skills must surely be a good thing?

How to: make your OpenSuSE 11.1 VirtualBox VM bigger

When you set up a VirtualBox HDD you get two options, a fixed size disk, or a dynamically expanding one. Despite having no good reason for doing so, when I set up my OpenSuSE 11.1 VirtualBox VM I opted for the former; I created a 12Gb virtual disk and installed OpenSuSE 11.1 onto that. Long story short, it was a big mistake, 12Gb was nowhere near enough. So what to do? I didn’t want to have to do a clean install and set up a new development environment, so I looked for a way port my existing VM into a new dynamically expanding virtual HDD – I found one too, but since the process wasn’t as straight forward as you might think, I have included the steps that I used here.

  1. Create a new virtual HDD in VirtualBox. I would recommend that you create a dynamic one and set the capacity to something far larger than you will ever need – remember that it won’t actually take up this much space on your host system unless you actually fill it with stuff.
  2. Download SystemRescueCd.
  3. Modify the settings of your existing VM to have the new virtual HDD as its “IDE Primary Slave” and the SystemResuceCd iso as its CD.
  4. Boot the VM from the CD. If your VM won’t automatically boot from the CD, don’t forget to press <F12> to enter the Boot Menu and select it.
  5. Hit <Enter> to boot SystemRescue.
  6. Enter startx at the command prompt, this will start X Windows.
  7. When X Windows starts, type gparted in the terminal that is open on screen, this will start gparted.
  8. In gparted, right click on the first partition, /dev/sdb1, and select “Copy”.
  9. Select the new, larger HDD from the drop down (top right).
  10. Right click on the empty representation of the HDD and select “Paste”, you can use the slider to set the new size of the partition.
  11. Repeat steps 8-10 for the other partitions, /dev/sdb2 and /dev/sdb3.
  12. Select “Apply” (big green tick) from the toolbar.
  13. Wait for SystemRescue to do its stuff.
  14. Right click on the /dev/sdb2 partition on the new disk and select “Manage Flags”. Make sure the “boot” option is checked.
  15. Exit gparted.
  16. Exit the SystemRescue CD.
  17. Power off the VM.
  18. Download OpenSuSE 11.1.
  19. Create a new VM with the new HDD as its “IDE Primary Master” and the OpenSuSE 11.1 iso as its CD.
  20. Boot the new VM from the DVD and select “Rescue Mode”.
  21. Enter hdparm -i /dev/sda at the command prompt, this will pop up a bunch of information including the serial number of the new HDD – note this down.
  22. Enter mount /dev/sda2 at the command prompt, this will mount /dev/sda2 to /mnt.
  23. Using the editor of your choice (I used Vi), modify /mnt/etc/fstab and /mnt/boot/grub/menu.lst, replace all references to the old HDDs serial number with the new HDDs serial number. Be careful not to delete the -partx from each entry.
  24. Enter umount /mnt at the command prompt, this will unmount /dev/sda2. Make sure you aren’t in /mnt otherwise this command will fail.
  25. Power off the VM.
  26. Modify the settings of the new VM to remove the OpenSuSE 11.1 iso.
  27. Power on the new VM, which should now boot happily.

QString::null WTF!

I recently discovered the cause of a bug feature in some software that I wrote (Qt 3.3.8) and thought that I’d share the information since it feels like the sort of thing that lots of people might have done. Essentially, the problem was my assumption that QString::null is some sort of special value, it isn’t, it is just a reference to a static empty QString. Given this information, consider the following three QStringLists:

QStringList listOne = QStringList();
QStringList listTwo = QStringList( QString::null );
QStringList listThree = QStringList( "" );

If, like me, you assumed that QString::null was a special null value, then you might reasonably expect both listOne and listTwo to be empty QStringLists and listThree a QStringList containing a single empty QString. The reality is that listTwo is actually equivalent to listThree, so when you are tearing your hair out trying to work out why your nice empty QStringList has a length of 1, remember this post. You have been warned.

It is worth noting that QString::null has been deprecated as of Qt4.0 and calls to it now evaluate to seperate calls to QString(), I guess I wasn’t the only person that fell into this trap! I know that assumption is the Mother of all fuck ups, but I can’t help thinking that this could have all been avoided by naming it QString::empty instead.