Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Rafael_Treiber

Member Since 30 Apr 2007
Offline Last Active Jul 18 2013 10:38 AM

Topics I've Started

SDL access violation

08 May 2013 - 02:17 PM

I have a big program that is causing me access violation when using sdl_rwops. So I decided to create a small program just to test sdl_rwops and it is causing me the same access violation. For what I could see it is being caused because of the fopen_s() part but I could not figure out why. Maybe you guys can find what I am missing. Here is the code:

#include "SDL.h"
#include < stdio.h >

int main(int argc, char *argv[]) 
{
  FILE *file;
  SDL_Surface *screen;
  SDL_Surface *one;
  SDL_Rect rect;
  errno_t err;

/* This is the RWops structure we'll be using */

  SDL_RWops *rw;
  SDL_Init(SDL_INIT_VIDEO);
  atexit(SDL_Quit);
  screen = SDL_SetVideoMode(640, 480, 16, SDL_DOUBLEBUF);

/* Here we get a file pointer to a bitmap */

  if ( (err = fopen_s(&file,"penguin.bmp", "r")) != 0)
  {
     printf("Couldn't load penguin.bmp\n");
     exit(1);
  }

/* This is where we actually create our RWops structure.  Here we're
 instructing SDL to get it from the file pointer we just opened */

rw = SDL_RWFromFP(file, 0);

/* SDL_LoadBMP_RW is the RWops version of the old standby,
 SDL_LoadBMP.  This will get the image from the RWops you passed
 in; in this case the file you've opened */

one = SDL_LoadBMP_RW(rw, 0); // This line calls fopen.c and causes the crash

/* Clean up after ourselves */
SDL_FreeRW(rw);
fclose(file);

/* Haphazard way of getting stuff to the screen */
rect.x = rect.y = 20;
rect.w = one -> w;
rect.y = one -> h;
SDL_BlitSurface(one, NULL, screen, &rect);

SDL_Flip(screen);

SDL_Delay(3000);
}

 

And here is the portion of fopen.c that causes the crash of the program:

 

errno_t __cdecl _tfopen_s (
FILE ** pfile,
const _TSCHAR *file,
const _TSCHAR *mode)
{

_VALIDATE_RETURN_ERRCODE((pfile != NULL), EINVAL);

*pfile = _tfsopen(file, mode, _SH_SECURE); // This line causes the access violation

if(*pfile != NULL)
   return 0;

return errno;
}

 

The line

one = SDL_LoadBMP_RW(rw, 0);
jumps to fopen.c and the line
*pfile = _tfsopen(file, mode, _SH_SECURE);

in that file makes it crash.

 

I am using Visual Studio 2012 and the picture is in the same folder as the executable. The SDL.dll and even SDL_image.dll are there too. I found a post in google of the same issue and the person said that when he put the whole path (instead of just penguin.bmp") it would not crash. It did not work for me, crashed anyway. I am starting to think that it may be some SDL initialization issue but I did anything I could find on google and nothing worked. I tryed running in Multi-threaded DLL (/Md), in Multi-threaded Debug Dll (/MDd), tryed running in 64 bits, tyred changing the Subsystem to Windows and to console... everything resulted in the same crash.

 

The error message is:

 

Unhandled exception at 0x77888C39 (ntdll.dll) in testrwops.exe: 0xC0000005: Access violation writing location 0x00000014.

 

Which makes me think of a null pointer. So I even tryed to allocate memory for file and rw with new and malloc but it didnt work also. I pretty much used the same code as this site but maybe it is out of date.

 

Thanks for any help.

 


tile based games

20 December 2007 - 01:23 AM

Hello guys. I have been quite a while away from the programming because I was having lots of work, but now that things got calm again, I started to make a game. I have always done simple games with few moving images and just some sounds. But now I decided to put all my knowlege together and create the kind of game I like the most: platform games. I still like pretty much the old SNES games like Demon's Crest, Black thorne and games like those. I am creating one similar to those and by the moment I can already make my hero walk through the screens, fall down on holes going to another screen, jump and colide against obstacles. Actually I am having some trouble on saving and loading the obstacles into a file but thats not why I am writing. I just would like to know if tile based games are still created today. I am not making it a tile based games. I just saved my hero in a bitmap, created a background and saved it too and then I created a text file with the coordinates where the hero should colide on the background. I dont know if this is the best way to do it so I looked for tile based games on the internet. I read that mostly of the SNES games were tile based games, including Super Mario Bros. But I also read that they did them like that because they are easier to load and faster too. With the technology they had at their processors at that time, it was the best thing to do. But my question is: is it still the best way to do this kind of game? Are there other technics to do platform games now? I have just found texts about tile based games in flash and I code in C++, so if anyone knows any link to a tile based game explanation in C++, I would appreciate very much. Any link about platform games in C++ would be appreciated as well. Thank you for your time guys.

collision in different screens

03 May 2007 - 12:00 PM

Hello all, I am making a 2D game that I can't say its style. Let me explain. It is that kind of game where you can move around the entire screen, without the background changing at all. And as you reach one of the edges of the screen, the entire background changes and you can travel again through the entire new background till you reach an edge again. I can just remember one name of a game of this kind. It is Black Thorne from SNES. Ok, my game is fine and I have three diferent screens where I can travel around. But I have made some obstacles in the backgrounds. One of them is a closed door, where the player will just be able to get through after he finds the key. And one of the obstacles is a gap that the player must jump over. Ok, I can handle the collisions. They are not a problem for me, but what I want to know is how the collisions in this kind of game are handled. I can create some variables to keep the player away from the door if he has not the key yet. But what will I do when my game has 100 different screens? Will I have to create 100 different variables to keep track of every obstacle? I don't think so. actually, this is a way that i thought about to solve this. The other way that I thought about was saving the informations about the obstacles in a text file and load them at runtime. But I dont quite know what to put in this textfile. How could I organize the information about the obstacles. And in some screens there are more than one... Well, I just want to know if you guys know how is it really done in this kind of game. Thank you for your time.

troubles

30 April 2007 - 11:56 AM

Hello all. I am having some troubles using SDL along with Visual Studio Express edition 2005 and as I didnt find any topics related to my problem in my search, I decided to post it here. Here is the situation: I created a game using SDL and the Microsoft Visual Studio Express edition 2005 compiler. It works fine and I get no error messages here. The code is basically making a man walk across the screen. As it is working fine, I decided to send it to my friends. So I sent it to one of them and it worked fine for him too. But he is a programmer too and he says he has SDL on his computer too. So I sent it to another friend of mine and it didnt work there, It just open and closes imediatly. So I sent it to my sister and she had the same problem. And I sent to another guy and he had the same problem. As the game is running OK here on my machine and it worked fine on another machine with SDL too, I can assume that it is some file missing. But I dont know which one. I know that along with my game I have to send SDL.dll and SDL_image.dll too. But even if you do not send them, the program asks for them on opening. And there is no error message. No asking for any file. It just opens and close. So I created a log in the code to see what is causing this and I saw that it was the image loading. If it cant open the image, it returns 1 and the program exits. But why wont it load the images? I am sure it is not the code because it works fine here and on the other friend I told. And some other friend of mine told me to use a program to see what dlls my game needs. I executed it and it showed me that I need SDL.dll, SDL_image.dll, msvcr80.dll and msvcp80.dll. But even sending all these dlls, the game wont run. And yes, the images are on the same directory of the exe file that I sent them. It is the second time that I have these incompatibility troubles. Any help would be welcome.

PARTNERS