SDL1.2 on a raspbian pi2

I'm learning SDL on a raspberry pi2 (raspbian OS) and I'm following the tutorials over at http://lazyfoo.net/SDL_tutorials/
The line SDL_Init(SDL_INIT_EVERYTHING) is returning an error message.

What worries me is that even though it returns an error, the program itself seems to run without a problem. So has anyone else seen this and if so, did you fix it? Will it cause a problem later on?

I've tried running the executable as sudo, I've checked that my user is in the video group, and I've updated/upgraded my pi and checked that I'm using libsdl1.2-dev version 1.2.15 ... I don't know what else to check. Should I just ignore this error?
Last edited on
You mean SDL_Init returns -1 and you get an error message from SDL_GetError()? What does it say?
Should I just ignore this error?

What's the error?
Maybe SDL just can't load one of the Subsystems, if you don't need this subsystem you don't have to worry and just ignore it...

We can't help you without knowing what the error message is
SDL_Init(SDL_INIT_EVERYTHING) returns -1, but I don't get any output from SDL_GetError(). Their earlier tutorial codes didn't have a test for SDL_Init() failure, but when I applied it to an earlier code there was no error. So I'm doing something wrong in this next code, but I can't pick it out.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <string>
#include <iostream>
#include <SDL.h>

using namespace std;

const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int SCREEN_BPP = 32;

SDL_Surface *message = NULL;
SDL_Surface	*bkg = NULL;
SDL_Surface *screen = NULL;

class box
{
	private:

	public:
	box(int x, int y, int xx, int yy);
	int x1;
	int y1;
	int x2;
	int y2;

};
box::box(int x, int y, int xx, int yy)
{
	x1 = x;
	x2 = xx;
	y1 = y;
	y2 = yy;
}


SDL_Surface* loadImage(string fileName)
{
	SDL_Surface* loadedImage = NULL;
	SDL_Surface* optimizedImage = NULL;
	loadedImage = SDL_LoadBMP(fileName.c_str());
	if(loadedImage != NULL)
	{
		optimizedImage = SDL_DisplayFormat(loadedImage);
		SDL_FreeSurface(loadedImage);
	}
	return optimizedImage;
}

void applySurface(int x, int y, SDL_Surface* source, SDL_Surface* destination)
{
	SDL_Rect offset;
	offset.x = x;
	offset.y = y;

	SDL_BlitSurface(source, NULL, destination, &offset);
}

int main(int argc, char ** argv)
{
	if(SDL_Init(SDL_INIT_EVERYTHING) < 0);
	{
		cout << "SDL_Init Failed.\n";
		cout << "Error: " << SDL_GetError() << endl;
//		return 1;
	}

	screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE);
	if(screen == NULL)
	{
		cout << "SDL_SetVideoMode failed.\n";
		return 1;
	}
	SDL_WM_SetCaption("HelloW.bkgImage", NULL);
	message = loadImage("hello.bmp");
	bkg = loadImage("arrowLeft.bmp");
	box fxf(0,0,320,240);
	applySurface(fxf.x1, fxf.y1, bkg, screen);
	applySurface(fxf.x2, fxf.y1, bkg, screen);
	applySurface(fxf.x1, fxf.y2, bkg, screen);
	applySurface(fxf.x2, fxf.y2, bkg, screen);
	applySurface(fxf.x2 / 2, fxf.y2 / 2, message, screen);

	bool run = true;
	while(run)
	{
		fxf.x1 ++;
		fxf.x2 ++;
		fxf.y1 ++;
//		fxf.y2 ++;
//		SDL_Delay(50);
		if(SDL_Flip(screen) == -1)
		{
			cout << "SDL_FLIP (draw) failed.\n";
			return 1;
		}
		applySurface(fxf.x1, fxf.y1, bkg, screen);
		applySurface(fxf.x2, fxf.y1, bkg, screen);
		applySurface(fxf.x1, fxf.y2, bkg, screen);
		applySurface(fxf.x2, fxf.y2, bkg, screen);
		applySurface(fxf.x2 / 2, fxf.y2 / 2, message, screen);
		if(fxf.x1 >= SCREEN_WIDTH)
		{
			run = false;
		}
	}

	SDL_FreeSurface(message);
	SDL_FreeSurface(bkg);
	SDL_Quit();
	return 0;
}
You have a semicolon at the end of line 60 which makes line 61-65 not part of the if statement so they will run no matter what SDL_Init returns.
Topic archived. No new replies allowed.