Sign in to follow this  
Followers 0
BaneTrapper

SFML application on exit dosent return 0

9 posts in this topic

Hello.
When i close application i always get (Process returned -2147418113 <0x8000FFFF>...)
And sometimes (-1073741819 <0xC0000005> Access Violation) if opened and closed in rapid succession.

I have return 0 at end of the code and i am wondering what may be causing a error like this, since i am using only c++ standard(string, int, enums) and sfml2.0 lib, no pointers or personally using heap memory space.
Before i shutdown all music, close window, and process still returns (-2147418113 <0x8000FFFF>).

The program works as expected, it didn't crash or shutdown for unknown reason. and i run it at least 10min.

Any suggestions on what should i turn my attention towards to fix this problem?
If some personal experience tips.

Id post code, but its months of coding... Edited by BaneTrapper
0

Share this post


Link to post
Share on other sites
Most likely somewhere in your cleanup code [s]you're accessing a pointer that is no longer valid [/s] (on rereading your post, I should say that) in your calls to SFML you're probably indirectly accessing memory that's already be released. Perhaps the best thing to do is open the program in a debugger, set a breakpoint where the shutdown begins, then step through it until you find the crash. An alternative is to insert printf statements throughout the cleanup code to see if that helps you find it. But using the debugger is likely the better way to go. Edited by Aldacron
1

Share this post


Link to post
Share on other sites
[quote name='Aldacron' timestamp='1354188785' post='5005266']
Most likely somewhere in your cleanup code [s]you're accessing a pointer that is no longer valid [/s] (on rereading your post, I should say that) in your calls to SFML you're probably indirectly accessing memory that's already be released. Perhaps the best thing to do is open the program in a debugger, set a breakpoint where the shutdown begins, then step through it until you find the crash. An alternative is to insert printf statements throughout the cleanup code to see if that helps you find it. But using the debugger is likely the better way to go.
[/quote]
No error but when i reach return 0.
End of main and probably where all code is being cleaned up this error pops up
[CODE]
Program received signal SIGSEGV, Segmentation fault.
In ?? () (C:\Windows\system32\nvoglv32.dll)
[/CODE]
So the deconstructors are problem?
And if so, i have made total of 0 deconstructors.
0

Share this post


Link to post
Share on other sites
[quote name='RulerOfNothing' timestamp='1354191047' post='5005274']
Can you give us the main() function?
[/quote]

[CODE]
int main()
{
srand(time(NULL));
Application objApp;
objWindow.SetupWindow();
objFps.SetupFps(objApp);
objTextures.SetupTextures();
objFunctions.SetupFunctions(objApp);
objMainMenu.SetupMainMenu(objApp);
objOptions.SetupOptions(objApp);
objOptions.UpdateOptions(objApp); // Call this after objOptions.SetupOptions
//ForGame
objSquad.SetupSquad(objApp);//Call this before SquadCreation to have proper values
objSquadCreation.SetupSquadCreation(objApp);
objAudio.PlayMusic(rand()%4);
while(objBools.isOn == true)
{
if(objBools.Focus == true) // Normal game loop
{
//before loop stuff
//before loop stuff end
objFps.CalculateFps(); // Calculates fps so its displayed correctly
objEventHandle.HandleEvents(objApp); // Handle events
objWindow.Screen.clear(sf::Color::Cyan); //Clear screen after each blit
//Game loop
if(objBools.isGame == true)
{
if(objBools.isGame_Created == false)
{
//Create new game Reset all data
objBools.isGame_Created = true;
objBools.isGame_SquadCreation = true;
}
else
{
//Normal game loop
if(objBools.isGame_SquadCreation == true)
{
objSquadCreation.DrawSquad(objApp);
}
}
}
//Menu loop
else if(objBools.isMenu == true)
{
if(objBools.isOptions == true)
{
//Draw options
objOptions.CheckAudio(objApp);
objOptions.UpdateAudio(objApp);
objOptions.CheckBackButton(objApp);
objOptions.CheckFullScreen(objApp);
objOptions.DrawOptions(objWindow.Screen);
}
else
{
//Draw menu
objMainMenu.HightLightButtons(objApp);
objMainMenu.DrawMainMenu(objApp);
}
objMainMenu.DrawCredits(objWindow.Screen);
}
objFps.DrawFps(objWindow.Screen); // Draw FPS
objWindow.Screen.display(); // Display to monitor buffer
//After loop cleanup
objEventHandle.isleftMouseDown = false;
//After loop cleanup end
}
else //No focus on screen
{
objEventHandle.HandleEvents(objApp); // Handle events
objWindow.Screen.display(); // Display to monitor buffer
}
}
objAudio.MenuMusic.stop();
objWindow.Screen.close();
return 0; //I get error here when debugging
}
[/CODE] Edited by BaneTrapper
0

