Fixing the Fedora 12 VirtualBox Guest Additions problem

I’m a frequent VirtualBox user, and as I’ve noted in my previous posts, I’m an avid fan of Fedora as well.

However, there is a nasty bug in the most recent version of VirtualBox (3.1.2) when combined with Fedora 12. After installing the Guest Additions kernel modules as per the user docs, the system boots to a black screen with a cryptic error message that looks like a SELinux labeling problem (it’s not).

type=1305 audit(12587840002.571:32444): audit_enabled=0 old=1 auid=4294967295 ses=4294967295 subj=system_u:system_r:readahead_t:s0 res=1

The problem is actually with the Guest Additions video driver, the one that gives you the nice resizable desktop window. Once the driver is built and installed, for some reason the X server can’t find any screens and refuses to start.

Until the bug gets fixed in the video driver, here’s how you can fix the system so that it will boot correctly, although you’ll lose the dynamic resizing ability. You’ll have to stick with fixed, predefined resolutions for now.

  1. Mount a Fedora 12 ISO, such as the full or network install discs, and boot to it. Boot into Rescue Mode from the GRUB bootloader screen.
  2. Breeze through the language and network options, but be sure to have it mount your hard disk image (it will mount under /mnt/sysimage).
  3. Drop into a shell and change into your hard disk’s X11 config directory, so that would be:
    cd /mnt/sysimage/etc/X11
  4. Edit your xorg.conf file… but wait! In Fedora 12, they switched to HAL for X configuration, so there is no xorg.conf file! Never fear, you just need to create one and it will override the HAL:
    vi xorg.conf
  5. Now, use the following settings for the new xorg.conf file:
    Section "Device"
        Identifier "Configured Video Device"
        Driver "vboxvideo"
    EndSection
    
    Section "Monitor"
        Identifier "Configured Monitor"
    EndSection
    
    Section "Screen"
        Identifier "Configured Screen"
        Monitor "Configured Monitor"
        Device "Configured Video Device"
        SubSection "Display"
            Depth 24
            Modes "1440x900" "1680x1050"
        EndSubSection
    EndSection
    
    Section "InputDevice"
        Identifier "vboxmouse"
        Driver "vboxmouse"
        Option "CorePointer"
        Option "Device" "/dev/input/mice"
    EndSection
    
    Section "ServerLayout"
       Identifier   "Default Layout"
       Screen      "Configured Screen"   0 0
       InputDevice   "vboxmouse"
    EndSection
    
  6. You’ll see I’ve defined two resolutions, 1440×900 and 1680×1050. What this allows me to do is work windowed at 1440×900 and if I want to go full screen (remember, dynamic resizing won’t work) I can hit the full screen shortcut in VirtualBox (Host+F) and change the resolution within Fedora to match my screen res.
  7. Save from vi (:wq) and reboot the system. Remember to unmount the install disc! The system should boot correctly now, albeit without dynamic resizing.

A huge thanks goes out to Jits in the VirtualBox forums for this fix!

Posted in Linux | 5 Comments

Include dependencies

Generally when I write software, I try to keep things relatively well organized. Inevitably, however, things are going to get a bit messy, especially if you’re working on a large, disorganized codebase that you didn’t write to begin with… say, oh… something like the Source SDK.

Frequently you have some class which is composed inside another class, but occasionally needs to access the class it’s composed inside of. Basically, the classes are composed inside each other, though the abstraction really only makes sense in one direction. Confused yet?

In this example, we’ll use a Refrigerator class which stores inside it an instance of a Cheese class. Why cheese, you ask? Because cheese is delicious. Also, our refrigerator is from the future and can slice and serve cheese just like the built in ice maker and water dispenser. It’s a pretty sweet fridge.

Now, we were all taught to keep our #includes in our header files, not the implementation files, so like good little programmers we construct our classes like so:

refrigerator.h

#include "cheese.h"

class Refrigerator {
private:
    Cheese *pCheese;
    int temp = 35;

public:
    void ServeCheese();
    int GetTemp();
};

refrigerator.cpp

#include "refrigerator.h"

void Refrigerator::ServeCheese() {
    printf("Now dispensing %s cheese!\n", pCheese->GetFlavor());
}

int Refrigerator::GetTemp() {
    return temp;
}

cheese.h

class Cheese {
private:
    Refrigerator *pFridge;
public:
    char *GetFlavor();
    void CheckTemp();
    void BeginMolding();
};

cheese.cpp

#include "cheese.h"

void Cheese::CheckTemp() {
    if (pFridge->GetTemp() > 45) {
        BeginMolding();
    }
}

