2016-03-05 38 views
0

我試過以下幾個教程似乎有麻煩。Directx設備不初始化爲窗口,程序掛起

我有一個現有的程序,我試圖添加一個directx窗口作爲一個額外的彈出式論壇,將作爲一個孩子運行到主應用程序的形式。

下面是Windows窗體類:

public partial class DxWindow : Form 
{ 

    Device device; 

    public DxWindow() 
    { 

     InitializeComponent(); 
     initDevice(); 
    } 

    private void initDevice() 
    { 
     MessageBox.Show("hello"); 

     PresentParameters pp = new PresentParameters(); 
     pp.Windowed = true; 
     pp.SwapEffect = SwapEffect.Discard; 

     device = new Device(0, DeviceType.Hardware, this, CreateFlags.HardwareVertexProcessing, pp); 
    } 

    private void Render() 
    { 
     //render stuff 
    } 

    private void DxWindow_Paint(object sender, PaintEventArgs e) 
    { 
     Render(); 
    } 
} 

這裏是我初始化形式(從主窗口中的UI按鈕)

private void toolStripButton3_Click_1(object sender, EventArgs e) 
{ 
    if (DirectxWindow == null) 
    { 
     DirectxWindow = new DxWindow(); 
     DirectxWindow.Show(); 
    } 
} 

當我運行該程序,然後點擊按鈕。它似乎創造了記憶中的形式,但從來沒有出現。當我在調試器中遍歷它時,它會轉到「DirectxWindow = new DxWindow();」然後自動跳出中斷模式並繼續在主窗口凍結並且沒有新的Dxwindow()的情況下運行。

當我打破執行似乎仍然是「DirectxWindow = new DxWindow();」

此外,「MessageBox.Show(」hello「);」在DxWindow構造函數沒有被調用」

編輯:我推斷,只要它擊中‘PresentParameters PP =新Microsoft.DirectX.Direct3D.PresentParameters();’應用程序,而不引發任何錯誤,不響應

回答

0

原來我的問題是需要在 「App.config中」 文件使用

<startup useLegacyV2RuntimeActivationPolicy="true"> 

解決方案在這裏找到:Mixed mode assembly is built against version 'v1.1.4322'

雖然我從來沒有得到OP所述的錯誤。我只是有這個問題,如評論中所述: 「謝謝!!!!這是我遇到過的最奇怪的問題在VS 2012 .Net 4.0中,我的應用程序只會暫停我初始化任何類型的變量與這個DLL相關的,我從來沒有見過這樣的東西,直到我找到這個,才發現有關這個問題的任何信息!「 - Quinxy von Besiex