SDL 2| Error 3221225477

Hello, I'm trying to learn SDL 2.0. I understand that the error has to do with trying to access memory that has not been allocated, but I am absolutely uncertain on how to go about fixing this. Could anyone give some clues or answers if possible on how to fix the issue?

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
#include "SDL.h"
#include <stdio.h>
#include <iostream>
#include <string>

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

int main(int argc, char *argv[])
{
	if(SDL_Init(SDL_INIT_VIDEO) != 0)
	{
		std::cout << "SDL init error: " << SDL_GetError() << std::endl;
		return 1;
		SDL_Window *win = SDL_CreateWindow("My SDL window!", 100, 100, 640, 480, SDL_WINDOW_SHOWN);
		if (win == NULL)
		{
			SDL_DestroyWindow(win);
			std::cout << "SDL Window creation failed! Reason: " << SDL_GetError() << std::endl;
			SDL_Quit();
			return 1;
		}
		SDL_Renderer *ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
    if (ren == NULL){
	SDL_DestroyWindow(win);
	std::cout << "SDL_CreateRenderer Error: " << SDL_GetError() << std::endl;
	SDL_Quit();
	return 1;
}
	SDL_Surface *bmp = SDL_LoadBMP("lena512.bmp");
    if (bmp == NULL)
	{
	     SDL_DestroyWindow(win);
	     std::cout << "SDL_LoadBMP Error: " << SDL_GetError() << std::endl;
	     SDL_Quit();
	     return 1;
    }
    SDL_Texture *tex = SDL_CreateTextureFromSurface(ren, bmp);
    SDL_FreeSurface(bmp);
    if (tex == NULL)
    {
	SDL_DestroyWindow(win);
	std::cout << "SDL_CreateTextureFromSurface Error: " << SDL_GetError << std::endl;
	SDL_Quit();
	return 1;
    }
    SDL_RenderClear(ren);
    SDL_RenderCopy(ren, tex, NULL, NULL);
    SDL_RenderPresent(ren);
    SDL_Delay(2000);
    SDL_DestroyTexture(tex);
    SDL_DestroyRenderer(ren);
    SDL_DestroyWindow(win);
    SDL_Quit();
    return 1;
	}
}
Last edited on
Hi Tristan

I'm not at home right now and I do not see an obvious error, would you mind using the code tags?

You should be careful with using the VSYNC, I've had various issues with that flag.

Greets HalfNOoB
Last edited on
I'm not sure if passing a null pointer to SDL_DestroyWindow is allowed or not (the wiki doesn't say). Remove the first call to SDL_DestroyWindow in your code anyhow. It is not necessary to destroy any windows at that location because there are no windows to destroy.
Last edited on
Alright, I added in the code tags. @Peter87, I see what you mean, I removed that, still getting the error however.
Topic archived. No new replies allowed.