char *Cheese::GetFlavor() {
    return "cheddar";
}

I’ve left out the constructors in this example for brevity, but let’s assume that they get the pointers set up correctly so that our instance of the Refrigerator class has a correct pointer to an instance of the Cheese class and vice versa.

Now, at this point you may be screaming that this needs to be refactored and reorganized. Yes, it probably does. But there are many instances where you simply can’t, and in fact the abstraction really only makes sense one way. The fridge has cheese in it, but the cheese certainly doesn’t have a fridge in it. We just need that pesky reference around so we can check the temperature of the fridge every so often.

(Yes, I am aware that the fridge could push it’s temperature down to all the items in it, ala the Observer Pattern. Yes I am aware that would be a better solution. But this is a contrived example anyway, so stick with me here.)

Now, the code given above doesn’t compile, because the Cheese class has no idea what the heck this Refrigerator class is, so we either need to include it or forward declare it. If we try to do this:

cheese.h

#include "refrigerator.h"

our compiler (more specifically, the preprocessor) is going to get very angry at us, depending on which order it decides to compile refrigerator and cheese. The solution, is a forward delcaration:

cheese.h

class Refrigerator;

class Cheese {
    // ...etc...
};

Basically what this does is tell the compiler, “Hey! There’s this class called Refrigerator that I might talk about, so here’s an empty declaration of it!”

The problem, though, is that this is rather limiting. Within the Cheese class, we can declare pointers to Refrigerator class, no problem. Pointers are of fixed size, so the compiler doesn’t much what care what it’s a pointer to, since it knows how much memory it needs to hold a pointer to it. When we try to access members of the class, though, like properties or methods, it falls apart because as far as the compiler knows, the class is empty. After all, we told it the Refrigerator class didn’t have anything in it.

So if we can’t #include it and forward declaring it doesn’t give us what we want, what can we do?

Well, we can do both. Kind of.

The solution is to forward declare in your header file, and #include in your implementation file. This will avoid the preprocessor headaches of of the chicken and egg #include, while allowing us to access the members of forward declared class in the implementation. In other words, here’s the fix:

cheese.h

class Refrigerator;

class Cheese {
    ...
};

cheese.cpp

#include "cheese.h"
#include "refrigerator.h"

Again, it goes without saying, the better solution is to refactor or rearchitect your code if you can. These kind of hacks can get really out of hand and are usually a good code smell that something needs to be fixed at a deeper level. However, if you’re working on a large codebase that you can’t change, this can help out a lot.

Posted in C/C++, Code | Leave a comment

Removing entities in the Source SDK

I haven’t written for a while, mainly because I’ve been busy with classes and studying for the GRE for my grad school applications, but here’s a quick tip for those of you meddling around with the Source SDK.

It’s well documented on how you go about spawning entities, but I couldn’t find a good place explaining how to remove spawned entities through code.

Don’t try meddling with the global entity list (gEntList) or calling its RemoveEntity() method. It doesn’t do what you want.

Instead, used one of the super-handy UTIL_* functions. Given a pointer to the entity you want to remove, simply use:

UTIL_Remove(pEntity);

Poof. Entity gone. Remember, entities are created and destroyed on the server side only. The server will automatically broadcast any changes to the entity list to its connected clients for you.

Posted in C/C++, Code, Gaming | Leave a comment

Dual videocards without SLI

I just recently upgraded my workstation to a quad monitor setup, because you can never have enough screen real estate. I originally had a dual-monitor setup on a single videocard, an nVidia GeForce 8800 GT.

A friend of mine sold me 2 older 19″ flat panels for just $50, but I needed a second videocard to drive the extra displays. Although I absolutely detest shopping there and I avoid it at all costs, I picked up a GeForce 9800 GT from Best Buy. Don’t worry, it was on sale so I was getting screwed slightly less than usual.

Interestingly enough, the 9800 is practically identical to the 8800. The two biggest differences are the move to the smaller manufacturing process (55nm from 65nm) and an updated BIOS on the card. This particular model is made by PNY and is tagged with an “EE” at the end to denote that it’s an “Energy Efficient” edition. Basically it means that it doesn’t require the standard 6-pin PCI-E graphics card power connection from your PSU. It draws all of it’s power (only 66 watts under full load!) from the PCI-E bus. Thankfully my 550 watt power supply is beefy enough to drive both cards without breaking a sweat.

Installation was simple enough. Getting Windows XP to recognize the second card was another story, though.

See, what you’re supposed to be able to do is just drop the card into the second slot and when you reboot, Windows will happily say “Wow, cool, nice new videocard! Lemme install those drivers for ya so you can get started experiencing multi-monitor bliss!” In fact, my copy of Windows just said “New videocard? Huh? Nobody tells me nutin’.”

And thus the issue debugging begins. I really hate this part.

First up was checking that the card was seated correctly. In the process of reseating the card, I noticed a small daughter card between my videocard slots that allowed you to specify if you were using single or dual videocards. “Sweet,” I thought, “this is the problem right here. I swapped the daughter card around to “dual videocards”  and booted up the rig.

No dice.

Next I thought perhaps the nVidia drivers only detected new cards when they were installed. I wiped off the current nVidia drivers and downloaded the latest copy. After reinstalling the video drivers, Windows still had no idea the second videocard was even there.

As I was double checking my motherboard manual to make sure dual videocards without SLI was indeed supported, I noticed that when one card is installed it runs at 16x speed. When two cards are installed, however, it splits the PCI-E bus and runs both cards in x8. “Perfect,” I thought, “I’ll just check the bus speed to see if the motherboard even sees the card.”

After locating the window in the nVidia control panel that shows you the PCI-E bus stats, I verfied that indeed, my single card (the 8800 GT) was running in x8. The motherboard was detecting the second card.

By this point, you’re probably wondering why I was using the 9800 GT (the newer card) as my secondary graphics card and the older 8800 GT as the primary card.

The only negative comment I found when looking through reviews of the PNY 9800 GT EE was that for some reason the fan seemed locked to 45% speed. Normally the fan spins up as necessary to cool off  the card under higher load, but this card didn’t seem to do that. You can adjust the fan speed manually through the nTune software, but I didn’t particularly feel like adjusting this every time I played a game, or have my computer sound like a Harrier jet 24/7. (It already sounds like a idling tractor.) Since the cards are practically identical performance-wise, I figured I’d leave the 8800 pulling gaming duty while the 9800 only had to push out the pixels to the 2 new monitors.

Since the 9800 wasn’t being detected by Windows, I then figured that maybe I’d try swapping the cards. After installing the 9800 in the primary slot and the 8800 in the secondary slot, I was greeted to a driver installation of my 9800, but my 8800 was nowhere to be found. At this point, I was seriously worried that somehow my motherboard’s second PCI-E slot was unusable.

I gave it one last hurrah and swapped the cards back. As soon as I booted up, I was greeted by nVidia’s multi-monitor setup wizard and Windows dutifully installing the 9800 drivers again. All four monitors were working.

Moral of the story: If your secondary card isn’t getting detected, install it in the primary slot and give Windows a chance to see it and install the drivers. Then swap it back to the secondary slot.

Lastly, this post couldn’t possibly be complete without pictures!

Four monitors means I can get my LCD tan 4 times quicker. I better get some more sunscreen!

Four monitors means I can get my LCD tan 4x quicker!

Playing Team Fortress 2 across three screens is only one of many uses!

Playing Team Fortress 2 across three screens is only one of many uses!

If you’re feeling particularly brave, check out these screenshots to see what I’m seeing when I play Team Fortress 2. Thanks to the SoftTH utility, I can get triple head gaming without the Matrox hardware adapter!

plr_pipeline as Pyro with SoftTH

plr_pipeline as Pyro with SoftTH

plr_pipeline as Soldier with SoftTH

plr_pipeline as Soldier with SoftTH

Posted in Gaming, Hardware | Leave a comment

Awesome regex test tool

So I’m working with a friend to develop a regex that matches something out of an API response, when we really wish we could quickly prototype a regex. Now, there are plenty of tools to do this, some are even freeware, but all them need to be downloaded and installed. I realize it sounds pathetic to say that I was too lazy to download and install a tool, but to be honest I really don’t need more tiny, rarely-used apps cluttering up my system. There’s got to be a web-based tool to do this, I thought.

Google did not disappoint. I found this awesome web-based regex test tool built on Adobe Flex called RegExr. If you’ve got Flash installed, it runs right in your browser.

Not only does it show you what it’s matching live as you type, what your match groups contain, what each chunk of your regex means, etc., but it’s also got a phenomenal quick-reference sidebar for all those handy meta-characters. You can even save your favorite regexs and browse other people’s favorite submissions.

We need more tools like this. I was able to quickly and easily prototype a regex in no time at all, and the app took about 10 seconds to figure out how to use.

Thanks, gskinner.com! You guys are awesome!

Posted in Code, Tools, Web | Leave a comment