SDL problem
Moderator: Coders of Rage
- Ginto8
- ES Beta Backer
- Posts: 1064
- Joined: Tue Jan 06, 2009 4:12 pm
- Programming Language of Choice: C/C++, Java
Re: SDL problem
ok what I see is that you're trying to dereference a pointer that points to memory location 0xC. 0xC is 12 in decimal. That means that it isn't trying to access NULL, but it also means that somewhere, your pointer gets screwed, because I don't think it's likely that any non-system program will access a memory location so low. Check ALL your pointers. EVERY ONE. Preferably their runtime values, with the debugger. If you can figure out which is causing the issue, you can figure out what chunk of code is the problem, and then you can fix the problem.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
-
- Chaos Rift Cool Newbie
- Posts: 85
- Joined: Wed Mar 17, 2010 4:32 pm
Re: SDL problem
That's the problem, i tried flowing wich code does the problem, and what i ended up with, is that even the simplest of all codes:Ginto8 wrote:ok what I see is that you're trying to dereference a pointer that points to memory location 0xC. 0xC is 12 in decimal. That means that it isn't trying to access NULL, but it also means that somewhere, your pointer gets screwed, because I don't think it's likely that any non-system program will access a memory location so low. Check ALL your pointers. EVERY ONE. Preferably their runtime values, with the debugger. If you can figure out which is causing the issue, you can figure out what chunk of code is the problem, and then you can fix the problem.
Code: Select all
#include "SDL.h"
SDL_Surface *screen = NULL;
SDL_Event Event;
int main (int argc, char *argv[])
{
SDL_Init(SDL_INIT_VIDEO);
screen = SDL_SetVideoMode(640,480,0,SDL_ANYFORMAT);
SDL_Surface *img = SDL_LoadBMP("a.bmp");
SDL_Surface *ConvertedImg = SDL_ConvertSurface(img,screen->format,SDL_HWSURFACE);
while (true)
{
if (SDL_PollEvent(&Event) == 0)
{
}else{
if (Event.type == SDL_QUIT)
break;
}
}
return 0;
}
Edit: The img isn't the problem. even when i removed it, the error is still there.
- RyanPridgeon
- Chaos Rift Maniac
- Posts: 447
- Joined: Sun Sep 21, 2008 1:34 pm
- Current Project: "Triangle"
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C/C++
- Location: UK
- Contact:
Re: SDL problem
Code: Select all
#include "SDL.h"
SDL_Surface *screen = NULL;
SDL_Event Event;
int main (int argc, char *argv[])
{
SDL_Init(SDL_INIT_VIDEO);
screen = SDL_SetVideoMode(640,480,0,SDL_ANYFORMAT);
SDL_Surface *img = NULL;
img = SDL_LoadBMP("a.bmp");
if (img == NULL) return 1;
SDL_Surface *ConvertedImg = SDL_DisplayFormat(img);
while (true)
{
if (SDL_PollEvent(&Event) == 0)
{
}else{
if (Event.type == SDL_QUIT)
break;
}
}
return 0;
}
-
- Chaos Rift Cool Newbie
- Posts: 85
- Joined: Wed Mar 17, 2010 4:32 pm
Re: SDL problem
That's weird, when i run it through the debugger, it runs and then exits, the value returned is 1 (even when the img is in the same directory.) but when running from the actual EXE, it works. does the debugger run the software from a different location and can't find the img?RyanPridgeon wrote:See if that works. If it's returning 1 then it's not loading the BMP succesfully. If it runs then you were doing something wrong in the convert format function, which I haven't looked into and have never used, but SDL_DisplayFormat converts it to the same format as the display, which it looks like you were trying to do yourself, so it would be fine like this.Code: Select all
#include "SDL.h" SDL_Surface *screen = NULL; SDL_Event Event; int main (int argc, char *argv[]) { SDL_Init(SDL_INIT_VIDEO); screen = SDL_SetVideoMode(640,480,0,SDL_ANYFORMAT); SDL_Surface *img = NULL; img = SDL_LoadBMP("a.bmp"); if (img == NULL) return 1; SDL_Surface *ConvertedImg = SDL_DisplayFormat(img); while (true) { if (SDL_PollEvent(&Event) == 0) { }else{ if (Event.type == SDL_QUIT) break; } } return 0; }
- RyanPridgeon
- Chaos Rift Maniac
- Posts: 447
- Joined: Sun Sep 21, 2008 1:34 pm
- Current Project: "Triangle"
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C/C++
- Location: UK
- Contact:
Re: SDL problem
Yes, haha. I thought this might be the problem. When you run your project from inside your IDE, it's often a different working directory. The working directory is basically what you described. You can probably find it in your IDE options somewhere, or you can just stick your images in the IDE's working directory.Avishaiozeri wrote:That's weird, when i run it through the debugger, it runs and then exits, the value returned is 1 (even when the img is in the same directory.) but when running from the actual EXE, it works. does the debugger run the software from a different location and can't find the img?RyanPridgeon wrote:See if that works. If it's returning 1 then it's not loading the BMP succesfully. If it runs then you were doing something wrong in the convert format function, which I haven't looked into and have never used, but SDL_DisplayFormat converts it to the same format as the display, which it looks like you were trying to do yourself, so it would be fine like this.Code: Select all
#include "SDL.h" SDL_Surface *screen = NULL; SDL_Event Event; int main (int argc, char *argv[]) { SDL_Init(SDL_INIT_VIDEO); screen = SDL_SetVideoMode(640,480,0,SDL_ANYFORMAT); SDL_Surface *img = NULL; img = SDL_LoadBMP("a.bmp"); if (img == NULL) return 1; SDL_Surface *ConvertedImg = SDL_DisplayFormat(img); while (true) { if (SDL_PollEvent(&Event) == 0) { }else{ if (Event.type == SDL_QUIT) break; } } return 0; }
Note that no matter what the IDE does, when you run that exe OUTSIDE the IDE, the working directory will always be where the EXE is located.
Edit: For Codeblocks and Dev - C++, the default working directory for a project is the directory that your project file is located. For example, if your project is called Foo, then you have to put the images in the folder called Foo. I have limited experience for Visual Studio so I cannot recall where it is if you're using that, but I imagine it's similar if not the same.
-
- Chaos Rift Cool Newbie
- Posts: 85
- Joined: Wed Mar 17, 2010 4:32 pm
Re: SDL problem
But how does it successful locate the SDL.dll when i put it where the EXE is (and the img too) (or maybe the transition of the location is after the initial setting of the program?)RyanPridgeon wrote:Yes, haha. I thought this might be the problem. When you run your project from inside your IDE, it's often a different working directory. The working directory is basically what you described. You can probably find it in your IDE options somewhere, or you can just stick your images in the IDE's working directory.Avishaiozeri wrote:That's weird, when i run it through the debugger, it runs and then exits, the value returned is 1 (even when the img is in the same directory.) but when running from the actual EXE, it works. does the debugger run the software from a different location and can't find the img?RyanPridgeon wrote:See if that works. If it's returning 1 then it's not loading the BMP succesfully. If it runs then you were doing something wrong in the convert format function, which I haven't looked into and have never used, but SDL_DisplayFormat converts it to the same format as the display, which it looks like you were trying to do yourself, so it would be fine like this.Code: Select all
#include "SDL.h" SDL_Surface *screen = NULL; SDL_Event Event; int main (int argc, char *argv[]) { SDL_Init(SDL_INIT_VIDEO); screen = SDL_SetVideoMode(640,480,0,SDL_ANYFORMAT); SDL_Surface *img = NULL; img = SDL_LoadBMP("a.bmp"); if (img == NULL) return 1; SDL_Surface *ConvertedImg = SDL_DisplayFormat(img); while (true) { if (SDL_PollEvent(&Event) == 0) { }else{ if (Event.type == SDL_QUIT) break; } } return 0; }
Note that no matter what the IDE does, when you run that exe OUTSIDE the IDE, the working directory will always be where the EXE is located.
- RyanPridgeon
- Chaos Rift Maniac
- Posts: 447
- Joined: Sun Sep 21, 2008 1:34 pm
- Current Project: "Triangle"
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C/C++
- Location: UK
- Contact:
Re: SDL problem
No idea, just remember to put the DLLs with the EXE.
-
- Chaos Rift Cool Newbie
- Posts: 85
- Joined: Wed Mar 17, 2010 4:32 pm
Re: SDL problem
Thanks man, so my problem probably was that because the different location the debugger looks for the image in, the LoadBMP returned null... so i tried to convert null...RyanPridgeon wrote:No idea, just remember to put the DLLs with the EXE.
Edit:
Confirmed it! i passed null to the SDL_ConvertSurface function, and got the error! from now on, i'll check for errors like these more frequently... Thank you all!
-
- Chaos Rift Regular
- Posts: 173
- Joined: Thu Feb 11, 2010 9:46 pm
Re: SDL problem
Haha I thought you were checking it? =p
-
- Chaos Rift Cool Newbie
- Posts: 85
- Joined: Wed Mar 17, 2010 4:32 pm
Re: SDL problem
lol, i am a beginnerX Abstract X wrote:Haha I thought you were checking it? =p
- xiphirx
- Chaos Rift Junior
- Posts: 324
- Joined: Mon Mar 22, 2010 3:15 pm
- Current Project: ******** (Unkown for the time being)
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C++
- Contact:
Re: SDL problem
How about, when you get the error, what line is VS telling you to look at?
StarCraft II Zerg Strategy, open to all levels of players!
Looking for paid work :< Contact me if you are interested in creating a website, need a web design, or anything else you think I'm capable of
Looking for paid work :< Contact me if you are interested in creating a website, need a web design, or anything else you think I'm capable of
-
- Chaos Rift Cool Newbie
- Posts: 85
- Joined: Wed Mar 17, 2010 4:32 pm
Re: SDL problem
Thanks man, but we already solved the problem... The problem was that i forgot to check for a case that the image wasn't successfully loaded by SDL_LoadBMP(), and because when i run it through the debugger it doesn't find the image, because it looks in the wrong place, then it returns NULL, and then the SDL_ConvertSurface function gets a null instead of a pointer to a surface as a parameter, so that caused the memory error...xiphirx wrote:How about, when you get the error, what line is VS telling you to look at?
- xiphirx
- Chaos Rift Junior
- Posts: 324
- Joined: Mon Mar 22, 2010 3:15 pm
- Current Project: ******** (Unkown for the time being)
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C++
- Contact:
Re: SDL problem
Yeah, im a dumbass, I didn't notice that there were 2 pages and posted based off of the first page X|Avishaiozeri wrote:Thanks man, but we already solved the problem... The problem was that i forgot to check for a case that the image wasn't successfully loaded by SDL_LoadBMP(), and because when i run it through the debugger it doesn't find the image, because it looks in the wrong place, then it returns NULL, and then the SDL_ConvertSurface function gets a null instead of a pointer to a surface as a parameter, so that caused the memory error...xiphirx wrote:How about, when you get the error, what line is VS telling you to look at?
StarCraft II Zerg Strategy, open to all levels of players!
Looking for paid work :< Contact me if you are interested in creating a website, need a web design, or anything else you think I'm capable of
Looking for paid work :< Contact me if you are interested in creating a website, need a web design, or anything else you think I'm capable of
-
- Chaos Rift Cool Newbie
- Posts: 85
- Joined: Wed Mar 17, 2010 4:32 pm
Re: SDL problem
A man that helps others out of kindness isn't a dumbass.xiphirx wrote:Yeah, im a dumbass, I didn't notice that there were 2 pages and posted based off of the first page X|Avishaiozeri wrote:Thanks man, but we already solved the problem... The problem was that i forgot to check for a case that the image wasn't successfully loaded by SDL_LoadBMP(), and because when i run it through the debugger it doesn't find the image, because it looks in the wrong place, then it returns NULL, and then the SDL_ConvertSurface function gets a null instead of a pointer to a surface as a parameter, so that caused the memory error...xiphirx wrote:How about, when you get the error, what line is VS telling you to look at?
-
- Chaos Rift Junior
- Posts: 345
- Joined: Tue Jan 12, 2010 7:23 pm
- Favorite Gaming Platforms: PC - Windows 7
- Programming Language of Choice: c++;haxe
- Contact:
Re: SDL problem
In visual studio you can change the working directory.RyanPridgeon wrote:Yes, haha. I thought this might be the problem. When you run your project from inside your IDE, it's often a different working directory. The working directory is basically what you described. You can probably find it in your IDE options somewhere, or you can just stick your images in the IDE's working directory.Avishaiozeri wrote:That's weird, when i run it through the debugger, it runs and then exits, the value returned is 1 (even when the img is in the same directory.) but when running from the actual EXE, it works. does the debugger run the software from a different location and can't find the img?RyanPridgeon wrote:See if that works. If it's returning 1 then it's not loading the BMP succesfully. If it runs then you were doing something wrong in the convert format function, which I haven't looked into and have never used, but SDL_DisplayFormat converts it to the same format as the display, which it looks like you were trying to do yourself, so it would be fine like this.Code: Select all
#include "SDL.h" SDL_Surface *screen = NULL; SDL_Event Event; int main (int argc, char *argv[]) { SDL_Init(SDL_INIT_VIDEO); screen = SDL_SetVideoMode(640,480,0,SDL_ANYFORMAT); SDL_Surface *img = NULL; img = SDL_LoadBMP("a.bmp"); if (img == NULL) return 1; SDL_Surface *ConvertedImg = SDL_DisplayFormat(img); while (true) { if (SDL_PollEvent(&Event) == 0) { }else{ if (Event.type == SDL_QUIT) break; } } return 0; }
Note that no matter what the IDE does, when you run that exe OUTSIDE the IDE, the working directory will always be where the EXE is located.
Edit: For Codeblocks and Dev - C++, the default working directory for a project is the directory that your project file is located. For example, if your project is called Foo, then you have to put the images in the folder called Foo. I have limited experience for Visual Studio so I cannot recall where it is if you're using that, but I imagine it's similar if not the same.
Project properties -> config properties -> debugging -> working directory. set it to $(TargetDir)