Sign in to follow this  

File Output

This topic is 2544 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

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_H

extern SDL_Event event;

#endif




Globals.cpp



#include "Globals.h"

SDL_Event event;


Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Here is the link to my image.

http://img547.imageshack.us/img547/2346/screenzx.jpg

Thanks BytePtr for the image shack website, and If I comment out

std::ofstream error

from my code then it works. so i have concluded that is what is causing it.

Share this post


Link to post
Share on other sites

This topic is 2544 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.

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