Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

[C++] Program działa tylko w Visualu 2012

Ostatnio zmodyfikowano 2013-05-11 21:44
Autor Wiadomość
Arturr300
Temat założony przez niniejszego użytkownika
[C++] Program działa tylko w Visualu 2012
» 2013-05-11 15:26:25
Witam.
Mam problem, nad którym siedzę pół dnia...
Program działa w środowisku programistycznym ( Visual Studio 2012 Express for Desktop ), a odpalony poprzez .exe w folderze Release wywala od razu po włączeniu (Program .exe przestał działać ).
Link do projektu (wymagany VS 2012). Mógłbym wrzucić sam kod, ale wtedy to nic nie da - kod jest chyba prawidłowy, skoro w VS działa...

W pliku CApp.cpp zaznaczona jest linijka, po wykomentowaniu której błędu nie ma. Jest oznaczona: // TUTAJ WYWALA PROGRAM

https://www.dropbox.com/s/cq6na9zjzds273e/PROJEKT.rar

Proszę o pomoc, bo to jest niemożliwe ;x

PS.
Debug działa zarówno w programie, jak i bezpośrednio poprzez .exe
P-82675
pekfos
» 2013-05-11 15:32:17
kod jest chyba prawidłowy
zaznaczona jest linijka, po wykomentowaniu której błędu nie ma.
Prawidłowy kod działa prawidłowo: wklej go.
P-82677
Arturr300
Temat założony przez niniejszego użytkownika
» 2013-05-11 15:42:16
CApp.h:
C/C++
#pragma once
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <sstream>
#include <iostream>
#include <vector>
#include <typeinfo>
#include "CTools.h"
#include <fstream>
#define _ROZ_SZER sf::VideoMode::getDesktopMode().width
#define _ROZ_WYS sf::VideoMode::getDesktopMode().height
#define _FULLSCREEN 0

#define _mouse_X ((sf::Mouse::getPosition().x- (640-(_G->kamera.getCenter().x))) / SCALE)
#define _mouse_Y ((sf::Mouse::getPosition().y- (512-(_G->kamera.getCenter().y))) / SCALE)
using namespace std;

const float SCALE = 60.0f;


enum SHAPE { ChainShape, CircleShape, EdgeShape, PolygonShape };

struct SShape
{
    float width, height;
    float radius;
    SHAPE shape;
    SShape( SHAPE shape, float width, float height )
        : width( width )
        , height( height )
        , shape( shape )
    { };
    SShape( SHAPE shape, float radius )
        : radius( radius )
        , shape( shape )
    { };
};

struct SUserData
{
    bool naZiemi;
    string nazwa;
    SUserData( string nazwa )
        : nazwa( nazwa )
    { };
    SUserData()
        : nazwa( "Default" )
    { };
};

class CApp {
public:
    sf::RenderWindow window;
    sf::Event zdarzenie;
    float fps, fps_currentTime, fps_lastTime;
    sf::Clock fps_clock;
   
   
    void Init()
    {
        window.create( sf::VideoMode::getDesktopMode(), "Craftmine" );
        //window.setKeyRepeatEnabled(false);
    }
    void Game();
    bool isPressed( Key klawisz )
    {
        if( sf::Keyboard::isKeyPressed(( sf::Keyboard::Key ) klawisz ) ) return true;
        else return false;
       
    };
   
   
    bool repeat;
    bool isReleased;
    bool firstrun;
    int i2;
    vector < int > v_id;
   
    vector < int > HeldKolejka;
   
    bool overlap;
   
    vector < CisHeld *> v_Held;
   
    int isHeld( Key klawisz, float czas_ms, int id );
   
   
    CApp()
    {
        i2 = 0;
        repeat = false;
        firstrun = false;
    }
    virtual ~CApp() { };
    static CApp * Instance()
    {
        if( !m_instance )
             m_instance = new CApp;
       
        return m_instance;
    }
   
   
private:
    static CApp * m_instance;
   
   
   
};



