That error means that you have your app open.
We can't know why things are unstable because you post one hundredth of your code every time..
Ok, Here is some code.
*you could have asked for more....*
I got my window working.
Turns out that the value wasn't being carried between objects for
bool Windowed; //Located in Genesis.h
So I changed it to:
static bool Windowed; //Located in Genesis.h
and it worked but now I have a issue........ it launches in fullscreen........... all of the time. XD
Though, I would love to have a second person look at some of this code. >.>
WindowManagment.h
#ifndef WINDOWMANAGER_H
#define WINDOWMANAGER_H
#include "stdafx.h"
class EngineWindow : public sf::Window
{
public:
void Launch();
sf::Window& GetRenderWindow();
void SetResolution(short int x,short int y);
void SetFullscreen(bool a);
void SetVerticalSync(bool a);
void ShowCourser(bool a);
void SetFramerateLimit(short int a);
private:
void GetDesktopResolution(short int&X,short int&Y);
};
#endif
WindowManagment.cpp
#include "stdafx.h"
#include "WindowManagment.h"
#include "Genesis.h"
#include "ConsoleUtils.h"
/**
Launches the render window.
*/
void EngineWindow::Launch()
{
Log consoleLog;
consoleLog.info("Launching Window...");
Genesis genesis;
if(genesis.Windowed)
{
consoleLog.info("Windowed Mode Detected");
create(sf::VideoMode(genesis.WindowX,genesis.WindowY,32),"Genesis");
}else{
consoleLog.info("Going Fullscreen");
short int X;
short int Y;
GetDesktopResolution(X,Y);
create(sf::VideoMode(X,Y,32),"Genesis",sf::Style::Fullscreen);
}
}
/**
Detects desktop resolution and adjusts the X and Y variables accordingly.
*/
void EngineWindow::GetDesktopResolution(short int&X,short int&Y)
{
RECT desktop;
const HWND hDesktop = GetDesktopWindow();
GetWindowRect(hDesktop, &desktop);
X = desktop.right;
Y = desktop.bottom;
}
/**
Recieves a true or false and enables/disables vertical sync accordingly.
*/
void EngineWindow::SetVerticalSync(bool a)
{
if(a)
setVerticalSyncEnabled(true);
else
setVerticalSyncEnabled(false);
}
/**
Recieves a true or false and enables/disables showing the mouse curser.
*/
void EngineWindow::ShowCourser(bool a)
{
if(a)
setMouseCursorVisible(true);
else
setMouseCursorVisible(false);
}
/**
Recieves a short int and sets the framerate limit to it. Must be between 15 - 60,
*/
void EngineWindow::SetFramerateLimit(short int a)
{
if(a>60) a=60;
if(a<15) a=15;
setFramerateLimit(a);
}
Genesis.h
#ifndef GENESIS_H
#define GENESIS_H
#include <string>
class Genesis{
public:
//Command Line Arguments
std::string flags;
static bool SkipSplash;
static bool Windowed;
static bool Debug;
static bool NoConsoleTags;
bool WaitBeforeExit;
short int WindowX;
short int WindowY;
//Core Engine States
enum CoreEngineState{Initializing,ShowingSplash,ShowingMenuScreen,Playing,Reloading,Closing};
CoreEngineState engineCoreState;
//Public Functions
void Initialize(int argc,char *argv[]);
void ArgumentHandler(int argsl,char *args[]);
std::string GetVersion(void);
bool isClosing();
private:
void ValidateFlags();
void ClassDistributor();
};
#endif
Genesis.cpp
/*
Genesis and its resources are copyright of PredawnStudios LLC (C)2012 PredawnStudios.
SFML - Copyright (c) 2007-2008 Laurent Gomila
*/
// Genesis.cpp : main project file.
#include "stdafx.h"
#include "Genesis.h"
#include "ConsoleUtils.h"
#include "WindowManagment.h"
using namespace std;
//Make used objects
Font font;
Log ConsoleLog;
Validate validate;
bool Genesis::Windowed;
bool Genesis::SkipSplash;
bool Genesis::Debug;
bool Genesis::NoConsoleTags;
//Declaring our version.
const std::string GenesisVersion = "2.0.0 Pre Alpha";
/**
The main will recieve our command line arguments and bee the starting point for
the engine.
*/
int main(int argc,char *argv[])
{
Genesis::CoreEngineState engineCoreState = Genesis::Initializing;
const int argcc = argc;
Genesis genesis;
genesis.Initialize(argc,argv);
return 0;
}
/**
This function will be our main tree for controling core engine specific paths.
*/
void Genesis::Initialize(int argc,char *argv[])
{
//Print Genesis Command Line Header And Version
cout << " @@@@@@@ @@@@@@@@ @@@ @@@ @@@@@@@@ @@@@@@ @@@ @@@@@@" << endl;
cout << " !@@ @@! @@!@!@@@ @@! !@@ @@! !@@ " << endl;
cout << " !@! @!@!@ @!!!:! @!@@!!@! @!!!:! !@@!! !!@ !@@!! " << endl;
cout << " :!! !!: !!: !!: !!! !!: !:! !!: !:!" << endl;
cout << " :: :: : : :: ::: :: : : :: ::: ::.: : : ::.: : " << endl;
cout << endl;
font.set_color(15);
cout <<"Version " << Genesis::GetVersion() << endl;
font.set_color(7);
cout << endl;
//End Header
//Set Flag Defaults
Genesis::SkipSplash=false;
Genesis::Windowed=false;
Genesis::Debug=false;
Genesis::NoConsoleTags=false;
Genesis::WaitBeforeExit=false;
short int WindowX=0;
short int WindowY=0;
if(argc>=2)
{
ConsoleLog.info("Command Line Arguments Detected...");
Genesis::ArgumentHandler(argc,argv);
}else{
ConsoleLog.info("No arguments found. Launching engine.");
}
//Validate Command Line Flags
ValidateFlags();
//We will make a render window but not automatically display it.
ConsoleLog.info("Initializing Window System");
EngineWindow eWindow;
eWindow.Launch();
//Ask for input so they can see what all occured if flag -wait set.
if(Genesis::WaitBeforeExit)
{
cout << "Press enter to close..." << endl;
cin.get();
}
}
void Genesis::ClassDistributor()
{
/*switch(CoreEngineState){
case Genesis::Initializing:
Genesis::CoreEngineState = Genesis::ShowingSplash;
break;
};*/
}
/**
Argument Handler will recieve the arguments all at once, and flip the proper
switches based on the argument. It also returns false if the argument was not
found in its database.
@arg int The Ammount of arguments being recieved.
@arg char* The array of arguments to be recieved.
*/
void Genesis::ArgumentHandler(int argsl,char *args[])
{
for(int i=1;i<argsl;i++)
{
int j = 0;
bool ProperArgument=false;
std::string arg = args[i];
std::string at = "Attempting to parse: \"" + arg + "\"";
ConsoleLog.info(at);
if(arg=="-SI")
{
Genesis::SkipSplash = true;
ProperArgument = true;
}
if(arg=="-WM")
{
Genesis::Windowed = true;
ProperArgument = true;
}
if(arg=="-DB")
{
Genesis::Debug = true;
ProperArgument = true;
}
if(arg=="-nct")
{
Genesis::NoConsoleTags = true;
ProperArgument = true;
}
if(arg=="-wait")
{
Genesis::WaitBeforeExit = true;
ProperArgument = true;
}
if(arg=="-X")
{
j = i;
j++;
if(validate.Digits(args[j]))
{
std::string k = args[j];
Genesis::WindowX = atoi(k.c_str());
ProperArgument = true;
i=j;
std::string m = "Windows \"-X\" value set to: " + k;
ConsoleLog.info(m);
}else{
ConsoleLog.error("Inproper argument for -X only INT is allowed!");
Genesis::WindowX = 0;
ProperArgument = false;
i=j;
}
}
if(arg=="-Y")
{
j = i;
j++;
if(validate.Digits(args[j]))
{
std::string k = args[j];
Genesis::WindowY = atoi(k.c_str());
ProperArgument = true;
i=j;
std::string m = "Windows \"-Y\" value set to: " + k;
ConsoleLog.info(m);
}else{
ConsoleLog.error("Inproper argument for -Y only INT is allowed!");
Genesis::WindowY = 0;
ProperArgument = false;
i=j;
}
}
if(ProperArgument==true){
std::string a = "Succesfully Recognized: \""+arg+"\"";
ConsoleLog.info(a);
}else{
std::string b = "Succesfully Recognized: "+arg;
ConsoleLog.error("Not a valid argument! \""+arg+"\"");
}
}
}
/**
If flags are dependant on other flags, checks should be added here!
*/
void Genesis::ValidateFlags()
{
if((Genesis::WindowX > 0 && Genesis::WindowY <= 0) || (Genesis::WindowY > 0 && Genesis::WindowX <= 0)) //Checks to make sure both X and Y are correct.
{
ConsoleLog.error("\"-X\" and \"-Y\" must be used at the same time, have a value greater than 0, and be proper integers!");
ConsoleLog.error("\"-X\" and \"-Y\" will be ignored.");
if(Windowed)
{
ConsoleLog.error("\"-WM\" Was dected but due to argument errors will be disabled.");
Windowed = false;
}
}
if((Genesis::WindowX>0)&&(Genesis::WindowY>0)&&(Genesis::Windowed=false)) //Makes sure that windowed mode is enabled when X and Y are correct.
{
ConsoleLog.error("\"-X\" and \"-Y\" were declared but windowed mode was never set! Did you forget a \"-WM\" ?");
ConsoleLog.error("\"-X\" and \"-Y\" will be ignored.");
}
}
/**
Returns the defined version of Genesis running.
*/
std::string Genesis::GetVersion()
{
return GenesisVersion;
}
bool Genesis::isClosing()
{
if(Genesis::engineCoreState==Closing)
return true;
else
return false;
}
There, that should be enough code for a while. ^^
Let me know your input tho. I want to do things PROPERLY. XD If someone seems very wrong, its likely I just didn't know how to do it right.
Just know, some parts are purposely torn apart right now in attempt to locate problems.