2016-07-08 1 views
0

リファレンスクラスは、コンパイラがクラッシュする(ただし、関数内で動作します)、現在

class commandsListClass 
{ 
public: 
    std::string name; 
    std::string description; 
    std::vector<std::string> commands; 
    columnHeaders headersRequired; 
    void (*function)(System::Object ^); 
    std::string recoveryFileHeader; 
    void reset() 
    { 
     name = ""; 
     description = ""; 
     commands.clear(); 
     headersRequired.reset(); 
     recoveryFileHeader = ""; 
     function = dummyFunc; // dummyFunc uses the same members as the intended - this is to ensure it is defined. DummyFunc is empty, returns void etc 
    } 
    commandsListClass() 
    { 
     reset(); 
    } 
}; 

私は以下のコードを実行した場合、コンパイラは

// This crashes the compiler 
System::Threading::ThreadPool::QueueUserWorkItem(gcnew System::Threading::WaitCallback(global::commandsList[index].function), ti); 

Visual of the crashed compiler

をクラッシュ
1>------ Build started: Project: MyProject, Configuration: Release x64 ------ 
1> project.cpp 
1>c:\users\guy\documents\visual studio 2012\projects\MyProject\MyProject\Form1.h(807): fatal error C1001: An internal error has occurred in the compiler. 
1> (compiler file 'msc1.cpp', line 1443) 
1> To work around this problem, try simplifying or changing the program near the locations listed above. 
1> Please choose the Technical Support command on the Visual C++ 
1> Help menu, or open the Technical Support help file for more information 
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 

私が呼び出しているのと同じ関数内のメンバーを宣言し、それは、グローバル:: commandsList [インデックス] .functionに、それはコンパイルし、正しく

// This runs correctly  
void (*func)(System::Object ^); 
func = global::commandsList[index].function; 
System::Threading::ThreadPool::QueueUserWorkItem(gcnew System::Threading::WaitCallback(func), ti); 

グローバルを実行します:: commandsListは、任意のアイデアタイプcommandsListClass

のベクトルのですか?ブラウジングGoogleとは、最適化しないようにコンパイラを変更することをお勧めします。これは成功していませんでした。コードはこのように書かれている:

インデックスは関数の変数があることが保証され
  • グローバル:: commandsListベクトルの有効なメンバーを指していない場合は、コード内のそのポイントに到達することはできません
    • 作成時にdummyFuncに設定するか、コード内の別の場所に設定して正しい(要求された)関数に設定します。

    ご協力いただければ幸いです。

    編集1:これは、Visual Studio 2012を使用している、ここでのWindows 7のx64

  • +1

    私の提案は、関数ポインタの代わりに 'gcroot 'を格納することです。 –

    答えて

    0

    は単純化されたレポです:

    public delegate void MyDel(Object^); 
    
    void g(Object^) {} 
    
    struct A { 
        static void(*fs)(Object^); 
        void(*f)(Object^); 
        gcroot<MyDel^> del; 
    }; 
    
    void(*fg)(Object^); 
    
    void h() 
    { 
        void (*f)(Object^); 
        A a; 
    
        gcnew MyDel(f); 
        gcnew MyDel(fg); 
        gcnew MyDel(a.fs); 
        a.del = gcnew MyDel(g); 
    
        //gcnew MyDel(a.f); // this line fails 
    
        // work around 
        f = a.f; 
        gcnew MyDel(f); 
    } 
    

    のみ非静的メンバ変数は失敗します。コンパイラのバグのようです。地元の中間体を使用してそれを回避する。

    また、gcrootを使用するルーカスの提案が優れています。

    +0

    ありがとうございましたが、ローカルメンバーを使用するというアイデアは既に問題になっていました。 –

    関連する問題