Share this post


Link to post
Share on other sites
Just because you didn't create your own destructor (deconstructor isn't the appropriate name, FYI) doesn't mean much. The compiler creates destructors on its own. And you maybe *should* have created destructors.

A few observations. First, tat's quite a lot of globals you have there. You have the following objects that aren't created in main():
objWindow, objFps, objTextures, objFunctions, ,objMainMenu, objOptions, objSquad, objSquadCreation, objAudio

The problem could be in any one of these or even objApp. My theory is that because many of the obj* objects are created and use objApp that there's an issue with how you're storing objApp in the other objects. objApp is destroyed before the globals and this could be causing issues somehow. So, two things you should do. First, create a block around objApp like this:

[CODE]
int main() {
srand(time(NULL));
{ // Add this!
Application objApp;

// the rest of your code here

} // Add this! ObjApp is destroyed here instead of after the return

return 0;
}
[/CODE]

If the problem is when objApp is destroyed, then you'll get an error before you reach the return statement. Otherwise the problem is when one of the globals is destroyed.

Second thing you should do is post the code of Application and one or two of the objects that use objApp.
1

Share this post


Link to post
Share on other sites
[quote name='nobodynews' timestamp='1354216099' post='5005404']
If the problem is when objApp is destroyed, then you'll get an error before you reach the return statement. Otherwise the problem is when one of the globals is destroyed.

Second thing you should do is post the code of Application and one or two of the objects that use objApp.
[/quote]
Ok this is what i did
[CODE]
int main()
{
{
AllStuffClass objQWE;
int i = objQWE.MainLoop();
}//Code should be destroyed here.
return 0; // I get segmentation error here
}
[/CODE]
I put break point at each line just to be sure, and it really pops up at return.
May it be that configurations of project are incorrect?


EDIT::
I am unsure, but i think segmentation error pops us when the debug reaches end of main
i mean closing brackets of the main.
[CODE]
At C:\C++\HeroesPath\main.cpp:18
Continuing...
Program received signal SIGSEGV, Segmentation fault.
In ?? () (C:\Windows\system32\nvoglv32.dll)
[/CODE]
line 18 is closing bracket for main...
so segmentation error comes after that, but there is no code run after that.

I am running codeblocks 10.05 IDE with SFML 2.0 library and GNUGCC compiler i think(Mingw)
I will try to port all the code to visual basic and post results.


And here are some classes that use Applications objApp object
[CODE]
//These are my only globals i have
#ifndef DEFINE_H_INCLUDED
#define DEFINE_H_INCLUDED

const int SCREEN_WIDTH = 1024;
const int SCREEN_HEIGHT = 768;
const int FPS = 60;

const int MAPSIZE_X = 32;
const int MAPSIZE_Y = 24;
const int TILESIZE = 32;

enum State
{
state_Up = 0,
state_Down,
state_Left,
state_Right
};

enum ClassType
{
Knight1 = 0,
Knight2, //1
Paladin1, // 2
Paladin2, // 3
Warrior1, // 4
Warrior2, // 5
Wizard1, // 6
Wizard2, // 7
Priest1, // 8
Priest2, // 9
Mage1, // 10
Mage2, // 11
Thief1, // 12
Thief2, // 13
Ninja1, // 14
Ninja2, // 15
Wanderer1, // 16
};

enum TypeMovment
{
Up = 0,
Down = 1,
Left = 2,
Right = 3
};

enum TileType
{
tiletype_none = 0,
tiletype_grass,
tiletype_water
};
#endif // DEFINE_H_INCLUDED

///////////////////////////////////SquadCreation.h
#ifndef SQUADCREATION_H
#define SQUADCREATION_H

#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <string>

class Application;
class SquadMember;

class SquadCreation
{
public:
SquadCreation();
void SetupSquadCreation(Application& objApp);

void DrawSquad(Application& objApp);
void UpdateSquad(Application& objApp);
void CheckSquad(Application& objApp);
void GrabIcon(SquadMember& objSquadMember, sf::Sprite& sprIcon);
std::string GrabClassName(SquadMember& objSquadMember);


private:
//Book itself
sf::Sprite sprBook;

//Page 1
sf::Text txtGroupHintandName;
std::string strGroupName;

//Page 2
sf::Text txtPerson1;
sf::Sprite sprIcon1;
sf::Text txtName1;

sf::Text txtPerson2;
sf::Sprite sprIcon2;
sf::Text txtName2;

sf::Text txtPerson3;
sf::Sprite sprIcon3;
sf::Text txtName3;

//HightLight
bool isHightLight;
sf::Sprite HighLight;

};

