We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3106 - SDL_CreateRenderer sets bogus error
Summary: SDL_CreateRenderer sets bogus error
Status: RESOLVED INVALID
Alias: None
Product: SDL
Classification: Unclassified
Component: render (show other bugs)
Version: 2.0.3
Hardware: x86_64 Linux
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-08-27 01:48 UTC by Raymond Jennings
Modified: 2016-05-11 21:19 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Raymond Jennings 2015-08-27 01:48:22 UTC
SDL_CreateRenderer is spuriously setting the current SDL error even when it returns a valid renderer.

triggering code:

SDL_Window *gamewindow;
SDL_Renderer *gamerenderer;
unsigned short width, height;

void check_error(const char *function)
{
	const char *errmsg;

	errmsg = SDL_GetError();

	if (strlen(errmsg)) {
		cout << "Error calling " << function << ": " << errmsg << endl;
		exit(1);
	}
}

static void setup_sdl()
{
	width = 32 * 16;
	height = 32 * 12;

	SDL_Init(SDL_INIT_VIDEO);
	check_error("SDL_Init");

	IMG_Init(IMG_INIT_PNG);
	check_error("IMG_Init");

	gamewindow = SDL_CreateWindow(
		"RPG Studio - (whatever your game is called here)"
		, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED
		, width, height, SDL_WINDOW_RESIZABLE);
	check_error("SDL_CreateWindow");
}

static void create_renderer()
{
	assert(!bubbletexture);
	assert(!gamerenderer);

	cout << "Creating renderer" << endl;

	check_error("NULL");
	gamerenderer = SDL_CreateRenderer(gamewindow, -1, SDL_RENDERER_SOFTWARE);

	if (!gamerenderer) {
		cout << "Got NULL gamerenderer" << endl;
		check_error("SDL_CreateRenderer");
	} else {
		if (strlen(SDL_GetError())) {
			cout << "Bogus SDL error: " << SDL_GetError();
		}
		SDL_ClearError();
	}
}

int main(int argc, char *argv[], char *envp[])
{
	setup_sdl();

	create_renderer();
}
Comment 1 Philipp Wiesemann 2015-08-30 18:44:58 UTC
The value returned by SDL_GetError() is undefined if the called SDL function did not return a failure (the value is not necessarily reset).

See also: https://wiki.libsdl.org/SDL_GetError
Comment 2 Ryan C. Gordon 2015-08-31 02:48:54 UTC
Yes, not a bug.

--ryan.
Comment 3 Raymond Jennings 2015-08-31 03:01:59 UTC
Even if you call SDL_ClearError before you make the call in question?
Comment 4 Philipp Wiesemann 2016-05-11 21:19:55 UTC
SDL_ClearError() does not help because some functions internally try other functions which may set error messages (the description in the wiki was wrong here).