After my recent rethink on agility, this weekend saw me finally start to cut some code! Time was short so I had to really focus on what I wanted to achieve. I decided to start with something that would give me visual feedback - rendering of the grid but I actually started one step back from that.
I know I'm going to use SDL for rendering in general and wxWidgets for specific Gui elements such as buttons and text boxes. The tricky thing is that wxWidgets wants to take over your application (stop you having a main function) so combining the two libraries requires a little rework of the usual model. Thankfully, somebody wrote a tutorial on doing just that which I used as my starting point. It didn't quite work but I was able to fix it quite easily.
The main problem lies in the SDLApp class. The OnInit function creates a frame and makes it the top window. In the OnRun function which is invoked after OnInit there is a call to SDL_Init followed by some code to create an event to get the event loop running. The problem here is that the call to SDL_Init causes an infinite loop. SDL is used in the SDLPanel class which owns a pointer to an SDL_Surface used for the drawing. The SDLPanel::OnPaint function is called whenever the panel needs to be updated and if you look at the code you'll see that if the surface hasn't been initialised the function returns.
The problem is that because the frame has been made a top window in the OnInit function of SDLApp, this causes the panel class to try and paint itself, but SDL hasn't been initialised yet so it can't. So the window hasn't been drawn, OnPaint gets fired again and round and round we go. Thus the code after that to create the event never gets executed, no event is created, there is no event loop and the application hangs. To fix this, I got rid of OnInit and moved the frame initialisation code to OnRun after the call to SDL_Init. That fixed the problem but there were still issues.
I got two windows being displayed and the spurious one tried to take up the whole screen. The tutorial says that called SDL_SetVideoMode with zeros for the size suppresses the creation of the window. I don't know how old the tutorial code is but on my system it does no such thing - the window is created anyway. I simply removed this call and the app worked fine.
It worked fine on my Windows box anyway! Now that I have committed myself to doing this cross-platform I needed to try and build it on Fedora. Unfortunately I soon realised that I would have to build wxWidgets on that too (eurgh!) and I can't remember how I did it on Windows never mind on Linux! I should have blogged that bit in more detail!
Well that's enough for one day. At least I got some code working - I'VE STARTED!
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment