Page 2 of 3
Re: SDL problem
Posted: Mon May 31, 2010 5:32 pm
by Ginto8
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.
Re: SDL problem
Posted: Mon May 31, 2010 7:15 pm
by Avishaiozeri
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.
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:
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;
}
does that error! that means that the problem is SDL_ConvertSurface (according to the debugger as well.) so i guess i'v used it incorrectly, maybe the type of image loaded, can't be converted...
Edit: The img isn't the problem. even when i removed it, the error is still there.
Re: SDL problem
Posted: Mon May 31, 2010 7:21 pm
by RyanPridgeon
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;
}
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.
Re: SDL problem
Posted: Mon May 31, 2010 7:34 pm
by Avishaiozeri
RyanPridgeon wrote: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;
}
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.
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?
Re: SDL problem
Posted: Mon May 31, 2010 7:38 pm
by RyanPridgeon
Avishaiozeri wrote:RyanPridgeon wrote: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;
}
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.
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?
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.
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.
Re: SDL problem
Posted: Mon May 31, 2010 7:45 pm
by Avishaiozeri
RyanPridgeon wrote:Avishaiozeri wrote:RyanPridgeon wrote: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;
}
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.
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?
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.
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.
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?)
Re: SDL problem
Posted: Mon May 31, 2010 7:48 pm
by RyanPridgeon
No idea, just remember to put the DLLs with the EXE.
Re: SDL problem
Posted: Mon May 31, 2010 7:55 pm
by Avishaiozeri
RyanPridgeon wrote:No idea, just remember to put the DLLs with the EXE.
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...
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!
Re: SDL problem
Posted: Mon May 31, 2010 9:06 pm
by X Abstract X
Haha I thought you were checking it? =p
Re: SDL problem
Posted: Mon May 31, 2010 9:31 pm
by Avishaiozeri
X Abstract X wrote:Haha I thought you were checking it? =p
lol, i am a beginner
Re: SDL problem
Posted: Mon May 31, 2010 11:41 pm
by xiphirx
How about, when you get the error, what line is VS telling you to look at?
Re: SDL problem
Posted: Tue Jun 01, 2010 9:27 am
by Avishaiozeri
xiphirx wrote:How about, when you get the error, what line is VS telling you to look at?
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...
Re: SDL problem
Posted: Tue Jun 01, 2010 12:40 pm
by xiphirx
Avishaiozeri wrote:xiphirx wrote:How about, when you get the error, what line is VS telling you to look at?
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...
Yeah, im a dumbass, I didn't notice that there were 2 pages and posted based off of the first page X|
Re: SDL problem
Posted: Tue Jun 01, 2010 1:31 pm
by Avishaiozeri
xiphirx wrote:Avishaiozeri wrote:xiphirx wrote:How about, when you get the error, what line is VS telling you to look at?
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...
Yeah, im a dumbass, I didn't notice that there were 2 pages and posted based off of the first page X|
A man that helps others out of kindness isn't a dumbass.
Re: SDL problem
Posted: Tue Jun 01, 2010 10:50 pm
by Live-Dimension
RyanPridgeon wrote:Avishaiozeri wrote:RyanPridgeon wrote: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;
}
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.
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?
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.
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.
In visual studio you can change the working directory.
Project properties -> config properties -> debugging -> working directory. set it to $(TargetDir)