#endif // SQUADCREATION_H


////////////////////////////////////////SquadCreation.cpp
#include "SquadCreation.h"
#include "Application.h"
#include "Units.h"

SquadCreation::SquadCreation()
{
isHightLight = false;
}

void SquadCreation::SetupSquadCreation(Application& objApp)
{
//Book itself
sprBook.setTexture(objApp.objTextures.OpenBook);

//Page 1
txtGroupHintandName.setCharacterSize(32);
txtGroupHintandName.setColor(sf::Color::Black);
txtGroupHintandName.setFont(objApp.objFonts.FontGame);
//txtGroupHintandName.setString(std::string(Black"The group name was ") + std::string("EnterGroupNameHere")); //EnterGroupNameHere is string whych the group name is actually
txtGroupHintandName.setString(static_cast<std::string>("The group name was:\n") + static_cast<std::string>("EnterGroupNameHere")); //EnterGroupNameHere is string whych the group name is actually
txtGroupHintandName.setPosition(110, 100);

strGroupName = "";

//Page 2
//Person1
txtPerson1.setCharacterSize(32);
txtPerson1.setColor(sf::Color::Black);
txtPerson1.setFont(objApp.objFonts.FontGame);
txtPerson1.setString(std::string("1st hero was: ") + GrabClassName(objApp.objSquad.Member1));
txtPerson1.setPosition(565, 100);

sprIcon1.setTexture(objApp.objTextures.SpriteSheet);
GrabIcon(objApp.objSquad.Member1, sprIcon1);
sprIcon1.setPosition(860, 152);

txtName1.setCharacterSize(32);
txtName1.setColor(sf::Color::Black);
txtName1.setFont(objApp.objFonts.FontGame);
txtName1.setString("Named: " + objApp.objSquad.Member1.name);
txtName1.setPosition(565, 150);

//Person2
txtPerson2.setCharacterSize(32);
txtPerson2.setColor(sf::Color::Black);
txtPerson2.setFont(objApp.objFonts.FontGame);
txtPerson2.setString(std::string("2nd hero was: ") + GrabClassName(objApp.objSquad.Member2));
txtPerson2.setPosition(565, 242);

sprIcon2.setTexture(objApp.objTextures.SpriteSheet);
GrabIcon(objApp.objSquad.Member2, sprIcon2);
sprIcon2.setPosition(860, 290);

txtName2.setCharacterSize(32);
txtName2.setColor(sf::Color::Black);
txtName2.setFont(objApp.objFonts.FontGame);
txtName2.setString("Named: " + objApp.objSquad.Member2.name);
txtName2.setPosition(565, 290);

//Person 3
txtPerson3.setCharacterSize(32);
txtPerson3.setColor(sf::Color::Black);
txtPerson3.setFont(objApp.objFonts.FontGame);
txtPerson3.setString(std::string("3rd hero was: ") + GrabClassName(objApp.objSquad.Member3));
txtPerson3.setPosition(565, 380);

sprIcon3.setTexture(objApp.objTextures.SpriteSheet);
GrabIcon(objApp.objSquad.Member3, sprIcon3);
sprIcon3.setPosition(860, 432);

txtName3.setCharacterSize(32);
txtName3.setColor(sf::Color::Black);
txtName3.setFont(objApp.objFonts.FontGame);
txtName3.setString("Named: " + objApp.objSquad.Member3.name);
txtName3.setPosition(565, 430);

//HighLight
HighLight.setTexture(objApp.objTextures.HightLight);
HighLight.setPosition(0, 0);

}

void SquadCreation::DrawSquad(Application& objApp)
{
sf::RenderWindow& Screen = objApp.objWindow.Screen;
//Book
Screen.draw(sprBook);
if(isHightLight == true){Screen.draw(HighLight);}//Draw hightlight
//Page 1
Screen.draw(txtGroupHintandName);
//Maybe story
//Page 2
Screen.draw(txtPerson1);
Screen.draw(txtPerson2);
Screen.draw(txtPerson3);
Screen.draw(sprIcon1);
Screen.draw(sprIcon2);
Screen.draw(sprIcon3);
Screen.draw(txtName1);
Screen.draw(txtName2);
Screen.draw(txtName3);
}

void SquadCreation::UpdateSquad(Application& objApp)
{
//Updated squad after Squad has bean edited
}

