Sign in to follow this  
Madster

any use for SDL user events besides error handling?

Recommended Posts

Madster    242
I've set up a simple error reporting system using custom events. The user event structure was used in the following way: code : severity of error (from an enum: info, warning, error, critical, fatal) data1 : string containing name of the system that sends the message data2 : string containing a description of the issue Now the thing is i've just hogged all user events by doing this. Will I miss them later on development? what other uses can they have? (besides sending an exit message to the main loop?)

Share this post


Link to post
Share on other sites
Drew_Benton    1861
One idea is wouldn't you rather just log everything instead? I was first thinking about making my own error handling system using messages and with custom logging and all - then I stumbled upon the free logger class from Fluid Studios. All you have to do is put
LOG("String Here");
And that's it! If you are going to abort or exit, then you might want to close the log file first though. This is just some comments about error handling, feel free to do it however you want though - I know you are not asking about error handling, but wanted to let you know of a great tool you could use. [smile].

Now as for SDL user events use. I really do not think so. I mean most of anything you could want to do can be accompished through other ways rather than filling up the message queue. It's kind of like the windows WM_USER events. You might only use them for like one or two things once in a blue moon, and that's it. If you decide to use them all up now, I would highly doubt it could come back and haunt you. I could not really think of anything other than error handling off the top of my head right now.

- Drew

Share this post


Link to post
Share on other sites
Madster    242
in mine you go
Log(warning,"OpenGL","X happened");

and you get this in the log:
Warning from module OpenGL: X happened

=) the only detail is that once you do SDL_Quit, you can't keep using it.

Share this post


Link to post
Share on other sites
Drew_Benton    1861
Quote:
Original post by Madster
in mine you go
Log(warning,"OpenGL","X happened");

and you get this in the log:
Warning from module OpenGL: X happened

=) the only detail is that once you do SDL_Quit, you can't keep using it.


[smile] Awesome! Right now in my audio library I mixed the logging with lots and lots of aborts [lol]. So if something goes wrong, you sure as heck are gonna know it! In my last library I did something similar to what you have done. I made a macro function that let me specify the log level, custom error message, and a remedy. If I specified release version, everything was compiled out to save speed and efficiency, for that logger sure does add some size. That is one good thing about making your own though. If I only had the time... Good luck on your project!

- Drew Benton

Share this post


Link to post
Share on other sites
Madster    242
It was really simple... might as well explain it, turned out much simpler than i thought it would.

Just tossed a global function Log that shoves the event in the SDL queue
and then tossed another global function that looks for the custom event: something like LogErrorEvent(const SDL_Event *event)
and it logs to cerr parsing with a simple switch structure.

Took about 15 minutes to code. Really. Took me longer to figure out some silly dependencies i had. Winded up tossing them in their own namespace in their own file pair (.cpp .h)

The only detail with it is that you gotta remember that SDL_Quit jumps at the front of the queue, and during shutdown you gotta keep processing events so if there's any errors they get logged. Im still thinking about that one. Ideas would be appreciated ;)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this