When I leave it as is (no & or *) then the game crashes as soon as the
function is called.
However, if I make it a & or *, and make the proper adjustments, it
crashes when it gets
to the switch statement (attempting to access event.type or
event->type). I can’t get
more specific than that since I am unsure what possible reasons there
could be for
either problem.
-TomT64
Hi,
Take a look at this, and notice the definition of the SDL_Event in Run(), and
how it gets passed around. How does this compare with your (as yet unseen)
code?
File: event-test.c
----------------------------------------------------------->8-------------
#include “stdlib.h”
#include “SDL.h”
static int MyHandleEvent(const SDL_Event *event)
{
switch (event->type) {
case SDL_QUIT :
return 0;
case SDL_KEYDOWN :
if (event->key.keysym.sym == SDLK_ESCAPE)
return 0;
break;
}
return 1;
}
static int Run()
{
SDL_Event event;
while(SDL_PollEvent(&event))
{
if ( !MyHandleEvent(&event) ) return 0;
}
return 1;
}
#define SC_WIDTH 640
#define SC_HEIGHT 480
#define SC_BPP 16
int main(int argc, char *argv[])
{
SDL_Surface *screen;
if((SDL_Init(SDL_INIT_VIDEO) == -1))
{
printf("Could not initialize SDL: %s.\n", SDL_GetError());
exit(1);
}
atexit(SDL_Quit);
screen = SDL_SetVideoMode(SC_WIDTH, SC_HEIGHT, SC_BPP, SDL_SWSURFACE);
if (screen == NULL)
{
printf("Couldn't set %dx%dx%d video mode: %s\n",
SC_WIDTH, SC_HEIGHT, SC_BPP, SDL_GetError());
exit(2);
}
while(Run()) SDL_Delay(1);
SDL_Quit();
return 0;
}
/* gcc -Wall event-test.c sdl-config --cflags
sdl-config --libs
*/
---------8<---------------------------------------------------------------
hope that helps,
cheers,
John Popplewell.On Thursday 09 September 2004 07:00, TomT64 wrote:
Donny Viszneki wrote:
On Sep 8, 2004, at 6:23 PM, Alan Wolfe wrote:
try changing it to…
int MyPollEvent(SDL_Event &event)
TomT64 said he already tried that.
On Sep 8, 2004, at 6:06 PM, TomT64 wrote:
I have tried changing the prototype to both
MyPollEvent(SDL_Event& event),
Tom, nothing you have shown us would suggest a problem. You’ve
probably made some sort of mistake, if you want help, you should show
us more. If you trace your code and see where it crashes I would guess
it would probably become fairly obvious to you what the problem is.
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl