Eydeet
0
Hallo, ich habe folgendes Problem:
Jedes mal wenn ich mein selbst gebasteltes SDL-Spiel (ein Snakes-Clon) aufrufe, bekomme ich folgende Fehlermeldung:
Das Programm kompiliere ich mit folgendem Aufruf:
Das Seltsame ist: wenn ich das ganze mit dem C++-Compiler kompiliere (g++ statt gcc), dann läuft das Spiel wie es soll, nur wenn ich es beende erhalte ich diese Fehlermeldung:
Hier mein Spiel:
// Edit:
Sorry, ich hab die Versionsinformationen vergessen. Ich benutze
* gcc-4.1.2
* libsdl-1.2.11-r2
Jedes mal wenn ich mein selbst gebasteltes SDL-Spiel (ein Snakes-Clon) aufrufe, bekomme ich folgende Fehlermeldung:
Code:
Inconsistency detected by ld.so: dl-close.c: 164: _dl_close: Assertion `idx == nloaded' failed!
Code:
gcc -Wall -pedantic -lSDL worms.c -o worms
Das Seltsame ist: wenn ich das ganze mit dem C++-Compiler kompiliere (g++ statt gcc), dann läuft das Spiel wie es soll, nur wenn ich es beende erhalte ich diese Fehlermeldung:
Code:
Inconsistency detected by ld.so: dl-fini.c: 195: _dl_fini: Assertion `ns != 0 || i == nloaded' failed!
Hier mein Spiel:
Code:
#include <SDL/SDL.h>
#define G_W 70
#define G_H 50
#define B_W 15
#define PIXELS_PER_FRAME 5
/***************************************************
* SDL stuff
***************************************************/
SDL_Surface *screen;
SDL_Event event;
SDL_Rect p1, p2;
Uint32 p1Col, p2Col, bgCol;
/***************************************************
* game related
***************************************************/
char keepRunning = 1;
short p1Dir, p2Dir;
char map[G_H][G_W];
void init();
void handleKeys(int key);
void moveWorms();
void actWorm(SDL_Rect *p, short pDir);
void checkCollusion(SDL_Rect *p, short pDir, char checkAll);
void rePaint();
int main()
{
int untilDirChange = 0;
init();
while (keepRunning) {
if (untilDirChange == 0) {
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
keepRunning = 0;
} else if (event.type == SDL_KEYDOWN) {
handleKeys(event.key.keysym.sym);
}
}
checkCollusion(&p1, p1Dir, 1);
checkCollusion(&p2, p2Dir, 1);
untilDirChange = B_W / PIXELS_PER_FRAME;
}
if (p1Dir != -1 && p2Dir != -1)
moveWorms();
--untilDirChange;
/*SDL_Delay(1);*/
}
return 0;
}
void init()
{
int i, j;
if (SDL_Init(SDL_INIT_VIDEO) != 0)
printf("could not initalize SDL: %s", SDL_GetError());
SDL_WM_SetCaption("Worms-Clone", "Worms-Clone by FabiBausT");
screen = SDL_SetVideoMode(G_W * B_W, G_H * B_W, 16, SDL_HWSURFACE);
if (screen == NULL) {
printf("error while getting screen surface: %s", SDL_GetError());
}
/* colors */
bgCol = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00);
p1Col = SDL_MapRGB(screen->format, 0xff, 0x00, 0x00);
p2Col = SDL_MapRGB(screen->format, 0x00, 0x00, 0xff);
/* players */
p1.w = B_W;
p1.h = B_W;
p1.x = G_W * B_W / 3 - (G_W * B_W / 3) % B_W;
p1.y = G_H * B_W / 2 - (G_H * B_W / 2) % B_W;
p1Dir = -1;
p2.w = B_W;
p2.h = B_W;
p2.x = 2 * G_W * B_W / 3 - (2 * G_W * B_W / 3) % B_W;
p2.y = G_H * B_W / 2 - (G_H * B_W / 2) % B_W;
p2Dir = -1;
/* map */
for (i = 0; i < G_W; ++i) {
for (j = 0; j < G_H; ++j) {
map[i][j] = 0;
}
}
SDL_FillRect(screen, NULL, bgCol);
rePaint();
}
void handleKeys(int key)
{
switch (key) {
/* player 1 */
case SDLK_UP:
if (p1Dir != 2)
p1Dir = 0;
break;
case SDLK_RIGHT:
if (p1Dir != 3)
p1Dir = 1;
break;
case SDLK_DOWN:
if (p1Dir != 0)
p1Dir = 2;
break;
case SDLK_LEFT:
if (p1Dir != 1)
p1Dir = 3;
break;
/* player 2 */
case SDLK_w:
if (p2Dir != 2)
p2Dir = 0;
break;
case SDLK_d:
if (p2Dir != 3)
p2Dir = 1;
break;
case SDLK_s:
if (p2Dir != 0)
p2Dir = 2;
break;
case SDLK_a:
if (p2Dir != 1)
p2Dir = 3;
break;
}
}
void moveWorms()
{
actWorm(&p1, p1Dir);
actWorm(&p2, p2Dir);
rePaint();
}
void actWorm(SDL_Rect *p, short pDir)
{
switch (pDir) {
case 0:
p->y -= PIXELS_PER_FRAME;
break;
case 1:
p->x += PIXELS_PER_FRAME;
break;
case 2:
p->y += PIXELS_PER_FRAME;
break;
case 3:
p->x -= PIXELS_PER_FRAME;
break;
}
/* check for rushing into the wall */
checkCollusion(p, pDir, 0);
}
void checkCollusion(SDL_Rect *p, short pDir, char checkAll)
{
int mPosX, mPosY;
/* calculate worms' head on the map */
mPosX = p->x/B_W;
mPosY = p->y/B_W;
/* check for movements out of range */
if (p->x < 0 || p->y < 0 || p->x > G_W*B_W || p->y > G_H*B_W) {
SDL_Delay(1000);
init();
}
if (checkAll == 1) {
/* check for collusions */
if (pDir != -1) {
switch (pDir) {
case 0: mPosY--; break;
case 1: mPosX++; break;
case 2: mPosY++; break;
case 3: mPosX--; break;
}
if (map[mPosX][mPosY] < 0) {
SDL_Delay(1000);
init();
}
}
} else {
map[mPosX][mPosY] = -1;
}
}
void rePaint()
{
SDL_FillRect(screen, &p1, p1Col);
SDL_FillRect(screen, &p2, p2Col);
SDL_Flip(screen);
}
// Edit:
Sorry, ich hab die Versionsinformationen vergessen. Ich benutze
* gcc-4.1.2
* libsdl-1.2.11-r2