CApp.cpp:
C/C++
#include "CApp.h"
CApp * CApp::m_instance = 0;
extern class CisHeld;
void CApp::Game()
{
    Init();
   
    while( window.isOpen() )
    {
       
        if( isHeld( T, 10, 1 ) == 1 )
        {
            cout << "Wcisnieto T" << endl;
        }
       
        window.display();
        window.clear( sf::Color::Blue );
    }
   
   
   
}
int CApp::isHeld( Key klawisz, float czas_ms, int id )
{
    if(( v_id.size() > 0 && v_Held.size() > 0 || firstrun == false ) && isReleased )
    {
        for( int i = 0; i < v_id.size(); ++i )
        {
            if( v_id[ i ] == id ) repeat = true;
           
        }
        if( !repeat )
        {
            v_Held.push_back( new CisHeld( klawisz, czas_ms, id ) );
            v_id.push_back( id );
           
        }
        for( int i = 0; i < v_id.size(); ++i )
        {
            if( v_Held[ i ]->isHeld() != 0 )
            {
               
                HeldKolejka.push_back( v_id[ i ] );
                isReleased = false;
                i2 = i;
            }
           
        }
       
    }
    if( !( sf::Keyboard::isKeyPressed(( sf::Keyboard::Key ) v_Held[ i2 ]->klawisz ) ) && isReleased == false ) // TUTAJ WYWALA PROGRAM
    {
        isReleased = true;
    }
   
    for( int i = 0; i < HeldKolejka.size(); ++i )
    {
        if( HeldKolejka[ i ] == id ) { HeldKolejka.erase( HeldKolejka.begin() + i ); return id; }
       
    }
   
   
    return 0;
   
}

CTools.h:
C/C++
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <sstream>
#include <iostream>
#include <vector>
#include <typeinfo>
using namespace std;

enum Key
{
    Unknown = - 1, ///< Unhandled key
    A = 0, ///< The A key
    B, ///< The B key
    C, ///< The C key
    D, ///< The D key
    E, ///< The E key
    F, ///< The F key
    G, ///< The G key
    H, ///< The H key
    I, ///< The I key
    J, ///< The J key
    K, ///< The K key
    L, ///< The L key
    M, ///< The M key
    N, ///< The N key
    O, ///< The O key
    P, ///< The P key
    Q, ///< The Q key
    R, ///< The R key
    S, ///< The S key
    T, ///< The T key
    U, ///< The U key
    V, ///< The V key
    W, ///< The W key
    X, ///< The X key
    Y, ///< The Y key
    Z, ///< The Z key
    Num0, ///< The 0 key
    Num1, ///< The 1 key
    Num2, ///< The 2 key
    Num3, ///< The 3 key
    Num4, ///< The 4 key
    Num5, ///< The 5 key
    Num6, ///< The 6 key
    Num7, ///< The 7 key
    Num8, ///< The 8 key
    Num9, ///< The 9 key
    Esc, ///< The Escape key
    LControl, ///< The left Control key
    LShift, ///< The left Shift key
    LAlt, ///< The left Alt key
    LSystem, ///< The left OS specific key: window (Windows and Linux), apple (MacOS X), ...
    RControl, ///< The right Control key
    RShift, ///< The right Shift key
    RAlt, ///< The right Alt key
    RSystem, ///< The right OS specific key: window (Windows and Linux), apple (MacOS X), ...
    Menu, ///< The Menu key
    LBracket, ///< The [ key
    RBracket, ///< The ] key
    SemiColon, ///< The ; key
    Comma, ///< The , key
    Period, ///< The . key
    Quote, ///< The ' key
    Slash, ///< The / key
    BackSlash, ///< The \ key
    Tilde, ///< The ~ key
    Equal, ///< The = key
    Dash, ///< The - key
    Space, ///< The Space key
    Return, ///< The Return key
    BackSpace, ///< The Backspace key
    Tab, ///< The Tabulation key
    PageUp, ///< The Page up key
    PageDown, ///< The Page down key
    End, ///< The End key
    Home, ///< The Home key
    Insert, ///< The Insert key
    Delete, ///< The Delete key
    Add, ///< The + key
    Subtract, ///< The - key
    Multiply, ///< The * key
    Divide, ///< The / key
    Left, ///< Left arrow
    Right, ///< Right arrow
    Up, ///< Up arrow
    Down, ///< Down arrow
    Numpad0, ///< The numpad 0 key
    Numpad1, ///< The numpad 1 key
    Numpad2, ///< The numpad 2 key
    Numpad3, ///< The numpad 3 key
    Numpad4, ///< The numpad 4 key
    Numpad5, ///< The numpad 5 key
    Numpad6, ///< The numpad 6 key
    Numpad7, ///< The numpad 7 key
    Numpad8, ///< The numpad 8 key
    Numpad9, ///< The numpad 9 key
    F1, ///< The F1 key
    F2, ///< The F2 key
    F3, ///< The F3 key
    F4, ///< The F4 key
    F5, ///< The F5 key
    F6, ///< The F6 key
    F7, ///< The F7 key
    F8, ///< The F8 key
    F9, ///< The F9 key
    F10, ///< The F10 key
    F11, ///< The F11 key
    F12, ///< The F12 key
    F13, ///< The F13 key
    F14, ///< The F14 key
    F15, ///< The F15 key
    Pause, ///< The Pause key
   
    KeyCount ///< Keep last -- the total number of keyboard keys
};

class CisHeld
{
public:
    sf::Clock timer;
    bool trzymanie;
    Key klawisz;
    float czas_wms;
    bool czyUruchomiono;
    int id;
    CisHeld( Key klawisz2, float czas_wms2, int id2 )
    {
        id = id2;
        klawisz = klawisz2;
        czas_wms = czas_wms2;
        czyUruchomiono = false;
    }
   
   
    int isHeld()
    {
        //czas_ms=czas_wms;
        if( !czyUruchomiono )
        {
            czyUruchomiono = true;
            timer.restart();
        }
       
        timer.getElapsedTime().asMicroseconds();
       
        if( timer.getElapsedTime().asMilliseconds() >= czas_wms )
        {
            timer.restart(); if( trzymanie == true )
            {
                czyUruchomiono = false;
               
               
                return id;
            }
        }
       
        if( sf::Keyboard::isKeyPressed(( sf::Keyboard::Key ) klawisz ) ) trzymanie = true;
        else
        {
            timer.restart(); trzymanie = false; czyUruchomiono = false; return 0;
        }
       
        return 0;
       
    }
   
};

Main.cpp:
C/C++
#include <SFML/Graphics.hpp>
#include <iostream>
#include <conio.h>
#include "CApp.h"
using namespace std;

int main()
{
   
    CApp::Instance()->Game();
   
    return 0;
}


PS.
Przepraszam za bałagan w kodzie.
Funkcja isHeld() była używana w moim poprzednim projekcie - działała i nadal działa bardzo dobrze
P-82679
pekfos
» 2013-05-11 16:24:57
Masz pewność, że w oznaczonej przez Ciebie linii kodu, kontener v_Held zawiera przynajmniej i2+1 elementów?
P-82684
Arturr300
Temat założony przez niniejszego użytkownika
» 2013-05-11 21:44:03
Tak, nawet sprawdzałem w trybie debug i się zgadza.

Po prostu w trybie Release działa w Visualu 2012, a uruchomiony .exe z folderu Release już nie ;/


Edit:
Naprawiłem to. Czuję się jak idiota :<
Wystarczyło dodać sprawdzanie, czy w wektorze jest więcej elementów od 0.
C/C++
if( v_Held.size() > 0 )
{
    if( !( sf::Keyboard::isKeyPressed(( sf::Keyboard::Key ) v_Held[ i2 ]->klawisz ) ) && isReleased == false )
    {
        isReleased = true;
    }
}

Dzięki za podsunięcie dobrego tropu.
Zamykam
P-82729
« 1 »
  Strona 1 z 1