I’m using SDL for almost 6 months, but only now I’m starting my own game
I’m having problems with SDL_PollEvent… everytime I use it, and it has
something on the queue, SDL quits returning: “SDL Parachute deployed”…
I’m using it on FreeBSD, SDL 1.1.1.
I’m using MacOS too, but I didn’t have a chance to test it yet.
Should I use SDL_WaitEvent? If I do, how can I keep my game going on,
without stopping everything?
Sorry for the newbie questions, but it’s my first attempt
I’m using SDL for almost 6 months, but only now I’m starting my own game
/me started Friday, and have an interesting (to me) beginning to a
reimplementation of a game I wrote a decade ago. SDL rules =) Anyone
interested in seeing a semi-test/semi-demo of a portion of it should
feel free to e-mail me.
I’m having problems with SDL_PollEvent… everytime I use it, and it has
something on the queue, SDL quits returning: “SDL Parachute deployed”…
Is it:
SDL_Event *event;
SDL_PollEvent( event );
or
SDL_Event event;
SDL_PollEvent( &event );
The latter works. The former croaks, since event hasn’t been allocated
yet. You’d need a 'event = (SDL_Event *)malloc( sizeof( SDL_Event ) );
or equivalent in there somewhere. I use the latter ;-)–
rot13 for e-mail: @Ex-Makron
The latter works. The former croaks, since event hasn’t been allocated
yet.
Not necessarily, unless the SDL code has been changed/fixed. I ran
into this problem myself, because I was doing the former (declaring a
pointer, not a struct), but it didn’t always croak. In fact, mouse
events seemed to work just fine! It was only when I hit a key (caused a
keyboard event) that my program segfaulted. Of course, this was with
SDL version 0.8, and I haven’t tested this under 1.0.x. Anybody else
seen this, or shall I try to re-create the case?
The latter works. The former croaks, since event hasn’t been allocated
yet.
Not necessarily, unless the SDL code has been changed/fixed. I ran
into this problem myself, because I was doing the former (declaring a
pointer, not a struct), but it didn’t always croak. In fact, mouse
events seemed to work just fine! It was only when I hit a key (caused a
keyboard event) that my program segfaulted. Of course, this was with
SDL version 0.8, and I haven’t tested this under 1.0.x. Anybody else
seen this, or shall I try to re-create the case?
It should always croak. What is happening is you are passing a pointer
into SDL that doesn’t point anywhere meaningful, so you are letting SDL
write into memory that is either not there (crash) or contains information
for some other part of your program (very hard to track bug).
Always use the latter method.
-Sam Lantinga (slouken at devolution.com)
Lead Programmer, Loki Entertainment Software–
“Any sufficiently advanced bug is indistinguishable from a feature”
– Rich Kulawiec
Not necessarily, unless the SDL code has been changed/fixed. I ran
into this problem myself, because I was doing the former (declaring a
You were just getting lucky. An uninitialized pointer is an
uninitialized pointer.
m.On Mon, Feb 14, 2000 at 07:32:47PM -0600, Nathan A. Yawn wrote:
–
Programmer "I wrote a song about dental floss,
Loki Entertainment Software but did anyone’s teeth get cleaner?" http://lokigames.com/~briareos/ - Frank Zappa, re: the PMRC
The pointer is fine. It simply doesn’t point to any allocated space
do a
SDL_Event event;
SDL_PollEvent(&event);
or if you are very pointer happy
SDL_Event * event;
event = malloc(sizeof(SDL_Event)); //allocate memory to the pointer
SDL_PollEvent(event); //should work
free(event); //because memory leaks are not fun to track down
/me started Friday, and have an interesting (to me) beginning to a
reimplementation of a game I wrote a decade ago. SDL rules =) Anyone
interested in seeing a semi-test/semi-demo of a portion of it should
feel free to e-mail me.
ok!
The latter works. The former croaks, since event hasn’t been allocated
yet. You’d need a 'event = (SDL_Event *)malloc( sizeof( SDL_Event ) );
or equivalent in there somewhere. I use the latter
I’ve used both
Sam has explained already… It seems that it’s a bug on FreeBSD’s library.
No problem… i just tested it on Windows, Linux and MacOS… everything
works quite nicely :))
Not necessarily, unless the SDL code has been changed/fixed. I ran
into this problem myself, because I was doing the former (declaring a
pointer, not a struct), but it didn’t always croak. In fact, mouse
events seemed to work just fine! It was only when I hit a key (caused a
keyboard event) that my program segfaulted. Of course, this was with
SDL version 0.8, and I haven’t tested this under 1.0.x. Anybody else
seen this, or shall I try to re-create the case?
: “Eduardo B. Fonseca” wrote:
: >
: > I’m using SDL for almost 6 months, but only now I’m starting my own
game
: >
:
: /me started Friday, and have an interesting (to me) beginning to a
: reimplementation of a game I wrote a decade ago. SDL rules =) Anyone
: interested in seeing a semi-test/semi-demo of a portion of it should
: feel free to e-mail me.
I would be interested in looking at a semi-test/semi-demo. I love
studying games and what people have come up with, it’s always nice to be
able to help out in the critique process too
I notice when I run my game that it uses up all my cpu. Is it because I am polling an event with SDL_PollEvent? If so, what should I do?
Thanks,
Rafik
At the end of your infinite loop you should have a SDL_Delay with a small (10) to average (100) value (note that these are milliseconds). This halts your program for a small amount of time and shares the CPU with other application so multitasking can live long in prosper
Have fun,
Daniel Schneidereit
Code example:
int main(void)
{
SDL_Event event;
if(SDL_Init(SDL_INITEVERYTHING) != 0)
{
return 1;
}
while(1)
{
while(SDL_PollEvent(&event))
{
// Process event further
}
// Sleep for 25 milliseconds
SDL_Delay(25);
}
SDL_Quit();
return 0;