2017-09-19 30 views
0

を増加させないと、問題を再現するために値を生成し、私は、次の手順にそれを絞り込む:StepTimer.GetTotalSeconds()は、常に私は単純化のためのDirectX 11を使用してい

  1. 「新しいを作成します。 Visual Studioで "DirectXとXAML App(UWP)"を使用しています(私はVS 2017を使用しています)。
  2. 次のコードでSample3DSceneRenderer :: Updateメソッドに置き換えます

    inline void DebugTrace(const wchar_t *format, ...) 
    { 
        // Generate the message string. 
        va_list args; 
        va_start(args, format); // initialize the argument list 
        wchar_t buffer[1024]; 
        va_end(args); 
    
        OutputDebugStringW(buffer); // this is a Windows function 
    } 
    

は、私が実行します。

void Sample3DSceneRenderer::Update(DX::StepTimer const& timer) 
{ 
    if (!m_tracking) 
    { 
     double total = timer.GetTotalSeconds(); 

     // Convert degrees to radians, then convert seconds to rotation angle 
     float radiansPerSecond = XMConvertToRadians(m_degreesPerSecond); 
     double totalRotation = total * radiansPerSecond; 
     float radians = static_cast<float>(fmod(totalRotation, XM_2PI)); 

     DX::DebugTrace(L"num = %4.2f\t%4.2f\n", radians, total); 

     Rotate(radians); 
    } 
} 
  • を出力ウィンドウに値をトレースするには、以下の機能を追加します。出力ウィンドウには次の値が表示されます:

    num = 0.01 0.01 
        num = 0.02 0.02 
        num = 0.00 0.00 // decreased 
        num = 0.00 0.01 // decreased 
        num = 0.03 0.04 
        num = 0.05 0.06 
        num = 0.02 0.02 // decreased 
        num = 0.06 0.07 
        num = 0.03 0.04 // decreased 
        num = 0.07 0.09 
        num = 0.04 0.06 // decreased 
        num = 0.08 0.11 
        num = 0.06 0.07 // decreased 
        num = 0.10 0.12 
        num = 0.07 0.09 // decreased 
        num = 0.11 0.14 
        num = 0.08 0.11 // decreased 
        num = 0.12 0.16 
        num = 0.10 0.12 // decreased 
        num = 0.11 0.14 
        num = 0.14 0.17 
        num = 0.12 0.16 // decreased 
        num = 0.15 0.19 
        num = 0.16 0.21 
        num = 0.14 0.17 // decreased 
        num = 0.18 0.22 
        num = 0.15 0.19 // decreased 
        num = 0.16 0.21 
        num = 0.19 0.24 
        num = 0.20 0.26 
        num = 0.18 0.22 // decreased 
        etc. 
    

    質問:なぜTotalSecondsの値が増減した後、再び増加しますか?例えば、0.01,0.02,0.00,0.01。彼らはいつも増えてはいけませんか?

  • +0

    私はこの問題をさらに調査したのだが、DirectXPageコンストラクタが二回呼ばれていたことが判明:1回のフレームワーク(ActivateInstance法)により、アプリケーション自体(コールm_directXPage = refの新しいDirectXPageによって別の時間( )をApp.xaml.cppに追加します)。質問が残る:XAMLページが2度インスタンス化されるのはなぜですか?バグですか? – ata6502

    +0

    説明:ページが2回インスタンス化されるため、Updateメソッドが2回呼び出されるため、2つのタイマーが並行して動作します。それは私のバグのようですね。 – ata6502

    答えて

    0

    バグはApp :: OnLaunchedにあります。

    • 直接割付:m_directXPage = ref new DirectXPage();
    • ナビゲーション:テンプレート内のバージョンが2つのDirectXPage Sを作成しているrootFrame->Navigate(TypeName(DirectXPage::typeid), e->Arguments);

    Iのみへの参照を取ることによって、単一のバージョンを作成し、修正版を持っていますナビゲーション中に作成されたものですが、エラーケースをチェックするのに多くの時間を費やしていません。

    void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ e) 
    { 
    #if _DEBUG 
         if (IsDebuggerPresent()) 
         { 
           DebugSettings->EnableFrameRateCounter = true; 
         } 
    #endif 
    
         if (e->PreviousExecutionState == ApplicationExecutionState::Terminated) 
         { 
           m_directXPage->LoadInternalState(ApplicationData::Current->LocalSettings->Values); 
         } 
    
         auto rootFrame = dynamic_cast<Frame^>(Window::Current->Content); 
    
         // Do not repeat app initialization when the Window already has content, 
         // just ensure that the window is active 
         if (rootFrame == nullptr) 
         { 
           // Create a Frame to act as the navigation context and associate it with 
           // a SuspensionManager key 
           rootFrame = ref new Frame(); 
    
           rootFrame->NavigationFailed += ref new Windows::UI::Xaml::Navigation::NavigationFailedEventHandler(this, &App::OnNavigationFailed); 
    
           // Place the frame in the current Window 
           Window::Current->Content = rootFrame; 
         } 
    
         if (rootFrame->Content == nullptr) 
         { 
           // When the navigation stack isn't restored navigate to the first page, 
           // configuring the new page by passing required information as a navigation 
           // parameter 
           rootFrame->Navigate(TypeName(DirectXPage::typeid), e->Arguments); 
         } 
    
         if (m_directXPage == nullptr) 
         { 
           m_directXPage = dynamic_cast<DirectXPage^>(rootFrame->Content); 
         } 
    
         // Ensure the current window is active 
         Window::Current->Activate(); 
    } 
    
    +0

    こんにちはボブ、はい、これはバグです。私はマイクロソフト社がこれほど長い間スリップを許していることに驚いています。とにかく、私は本当にこの問題の解決策が必要です。あなたのコードは部分的にしか動作しません。 m_directXPageがnullなので、アプリケーションがTerminated状態から起動すると、NullReferenceExceptionがスローされます。一方、m_directXPageを初期化しないと、アプリケーションが終了するとメモリアクセス違反例外が発生します。何か案は? – ata6502

    +0

    ' if(e-> PreviousExecutionState == ApplicationExecutionState :: Terminated) { m_directXPage-> LoadInternalState(ApplicationData :: Current-> LocalSettings-> Values)のチェックを移動してください。 } をメソッドの最後に追加します。 –

    +0

    今はうまくいきます。ありがとう。 – ata6502

    関連する問題