Jump to content
  • Advertisement
Sign in to follow this  
mattnenterprise

File Output

This topic is 2761 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
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?

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
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.

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
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!