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

Error Log Help

19 posts in this topic

Hello,

I am learning SDL and i thought it would be helpful to make an Debug log to tell me if something is working or not. I am doing the project as a stand alone just to see if it works and then implement it in my SDL projects. So i have played a round with it a little but i cannot get the program to work. I am trying to make a class that handles all the debug stuff for me using the fstream to make a file telling me what happened. I cannot seem to get this to work, can anyone give me some hints? anything would be much appreciated.
0

Share this post


Link to post
Share on other sites
Let me just grab my crystal ball... seriously, if you want help on your code, you might want to post said code, otherwise there's not much to go on. We're not psychic [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img]
0

Share this post


Link to post
Share on other sites
Sorry i thought i linked the project.
Main.cpp
[source lang="cpp"]#include "stdafx.h"
#include "DebugLog.h"
int main (){
DebugLog debug("DebugLog.txt");
debug.~debug();
return 0;
}[/source]
DebugLog.h
[source lang="cpp"]
#include "stdafx.h"
#include <fstream>
#include <iostream>
#include <string>
using namespace std;

class DebugLog {
public:
DebugLog();
~DebugLog();
string writeTo(string text);
private:
string m_Text;
string m_Filename;
};[/source]
DebugLog.cpp
[source lang="cpp"]
#include "stdafx.h"
#include "DebugLog.h"
DebugLog::DebugLog(){
ofstream debugLog("DebugLog.txt");
m_Text = "-----Debug Log Starts Now-----\n\n";
debugLog << m_Text;
}
DebugLog::~DebugLog(){
m_Text = "-----End of DebugLog-----";
debugLog << m_Text;
debugLog.close();
}
string DebugLog::writeTo(string text){
m_Text = text;
debugLog << text;
return;
}[/source]
0

Share this post


Link to post
Share on other sites
DebugLog.h:
#include "stdafx.h"
#include <fstream>
#include <iostream>
#include <string>
using namespace std;

class DebugLog {
public:
DebugLog();
~DebugLog();
string writeTo(string text);
private:
string m_Text;
string m_Filename;
};
Debug.cpp:
#include "stdafx.h"
#include "DebugLog.h"
DebugLog::DebugLog(){
ofstream debugLog("DebugLog.txt");
m_Text = "-----Debug Log Starts Now-----\n\n";
debugLog << m_Text;
}
DebugLog::~DebugLog(){
m_Text = "-----End of DebugLog-----";
debugLog << m_Text;
debugLog.close();
}
string DebugLog::writeTo(string text){
m_Text = text;
debugLog << text;
return;
}
and Main.cpp
{
DebugLog debug("DebugLog.txt");
debug.writeTo("Line 1\n");
debug.~debug();
return 0;

I have an idea about whats going on but not a way to fix it.
0

Share this post


Link to post
Share on other sites
First, don't call destructors like that. Use delete debug instead - and if the class is allocated on the stack instead - like it is here - just let it die when it goes out of scope, its destructor will be called automatically.

Secondly, does this even compile? debugLog is not defined in the destructor or in writeTo(). Basically, you allocate your iostream in the constructor, which is on the stack - as soon as it goes out of scope (i.e. when the constructor returns) the iostream is closed and lost. This iostream exists only in the constructor. If you want to keep a persistent iostream throughout your debug log's lifetime, you want it to exist as a private field in your class. Then you can use it anywhere, and your writeTo() will actually work. Does it make sense?
0

Share this post


Link to post
Share on other sites
If im understanding this right, your saying the ofstream debugLog("DebugLog.txt"); should be in my private: part of the class. When i do this i get an error saying that the "DebugLog.txt" needs an identifier before it. And Im not understanding what your saying about the destructor.
0

Share this post


Link to post
Share on other sites
And int the main function it says DebugLog debug("DebugLog.txt"), that isnt supposed to be there sorry i forgot to delete it.
0

Share this post


Link to post
Share on other sites
[source lang="cpp"]class DebugLog {
public:
DebugLog();
~DebugLog();
string writeTo(string text);
private:
string m_Text;
string m_Filename;
ofstream m_debugLog;
};

DebugLog::DebugLog()
{
m_debugLog.open("DebugLog.txt"); // m_debuglog now belongs to the class, not just the constructor
// so it can be accessed in writeTo() as well
}[/source]

This means the debugLog object is now attached to your class instead of a specific method, so every method in the class has now access to it. The constructor takes care of creating the stream. Does it make more sense now?

Never mind the destructor stuff for now - you need to understand the concept of class fields before. Edited by Bacterius
1

Share this post


Link to post
Share on other sites
Yes it makes sense now, thanks. But when i compiles it a message poped up saying Debug Assertion failed, what does this mean?
0

Share this post


Link to post
Share on other sites
Sorry, one more thing, When i compile it i get a message that says

:[b]Unhandled exception at 0x7784ef10 in DebugLog.exe: 0xC0000005: Access violation reading location 0xfeeefef6.[/b]
0

Share this post


Link to post
Share on other sites
Whole code, please. Works fine here. You're trying to access 0xfeeefeee, which is a bit pattern written by the Microsoft compiler to indicate memory that has been freed, So either you're not calling the constructor, either you're trying to use the DebugLog after you've freed it.

[quote]And int the main function it says DebugLog debug("DebugLog.txt"), that isnt supposed to be there sorry i forgot to delete it.[/quote]
What did you mean by that?
0

Share this post


Link to post
Share on other sites
In the code i posted above it said in the main function debugLog debug("DebugLog.txt"). I sending the "DebugLog.txt" to the compiler so it name the file, but i changed it to name it in the constructor itself because i wasn't planning on changing the name. And what do you mean by using the Constructor after i freed it and why would it work for you and not for me?
0

Share this post


Link to post
Share on other sites
Sanity check: does this work for you?

[source lang="cpp"]#include < iostream >
#include < fstream >

using namespace std;

class DebugLog {
public:
DebugLog();
void writeTo(string text);
~DebugLog();
private:
ofstream m_debugLog;
};

DebugLog::DebugLog()
{
m_debugLog.open("DebugLog.txt");
}

DebugLog::~DebugLog()
{
cout < < "Closing debug log." < < endl;
m_debugLog.close();
}

void DebugLog::writeTo(string text)
{
m_debugLog < < text;
}

int main()
{
DebugLog log;
log.writeTo("hello world");

// log is about to fall out of scope - destructor should be called
return 0;
}
[/source]

[b]Remove all the extra spaces I had to insert since the source tags are broken.[/b] I think we're just having a communication breakdown here. Edited by Bacterius
0

Share this post


Link to post
Share on other sites
My code does the same thing yours does, however mine has different names, and when i deleted the Destructor i didnt get the message i got before.
0

Share this post


Link to post
Share on other sites
Yes, you must essentially never call a destructor using the tilde method. If you need to delete it, use the "delete" keyword, and that's only for pointers (e.g. when going DebugLog* log = new DebugLog(), but that's for later). In your case, the destructor will be automatically called (since once you go out of main, your DebugLog is lost and can never be used again, so C++ chooses to destroy it there).
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