2017-09-19 1 views
0

을 증가시키지 않고, 문제를 재현하는 값을 생성, 나는 다음 단계로 좁혀 :StepTimer.GetTotalSeconds()는 항상 내가 단순화하기 위해 다이렉트 X 11을 사용하고

  1. "새 만들기 DirectX 및 XAML 응용 프로그램 (UWP) "Visual Studio (VS 2017 사용하고 있습니다).
  2. 다음 코드로 Sample3DSceneRenderer :: 업데이트 방법 교체 :

    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 생성자가 두 번 호출 된 것으로 밝혀졌다 : 한 번 프레임 워크 (ActivateInstance 방법)에 의해 응용 프로그램 자체 (통화 m_directXPage = 심판 새로운 DirectXPage에 의해 다른 시간 ()을 App.xaml.cpp에 추가합니다. 질문은 여전히 ​​남아 있습니다. XAML 페이지가 두 번 인스턴스화되는 이유는 무엇입니까? 그게 버그 야? – ata6502

    +0

    설명 : 페이지가 두 번 인스턴스화 되었기 때문에 Update 메서드가 두 번 호출되므로 두 개의 타이머가 동시에 작동합니다. 내게 버그 같아 보이지? – ata6502

    답변

    0

    버그는 App :: OnLaunched에 있습니다.

    • 직접 할당 : m_directXPage = ref new DirectXPage();
    • 탐색 : 템플릿의 버전은 두 DirectXPage의를 만드는 rootFrame->Navigate(TypeName(DirectXPage::typeid), e->Arguments);

    나는 단지에 대한 참조를 복용하여 단일 버전을 생성하는 수정 된 버전이 하나는 탐색 중에 생성되었지만 오류 사례를 확인하는 데 많은 시간을 할애하지 않았습니다.

    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

    안녕하세요 Bob, 예, 이것은 버그입니다. 나는 마이크로 소프트가 오랫동안 미끄러지도록 허용 한 것에 놀랐다. 어쨌든이 문제에 대한 해결책이 필요합니다. 코드는 부분적으로 만 작동합니다. m_directXPage가 null이므로 응용 프로그램이 Terminated 상태에서 시작되면 NullReferenceException이 발생합니다. 반면 m_directXPage를 초기화하지 않으면 응용 프로그램을 닫을 때 메모리 액세스 위반 예외가 발생합니다. 어떤 아이디어? – ata6502

    +0

    대한 검사를 이동보십시오 ' 경우 (전자> :: PreviousExecutionState == ApplicationExecutionState 종료) { m_directXPage-> LoadInternalState (ApplicationData :: 전류 -> LocalSettings-> 값); } ' 아래쪽에 있습니다. –

    +0

    이제 제대로 작동합니다. 감사. – ata6502

    관련 문제