• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Rafael_Treiber

SDL access violation

3 posts in this topic

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.

 

0

Share this post


Link to post
Share on other sites

Very confusing. SDL's [url="http://wiki.libsdl.org/moin.fcg/SDL_RWFromFP"]documentation for SDL_RWFromFP[/url] says:

This is not available under Win32, since files opened in an application on that platform cannot be used by a dynamically linked library

They should make it so that on Win32, this function either doesn't appear to be available, or at the very least have an alternate code path that returns an error.

Edited by rip-off
WYSIWYG rage... give me plain text or give me death!
1

Share this post


Link to post
Share on other sites

The weird thing is that I got SDL_Rwops to work on MinGW compiler but it always crashes on Visual Studio.

My interest in SDL_Rwops is because I was trying to create a packfile to put all my images, sounds, fonts, etc. And for that I was following the code from an old game called I have no Tomatoes and, as I said, it works on MinGW. The problem is that Visual Studio is much faster to write code and much easier to debug. The only little detail is that it does not work tongue.png .

Besides, to use Visual Studio I had to change some things in the code like fopen() to fopen_s(), sprintf() to sprintf_s() and I believe that these comands don't work on MinGW.

Anyway, enough of punching on a rock...

Could you recomend anything to look up to create my own packfile? I think zlib does that but I am not sure if it is not a little too old. And I know that it is impossible to avoid people from hacking your resources but I wanted a packfile that could not be opened in a simple Winrar or Winzip. If you could recomend any library in C++ to do that, it would be great.

Thank you very much for your time and interest.

0

Share this post


Link to post
Share on other sites

That is really a separate question, and you'll probably get more responses if you started a new thread. That said, PhysFS is one library I've often heard used to achieve this. If you really don't want your packfile to be trivially opened using simple tools, a quick XOR obfuscation pass will probably suffice.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0