SDL wrapper problem

Started by
1 comment, last by lightkuragari 13 years, 4 months ago
Hi, everyone! this is my first post ever at gamedev.net.

I've known this page for some time now but never actually registered.
Now i have a big doubt about writing a C++ wrapper for SDL.

I wrote this code as a test:

=================================
#include <iostream>
#include <SDL/SDL.h>

using namespace std;

class Proto {
public:
Proto(){
}
virtual ~Proto(){

}
static int initialize(){
int result = SDL_Init(SDL_INIT_VIDEO);
return result;
}
};

int main(int argc, char* argv[]) {

Proto::initialize();

cout << "SDL Initialized!!!" << endl;
return 0;
}
====================================================

However, when i debug and step into Proto::initialize,
the program just freezes in SDL_Init.

If i call SDL_Init directly from the main() function
there's no problem. But if i encapsulate it in another class
whether in a static function or non-static member function,
it doesn't work.

If i continue execution, it never ends. I have to terminate it.

If i just execute the resulting binary(not debug) it starts
and ends without error message from console.

The message is never printed on screen.

What is going on? I'm doing this in eclipse on windows and mingw32.
Thanks!
Advertisement
Have you tried using a singleton with lazy initialization? I think that SDL redirects the call to main at the start of the program so it might be related to that.
I trust exceptions about as far as I can throw them.
Hi, storyyeller. Thanks for your answer. That's something new to me. Singleton and lazy initialization. Not sure how one implements that, though i read this
(C++ example part).

http://es.wikipedia.org/wiki/Singleton

However, i took my code in a linux VM and guess what? No problems with Linux GCC.
I also compiled my code under Visual C++ 2010 Express, and no problems either.

So i'm starting to think theres something wrong with my Mingw32 config, or with the compiler itself.

What do you think?

This topic is closed to new replies.

Advertisement