Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualBaneTrapper

Posted 29 November 2012 - 05:40 PM

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.

Ok this is what i did
int main()
{
    {
	    AllStuffClass objQWE;
	    int i = objQWE.MainLoop();
    }//Code should be destroyed here.
    return 0; // I get segmentation error here
}
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.
At C:\C++\HeroesPath\main.cpp:18
Continuing...
Program received signal SIGSEGV, Segmentation fault.
In ?? () (C:\Windows\system32\nvoglv32.dll)
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
//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;
    }
}


#4BaneTrapper

Posted 29 November 2012 - 05:36 PM

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.

Ok this is what i did
int main()
{
    {
	    AllStuffClass objQWE;
	    int i = objQWE.MainLoop();
    }//Code should be destroyed here.
    return 0; // I get segmentation error here
}
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.
At C:\C++\HeroesPath\main.cpp:18
Continuing...
Program received signal SIGSEGV, Segmentation fault.
In ?? () (C:\Windows\system32\nvoglv32.dll)
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.

#3BaneTrapper

Posted 29 November 2012 - 05:30 PM

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.

Ok this is what i did
int main()
{
    {
	    AllStuffClass objQWE;
	    int i = objQWE.MainLoop();
    }//Code should be destroyed here.
    return 0; // I get segmentation error here
}
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.
At C:\C++\HeroesPath\main.cpp:18
Continuing...
Program received signal SIGSEGV, Segmentation fault.
In ?? () (C:\Windows\system32\nvoglv32.dll)
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.

#2BaneTrapper

Posted 29 November 2012 - 05:27 PM

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.

Ok this is what i did
int main()
{
    {
	    AllStuffClass objQWE;
	    int i = objQWE.MainLoop();
    }//Code should be destroyed here.
    return 0; // I get segmentation error here
}
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.
At C:\C++\HeroesPath\main.cpp:18
Continuing...
Program received signal SIGSEGV, Segmentation fault.
In ?? () (C:\Windows\system32\nvoglv32.dll)
line 18 is closing bracket for main...
so segmentation error comes after that, but there is no code run after that.

#1BaneTrapper

Posted 29 November 2012 - 05:21 PM

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.

Ok this is what i did
int main()
{
    {
	    AllStuffClass objQWE;
	    int i = objQWE.MainLoop();
    }//Code should be destroyed here.
    return 0; // I get segmentation error here
}
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?

PARTNERS