2016-05-24 6 views
0

私はかなり一般的な質問がありますが、少なくとも正しい方向で私を指揮することができれば幸いです。C++ Visual Studioリリース未使用のコードクラッシュを作成する

プロジェクトを作成しました。私は/ MDdフラグを付けてデバッグモードでビルドしていました。 しかし、それはperfomanceの問題を持ち始めたので、リリースモードでそれを試してみた。 問題は、/ MDまたは/ MTフラグとリリースモードを使用すると、アプリケーションが即座にクラッシュすることです。 その理由を調べようとしました。それはデバッグで正常に動作します。私はいくつかのコード変更を試みましたが、何も助けませんでした。だから、私のアプリをちょうど始め、残りのコードをコメントアウトすることにした。しかし、それはまだクラッシュしていた。私のコードが使われていなくても。私がコードのこれらの未使用部分を完全に削除したときだけ、クラッシュしませんでした。

私はそれが変則的なinicialization /宣言を持つものだと思うが、私は何を探すべきかは不明だ。

誰かが、アプリケーションがクラッシュする可能性があるのは、それが宣言/ Inaticizationであっても、ランタイムでは使用されていないとしても、

私は何とか自分の問題が何であるかを理解できることを願っています。

ありがとうございました!

EDIT:未使用のコードがプロジェクトにある場合にクラッシュするコードですが、未使用のコードを削除するとクラッシュしません。

#include "core/oxygine.h" 
#include "Stage.h" 
#include "DebugActor.h" 

//#include "Galatex.h" 


using namespace oxygine; 


//called each frame 
int mainloop() 
{ 
    //galatex_update(); 
    //update our stage 
    //update all actors. Actor::update would be called also for all children 
    getStage()->update(); 

    if (core::beginRendering()) 
    { 
     Color clearColor(32, 32, 32, 255); 
     Rect viewport(Point(0, 0), core::getDisplaySize()); 
     //render all actors. Actor::render would be called also for all children 
     getStage()->render(clearColor, viewport); 

     core::swapDisplayBuffers(); 
    } 

    //update internal components 
    //all input events would be passed to Stage::instance.handleEvent 
    //if done is true then User requests quit from app. 
    bool done = core::update(); 

    return done ? 1 : 0; 
} 

//it is application entry point 
void run() 
{ 
    ObjectBase::__startTracingLeaks(); 

    //initialize Oxygine's internal stuff 
    core::init_desc desc; 

#if OXYGINE_SDL || OXYGINE_EMSCRIPTEN 
    //we could setup initial window size on SDL builds 
    desc.w = 1800; 
    desc.h = 1000; 
    //marmalade settings could be changed from emulator's menu 
#endif 


    //galatex_preinit(); 
    core::init(&desc); 


    //create Stage. Stage is a root node 
    Stage::instance = new Stage(true); 
    Point size = core::getDisplaySize(); 
    getStage()->setSize(size); 

    //DebugActor is a helper actor node. It shows FPS, memory usage and other useful stuff 
    DebugActor::show(); 

    //initialize this example stuff. see example.cpp 
    //galatex_init(); 

#ifdef EMSCRIPTEN 
    /* 
    if you build for Emscripten mainloop would be called automatically outside. 
    see emscripten_set_main_loop below 
    */ 
    return; 
#endif 


    //here is main game loop 
    while (1) 
    { 
     int done = mainloop(); 
     if (done) 
      break; 
    } 
    //user wants to leave application... 

    //lets dump all created objects into log 
    //all created and not freed resources would be displayed 
    ObjectBase::dumpCreatedObjects(); 

    //lets cleanup everything right now and call ObjectBase::dumpObjects() again 
    //we need to free all allocated resources and delete all created actors 
    //all actors/sprites are smart pointer objects and actually you don't need it remove them by hands 
    //but now we want delete it by hands 

    //check example.cpp 
    //galatex_destroy(); 


    //renderer.cleanup(); 

    /**releases all internal components and Stage*/ 
    core::release(); 

    //dump list should be empty now 
    //we deleted everything and could be sure that there aren't any memory leaks 
    ObjectBase::dumpCreatedObjects(); 
    ObjectBase::__stopTracingLeaks(); 
    //end 
} 

#ifdef __S3E__ 
int main(int argc, char* argv[]) 
{ 
    run(); 
    return 0; 
} 
#endif 


#ifdef OXYGINE_SDL 

#include "SDL_main.h" 
extern "C" 
{ 
    int main(int argc, char* argv[]) 
    { 
     run(); 
     return 0; 
    } 
}; 
#endif 

#ifdef EMSCRIPTEN 
#include <emscripten.h> 

void one() { mainloop(); } 

int main(int argc, char* argv[]) 
{ 
    run(); 
    emscripten_set_main_loop(one, 0, 0); 
    return 0; 
} 
#endif 
+1

コードを投稿する必要があります(ごくわずかな例がクラッシュしていると主張しています)。 – SergeyA

+0

VSでテンプレートからプロジェクトを作成した場合、そのすべてのスイッチについて心配する必要はありません。デバッグまたはリリースのいずれかを選択します。私はあなたが新しいプロジェクトを作成し、それにすべてのコードをコピーすることをお勧めします。 – marcinj

+0

未使用のコードでクラッシュするコードを追加しましたが、プロジェクトから未使用のコードを完全に削除すると問題ありません。しかし、私はそれがanyhingに役立つとは思わない。 –

答えて

0

だから、私のような他の初心者のためにここに書いてみましょう。

私の問題は静的およびその他の変数の「機能外」の初期化でした。例:

MyObject object = new MyObject(); //This was the reason, why it was crashing, just had to move 
             // initialization of such variables to function which was called with object creation.     
    void MyClass::myFunction(){ 

     object->doSomething();  
    } 

したがって、これらの変数のinicializationが開始されたときに、プログラムのクラッシュが発生しました。 注:オブジェクトに問題があるようですが、Integersなどの変数が原因で問題ないと思われます。

なぜ、これがデバッグモードで許可されているのかわからないが、開始直後にリリースモードがクラッシュする可能性があります。誰かがこのコメントの下で答えて、この動作を説明することができます。たくさんの悪いものがありますが、私は試しています。それはいいのですよね? :D

私はあなたの時間の人をあまりにも無駄にしなかったと思うし、多分このポストは将来誰かに役立つだろう。

関連する問題