Debuggeration

Not surprisingly there is a bug in my code. The segfault was a hint. So, like you do I sprayed printf()s all over the place and found a likely bit of code causing the trouble. I was trying to dereference a NULL pointer, so added a bit of code that said “if (!whatever) return”.

Which then shifted the crash up a level, so I attached a debugger and began stepping through the code, jumping over the error several times before remembering what I was doing. Debuggers really need an “undo” or “rewind” option for when you accidentally jump over the line of code causing the crash.

And now I know exactly where my code crashes and why. It crashes on the line where I attempt to call an object’s member function, except the object is really a NULL pointer.

The pointer should be NULL, the problem is the code shouldn’t even be running at this moment in time.

I hate recursive programming, it always bites me somewhere unexpected. Unfortunately it makes sense to parse a recursive data structure using a recursive function.

And I won’t ask why I can’t compare two std::string objects using ==, but .compare() works fine.

School's Out

So, it’s finished. I’ve survived my first school placement. It was interesting, difficult at times but mostly quite good. Onwards to my next one in January. Let’s see how different it is.

Thursday consisted of Student Review Day, where we talk to each person in our form and tell them what to do and how to improve their grades. Some of the kids were quite receptive to what we had to say, some just sat there and mumbled at us. There was even the odd parent.

Now sat at my cousin’s house typing this on his Intel MacBook which is quite nice, but feels like Linux with a different window manager. Nice small computer though, even if its keyboard does feel like typing on a ZX81.

GUI Programming

I have sought the wisdom of my as yet unwritten application, and it wants its own GUI writing.

So far I have a nice basic “GUI base object” that handles standard stuff like screen position and a bit of memory to draw onto. It also contains a list to put child objects in. The “draw” function iterates that list calling each child’s draw function.

Then I derived a “window” object which at the moment doesn’t do much beyond claim its own bit of graphics memory to scribble on and set up its size. Right now I’m not going for anything more advanced than a load of coloured boxes on the screen.

Now what’s a nice way to handle the drawing onto the screen? I’m using SDL and the way it works is to first create a main surface for your app. This gets done in the main function right when the program starts. I can then blit more surfaces onto this in a relatively painless way.

All my widgets need to draw themselves on this main surface, but how can I do this in a sane way? I could just pass a pointer to this into every object’s constructor but it seems inelegant.

Would it be better to have each object’s draw function return the allocated graphics surface, and build up the screen in chunks. English isn’t so good at explaining this, have some code…

Code:
Widget::Draw()
{
for (all widgets in our child list) {
blit (child.surface, this.surface, child,x, child.y, child.w, child.h)
}return this.surface;
}

with the top level doing this:

Code:
main()
{
screen = SDL_Initblah (800×600@32bpp);Window mainwind;

for (ever) {
process event loop
other stuff
mainwind.draw();
blit (mainwind.surface, screen, with-and-height);
}
}

This would need all object co-ords to be done relative to their parent window, but that’s normal anyway, isn’t it?

It's an Internet Go-slow

Got this email from my ISP…

Quote: My ISP
Dear Mr Piku,

Your peak-time usage for this billing month just exceeded 11GB.

Although this is not more than your allowance, we wanted to make you aware
of light restrictions to your connection speeds that come into force should
you reach 13GB. These restrictions help you to stay within your allowance,
and ensure that all customers receive the best possible quality of
service.

All I did was download the Fedora Core 6 DVD image twice, plus the usual downloadings and stuff that happen in a month. Turns out my ISP’s idea of “off peak” is 4PM till Midnight. Not the usual 9-5, Monday-Friday we all assume…