Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Access violation by memeset and fopen

This topic is 5463 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

When I compile my code I get an access violation. The debugger seems to think that it is caused by both memset and fopen because it wants to see their code. Here are my definitions
#ifndef GUI_H_
#define GUI_H_

#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <stdio.h>
#include <string.h>

	void (*On_Action)(void);
	int ID;
	char buffer[255];
	char command[255];
	int x,y,width,height;        //width and height are in characters not pixels
	int bufferPosition;
	void (*On_Action)(void);
	int ID;
	char *Caption;
	int x,y;

	GUI_TEXT_BOX *texts;
	GUI_BUTTON *buttons;
	GUI_TEXT_BOX *temp_texts;
	GUI_BUTTON *temp_buttons;
	int numButtons;
	int numTexts;
	int focused_text_id;
	void guiPrint(char *fmt,int x, int y);
	unsigned int base;
	HDC hDc;
	void AddToTextsStack(GUI_TEXT_BOX text);
	void AddToButtonsStack(GUI_BUTTON button);
	void FocusObject(int x,int y);
	void AddToTextBuffer(char c);
	void RenderGUI();
	void BuildFont(int height,int width, char *typeface);

class GUI
	void Update(int x,int y,int b,char c);
	void SetUpText(void (*On_Action)(void),int ID,char *Command,int x,int y,int width,int height);
	void SetUpButton(void (*On_Action)(void),int ID,char *Caption,int x,int y);
	void InitGUI(HDC hDc);

	GUI_OBJECTS objects;




and here is the code
void GUI_OBJECTS::AddToTextsStack(GUI_TEXT_BOX text)
		temp_texts=new GUI_TEXT_BOX[numTexts];

		int i;
		for (i=0;i=texts[i];
		delete texts;
		texts = new GUI_TEXT_BOX[numTexts];
Now the when I compile and run this, if I call the function once it works;twice and it doesn''t work but it does not cause the violateion;3 times and up it gives me the error; 

Share this post

Link to post
Share on other sites
The debugger, when it thinks something, is right

You need to check the results from fopen() to make sure it is a valid file handle, and memset to make sure it isn''t returning an error code. fopen() will cause access violations when files are missing, under incorrect permissions (NT, 2k, XP, 2k3 only), etc.

Share this post

Link to post
Share on other sites
I looked at it more closely with the debugger and all the values are what they should be right before the memset function. When it hits the memset it gives me the error.

[edited by - tHiSiSbOb on July 8, 2003 6:35:29 PM]

Share this post

Link to post
Share on other sites
You used


which is out of bounds. You should have used


Also, if you

new yada[]

then you should

delete [] yada

EDIT -- Fixed formatting

[edited by - Dave Hunt on July 8, 2003 8:32:24 PM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!