void SquadCreation::CheckSquad(Application& objApp)
{
//Name entering
int x1 = objApp.objEventHandle.mouseX, y1 = objApp.objEventHandle.mouseY;
int x2 = 95, y2 = 80, w2 = 350, h2 = 130;
bool isDrawHighlight = false;
bool isleftMouseDown = objApp.objEventHandle.isleftMouseDown;

if(x1 > x2 &&
x1 < x2 + w2 &&
y1 > y2 &&
y1 < y2 + h2)
{
//Collision
HighLight.setPosition(95, 80);
isDrawHighlight = true;
}

//Person1
x2 = 557, y2 = 85, w2 = 350, h2 = 130;
if(x1 > x2 &&
x1 < x2 + w2 &&
y1 > y2 &&
y1 < y2 + h2)
{
//Collision
HighLight.setPosition(557, 85);
isDrawHighlight = true;
if(isleftMouseDown == true)
{
objApp.objFunctions.UpdateSquadMemberInfo(objApp, 0);
}
}

//Person2
x2 = 557, y2 = 227, w2 = 350, h2 = 130;
if(x1 > x2 &&
x1 < x2 + w2 &&
y1 > y2 &&
y1 < y2 + h2)
{
//Collision
HighLight.setPosition(557, 227);
isDrawHighlight = true;
if(isleftMouseDown == true)
{
objApp.objFunctions.UpdateSquadMemberInfo(objApp, 1);
}
}

//Person3
x2 = 557, y2 = 369, w2 = 350, h2 = 130;
if(x1 > x2 &&
x1 < x2 + w2 &&
y1 > y2 &&
y1 < y2 + h2)
{
//Collision
HighLight.setPosition(557, 369);
isDrawHighlight = true;
if(isleftMouseDown == true)
{
objApp.objFunctions.UpdateSquadMemberInfo(objApp, 2);
}
}

if(isDrawHighlight == true)
isHightLight = true;
else
isHightLight = false;

}

void SquadCreation::GrabIcon(SquadMember& objSquadMember, sf::Sprite& sprIcon)
{
switch(objSquadMember.classType)
{
case 0:
sprIcon.setTextureRect(sf::IntRect(128, 1024, 32, 32));
break;

case 1:
sprIcon.setTextureRect(sf::IntRect(128, 1024, 32, 32));
break;

case 2:
sprIcon.setTextureRect(sf::IntRect(160, 1024, 32, 32));
break;

case 3:
sprIcon.setTextureRect(sf::IntRect(160, 1024, 32, 32));
break;

case 4:
sprIcon.setTextureRect(sf::IntRect(192, 1024, 32, 32));
break;

case 5:
sprIcon.setTextureRect(sf::IntRect(192, 1024, 32, 32));
break;

case 6:
sprIcon.setTextureRect(sf::IntRect(224, 1024, 32, 32));
break;

case 7:
sprIcon.setTextureRect(sf::IntRect(224, 1024, 32, 32));
break;

case 8:
sprIcon.setTextureRect(sf::IntRect(128, 1056, 32, 32));
break;

case 9:
sprIcon.setTextureRect(sf::IntRect(128, 1056, 32, 32));
break;

case 10:
sprIcon.setTextureRect(sf::IntRect(160, 1056, 32, 32));
break;

case 11:
sprIcon.setTextureRect(sf::IntRect(160, 1056, 32, 32));
break;

case 12:
sprIcon.setTextureRect(sf::IntRect(192, 1056, 32, 32));
break;

case 13:
sprIcon.setTextureRect(sf::IntRect(192, 1056, 32, 32));
break;

case 14:
sprIcon.setTextureRect(sf::IntRect(224, 1056, 32, 32));
break;

case 15:
sprIcon.setTextureRect(sf::IntRect(224, 1056, 32, 32));
break;

case 16:
sprIcon.setTextureRect(sf::IntRect(128, 1088, 32, 32));
break;

default:
sprIcon.setTextureRect(sf::IntRect(0, 0, 90, 90));
break;

}
//Modifies sprIcon TextureRec to point onto Squad Member class head
}

std::string SquadCreation::GrabClassName(SquadMember& objSquadMember)
{
switch(objSquadMember.classType)
{
case 0:
return "Knight";
break;

case 1:
return "Knight";
break;

case 2:
return "Paladin";
break;

case 3:
return "Paladin";
break;

case 4:
return "Warrior";
break;

case 5:
return "Warrior";
break;

case 6:
return "Wizard";
break;

case 7:
return "Wizard";
break;

case 8:
return "Priest";
break;

case 9:
return "Priest";
break;

case 10:
return "Mage";
break;

case 11:
return "Mage";
break;

case 12:
return "Thief";
break;

case 13:
return "Thief";
break;

case 14:
return "Ninja";
break;

case 15:
return "Ninja";
break;

case 16:
return "Wanderer";
break;

default:
return "error";
break;
}
}

