• 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
storage

0xC0000005: Access violation writing location 0x00000004.

15 posts in this topic

No, I am not that experienced in C++/SDL programming, but I've tried everything I can think of, but it doesn't seem to help. This is the error I get in VS .NET 2003:
Unhandled exception at 0x0040163f in Scarinum Client.exe: 0xC0000005: Access violation writing location 0x00000004.

And it occurs here:
int Sprite::Load(const char *filename)
{
	// Make sure a filename was given
	if (filename == NULL)
	{
		// No filename given, exit
		return 0;
	}

	// Set loaded flag to false
	loaded = false;

	// Load bitmap into memory
	img = SDL_LoadBMP(filename);

	// Make sure bitmap was loaded successfully
	if (!img)
	{
		// Bitmap wasn't loaded, exit
		return 0;
	} else {
		// Bitmap was loaded, set loaded flag to true
		loaded = true;
	}

	// Bitmap was loaded successfully
	return 1;
}

Any help is appreciated! [Edited by - storage on February 23, 2005 10:55:49 PM]
0

Share this post


Link to post
Share on other sites
Quote:
Original post by kingnosis
First, I would check two things:

Is img an SDL_Surface *?
Is filename != NULL?


Thanks for your help! :)

Yep, img is an SDL_Surface *
Added filename != NULL

Still same problem tho :(

sprite.h:

#include <SDL.h>

class Sprite
{
public:
int Load(const char *filename);
int DrawSprite(SDL_Surface *img, int x, int y);
SDL_Surface *img;
bool loaded;
};
0

Share this post


Link to post
Share on other sites
Are you *sure* it occurs there?

Perhaps your sprite class isn't getting constructed correctly, or perhaps you're accessing it incorrectly.

I see nothing wrong with what you have posted. Perhaps it's elsewhere.
0

Share this post


Link to post
Share on other sites
You need to post more code I guess.
On a side note, returning 0 for failure is kinda non-standard and will confuse you when you are to use 3rd party libraries and such. Better get off that habit.
0

Share this post


Link to post
Share on other sites
Quote:
Original post by Prototype
You need to post more code I guess.
On a side note, returning 0 for failure is kinda non-standard and will confuse you when you are to use 3rd party libraries and such. Better get off that habit.


Okay, thanks, mind telling me what to return? :)

This is all the code in my main.cpp that has something to do with the sprite class:
// Includes
#include <SDL.h>
#include <stdio.h>
#include <sstream>
#include "logging.h"
#include "sprite.h"

int main(int argc, char *argv[])
{
Sprite *tile[4];

// ... logging, SDL initialization and such here ...

// Transparent color
alpha_r = 255; // Red
alpha_g = 0; // Green
alpha_b = 255; // Blue

// Load tiles
for (int n = 0; n <= 4; n++)
{
std::stringstream temp;

temp << "data\\tiles\\" << n << ".bmp";

tile[n]->Load(temp.str().c_str());

// transparency
SDL_SetColorKey(tile[n]->img, SDL_SRCCOLORKEY, SDL_MapRGB(tile[n]->img->format, alpha_r, alpha_g, alpha_b));
}

// ... event handling and more logging etc ...
}





Tell me if you need more :)

Thanks for all the help!
0

Share this post


Link to post
Share on other sites
You have:

Sprite *tile[4];


Which is an array of pointers to Sprites. You will either need to allocate new memory or use:


Sprite tile[4];
...
tile[n].Load(temp.str().c_str());


Once you do that, you should not be crashing anymore. Right now you are using NULL pointers, which is making your program do what it is doing.

- Drew
0

Share this post


Link to post
Share on other sites
Quote:
Original post by Drew_Benton
You have:

Sprite *tile[4];


Which is an array of pointers to Sprites. You will either need to allocate new memory or use:

[code]
Sprite tile[4];
...
tile[n].Load(temp.str().c_str());
[code]

- Drew


Thanks alot! :)

0

Share this post


Link to post
Share on other sites
You create an array of 4 sprites, while you are trying to initialize 5:


Sprite *tile[4]; // only creates 4 elements [0..3]
...
for (int n = 0; n <= 4; n++) // tries to access tile[4]

So change n<=4 into n<4.
0

Share this post


Link to post
Share on other sites
Quote:
Original post by Prototype
You create an array of 4 sprites, while you are trying to initialize 5:


Sprite *tile[4]; // only creates 4 elements [0..3]
...
for (int n = 0; n <= 4; n++) // tries to access tile[4]

So change n<=4 into n<4.


Thanks :)

It works! :) Thanks everyone, for helping me and learning me about pointers and such :)
0

Share this post


Link to post
Share on other sites
Oh yeah, BTW, usually a function returns 0 for success, and any other value to denote an error (which you can conveniently put into an enum for readability).
0

Share this post


Link to post
Share on other sites
Quote:
Original post by Prototype
Oh yeah, BTW, usually a function returns 0 for success, and any other value to denote an error (which you can conveniently put into an enum for readability).


Thanks thanks :)
0

Share this post


Link to post
Share on other sites
It is perhaps worth noting the following point.

If you get an error such as: "Access violation writing location 0x00000000."
Then it usually means that you have dereferenced a NULL pointer.

However you got: "Access violation writing location 0x00000004."
When you get an error like this, with a small non-zero value, then
it often (but not always) means that your "this" pointer is NULL.

In this case you had "loaded = true;". Notice that loaded is exactly 4 bytes
into the class Sprite as it follows a pointer (4 bytes) in the declaration.

So given the error message the first thing to do was to check the "this"
pointer in the debugger, or just read the code that called the function
and check whether the pointer could be NULL.

Martin
0

Share this post


Link to post
Share on other sites
Hi everyone, I think I have a similar problem with VS.NET 2003. I get
Unhandled exception at 0x0041821a in test.exe: 0xC0000005: Access violation writing location 0x004436ec.

message with this code:
#include <conio.h>
#include <iostream>

using namespace std;

void revert(char *str)
{
char *last_ch = str;
while (*++last_ch) //*pluspluslast_ch
;
--last_ch;

while (str < last_ch)
{
char tmp;
tmp = *str;
*str++ = *last_ch; //buggy line (*strplusplus)
*last_ch-- = tmp;
}
}
int main()
{
char *zaq = "abcdefgh";
cout<<zaq<<endl;
revert(zaq);
cout<<endl<<zaq<<endl;

getch();
return 0;
}


It comes from "Pointers on C" by Kenneth A. Reek (chapter 6, ex. 3). The function should put chars in reverse order in a given char array without using indices and local temp arrays (by using pointers only). I don't know what is wrong with this code - it comes from the spoiler at the end of the book :(
0

Share this post


Link to post
Share on other sites
Your problem is:

char *zaq = "abcdefgh";

the fix:

char zaq[] = "abcdefgh";

zaq was pointing pointing to a memory address inside the text of your program, which cannot be changed.
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