File Output

Started by
9 comments, last by mattnenterprise 13 years, 3 months ago
So I am making a program using SDL and OpenGL, and I am trying to make output to a file. There is a problem that when I have global variables and I close the program there is an error.

Here is my code and files, and yes I know the code is very sloppy

Main.cpp

#pragma comment(lib,"SDLmain.lib")#pragma comment(lib,"SDL_image.lib")#pragma comment(lib,"OpenGL32.lib")#pragma comment(lib,"GLU32.lib")#include <fstream>#include <iostream>#include <Windows.h>#include <SDL/SDL.h>#include <SDL/SDL_image.h>#include <gl/GL.h>#include <gl/GLU.h>#include <map>#include <vector>#include "Globals.h"int main(int argc, char * argv[]){	std::ofstream error;	error.open("Error_Log.txt");	error.close();	SDL_Init(SDL_INIT_EVERYTHING);	SDL_SetVideoMode(800,700,32,SDL_OPENGL | SDL_SWSURFACE);	glMatrixMode(GL_PROJECTION);	glLoadIdentity();	glOrtho(-100.0f,100.0f,-100.0f,100.0f,-1.0f,1.0f);	glMatrixMode(GL_MODELVIEW);	glLoadIdentity();	while(1)	{		if(SDL_PollEvent(&event))		{			if(event.type == SDL_QUIT)			{				break;			}		}		glClearColor(0.0f,0.0f,0.0f,0.0f);		glClear(GL_COLOR_BUFFER_BIT);		SDL_GL_SwapBuffers();	}	SDL_Quit();	return 0;}


Globals.h

#include <SDL\SDL.h>#ifndef GLOBALS_H#define GLOBALS_Hextern SDL_Event event;#endif


Globals.cpp

#include "Globals.h"SDL_Event event;
Advertisement
Quote:
There is a problem that when I have global variables and I close the program there is an error.

What error is that?

Why does "event" have to be global? Can't you pass it to any functions that require it?
I also don't understand what "error" you encounter, but I noticed you are opening your error log and closing it immediately after in your Main.cpp. You cannot use your "error"-stream after you called close() on it.
Well "event" doesn't have to be global, but I would really like to know what is causing this. I have to run the debugger to find out what happens, because it occurs when I close the program. I just know that it has something to do with the lock_file function, and in that function there is a pf variable and it says that it is a bad pointer.

and I don't even have to open or close the file for this error to occur.
If I just create the variable

std::ofstream error;

I get the error thing that happens.
Quote:
I get the error thing that happens.

Again: what error is that? Can you paste the error message, or at worst a screen shot showing what is happening.
Sorry but I don't have web space to post a screenshot.
But I will post some of the call stack in the debugger.


> msvcr100d.dll!_lock_file(_iobuf * pf) Line 237 C

msvcr100d.dll!fclose(_iobuf * stream) Line 54 + 0x9 bytes C

it states that the pf pointer and the stream pointer are both bad

the problem is somewhere in here, sorry I can't give you more.
I have a screenshot but I cannot post it because I have no webspace
Quote:Original post by mattnenterprise
Sorry but I don't have web space to post a screenshot.
But I will post some of the call stack in the debugger.


> msvcr100d.dll!_lock_file(_iobuf * pf) Line 237 C

msvcr100d.dll!fclose(_iobuf * stream) Line 54 + 0x9 bytes C

it states that the pf pointer and the stream pointer are both bad

the problem is somewhere in here, sorry I can't give you more.
I have a screenshot but I cannot post it because I have no webspace




Hmmmmm, have you tried searching the internet for working SDL and OpenGL tutorials?
the problem is not SDL or OpenGL it is with file I/O. I can't even create a

std::ofstream var;

without the error. The error happens when I close the program, it has something to do with the pf pointer in my variable. I have no idea how to fix it, this must be a really rare problem, because I tried google and have found nothing on it.
the problem is not SDL or OpenGL it is with file I/O. I can't even create a

std::ofstream var;

without the error. The error happens when I close the program, it has something to do with the pf pointer in my variable. I have no idea how to fix it, this must be a really rare problem, because I tried google and have found nothing on it.
http://imageshack.us/ is free image hosting site.
If you didn't know yet.


When i have some bug in code that is hard to find but at least compiler shows what causes trouble (usually exception windows etc), then i usually starting to comment out suspicious code that could cause it. And recompile and run it again.

If bug is still there, i will uncomment it and comment out another piece of code or line.

If bug is gone, then it means that bug is in that line(s) that was just commented out. So i have to examine it more closely.


This is my way of doing debug. To be honest, i very rarely use debugger.
I only use the info that VS exception dialog or compiler messages show me.

This topic is closed to new replies.

Advertisement