[/CODE] Edited by BaneTrapper
0

Share this post


Link to post
Share on other sites
How old is your SFML2 library? Their was a bug in the RC that caused a similar crash on exit related to the default font used by sf::Text. Explicitly providing a font may solve your crash.

Another common-ish error could be coming from your global objects. The OpenGL context is created along with your sf::RenderWindow. But if one of your globals ends up creating a sf::Texture before your window, then it may cause some problems as the texture depends on the OpenGL context.
1

Share this post


Link to post
Share on other sites
[quote name='BaneTrapper' timestamp='1354231317' post='5005492']
line 18 is closing bracket for main...
so segmentation error comes after that, but there is no code run after that.
[/quote]

None of your code is run after that, true, but the OS is still doing some cleanup of its own after main exits. This sort of error usually indicates that you're stomping memory somewhere. It's at this point that the OS is freeing up resources, including unloading shared libraries and releasing any remaining memory allocated by the program. It has certain markers it uses to manage this stuff. And if corruption has occurred, for example one of those markers has been overwritten, situations like this can arise where the problem does not manifest during runtime but, rather, at exit. In your particular case, the problem is occurring when the graphics driver is being shutdown, which indicates that memory in driver's space has been corrupted somehow.

There are a number of ways to cause this sort of corruption, but they can be hard to find. If you are using VisualC++, you might be able to get more info by calling _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG_DF)|_CRTDBG_CHECK_ALWAYS_DF) during startup. If that doesn't help, another technique is to comment out most of the program, recompile with only a do-nothing main function, and run it. Then you keep uncommenting more functionality, recompiling, and running again until you get the crash. That will help you hone in on the place where the corruption is occurring.
1

Share this post


Link to post
Share on other sites
[quote name='thePyro_13' timestamp='1354252066' post='5005580']
How old is your SFML2 library? Their was a bug in the RC that caused a similar crash on exit related to the default font used by sf::Text. Explicitly providing a font may solve your crash.
Another common-ish error could be coming from your global objects. The OpenGL context is created along with your sf::RenderWindow. But if one of your globals ends up creating a sf::Texture before your window, then it may cause some problems as the texture depends on the OpenGL context.
[/quote]
I will try to update sfml.

[quote name='Aldacron' timestamp='1354252330' post='5005581']
[quote name='BaneTrapper' timestamp='1354231317' post='5005492']
line 18 is closing bracket for main...
so segmentation error comes after that, but there is no code run after that.
[/quote]

None of your code is run after that, true, but the OS is still doing some cleanup of its own after main exits. This sort of error usually indicates that you're stomping memory somewhere. It's at this point that the OS is freeing up resources, including unloading shared libraries and releasing any remaining memory allocated by the program. It has certain markers it uses to manage this stuff. And if corruption has occurred, for example one of those markers has been overwritten, situations like this can arise where the problem does not manifest during runtime but, rather, at exit. In your particular case, the problem is occurring when the graphics driver is being shutdown, which indicates that memory in driver's space has been corrupted somehow.

There are a number of ways to cause this sort of corruption, but they can be hard to find. If you are using VisualC++, you might be able to get more info by calling _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG_DF)|_CRTDBG_CHECK_ALWAYS_DF) during startup. If that doesn't help, another technique is to comment out most of the program, recompile with only a do-nothing main function, and run it. Then you keep uncommenting more functionality, recompiling, and running again until you get the crash. That will help you hone in on the place where the corruption is occurring.
[/quote]
Commenting out the program... Seems like optimal solution. Thanks on help, its work time now.


EDIT::
He...Hello?
Em i allive???
My code is a spaghetti. After a long commenting out code here are resaults.
[CODE]
int main()
{
sf::Music audio;
return 0;
}
[/CODE]Process returned -2147418113 <0x8000FFFF> execution time : 0.100s
Press any key to continue.

Same return value with a basic setup like this one
[CODE]
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);

sf::Music audio;
audio.openFromFile("Mus.ogg");
audio.play();

while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}

window.clear();
window.draw(shape);
window.display();
}

return 0;
}
[/CODE]

So declaring a sf::Music gro... me!!!
I have downloaded newest data from sfml, build it with cmake - MinGW and i still get this error
Am gonna make a new thread on sfml forum. If by any chance you can help am glad to hear it.
Thanks on support you two, keep up the good work!

EDIT 924:
Error is removed by replacing OpenAL32.dll dll file with one from interet. Tho now my application takes 10-15 second to start up.
Edited by BaneTrapper
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