DirectX VB.NET - Simple initialisation - Exception
Bonjour à tous !
Je suis débutant dans les appli DirectX / VB.NET et j'ai un probleme sur un programme bateau qui affiche un écran vide (et bleu).
L'écran bleu se crée correctement mais quand j'appui sur Echap j'obtiens une exception sur la ligne device.Present() :cry:
Citation:
A first chance exception of type 'Microsoft.DirectX.Direct3D.DeviceLostException' occurred in Microsoft.DirectX.Direct3D.dll
Voici la source de la seule classe du programme : (en rouge la ligne qui plante)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| Imports Microsoft.DirectX
Imports Microsoft.DirectX.Direct3D
Imports Microsoft.DirectX.Direct3D.D3DX
Class GameClass
Private displaySettings As DisplayMode
Private deviceParameters As PresentParameters
Public device As Device
Public gameExit As Boolean
Public Sub Initialize(ByVal fullScreen As Boolean)
If fullScreen Then
displaySettings.Width = 800
displaySettings.Height = 600
displaySettings.Format = Format.X8R8G8B8
Else
displaySettings = Manager.Adapters.Default.CurrentDisplayMode
End If
deviceParameters = New PresentParameters()
deviceParameters.BackBufferWidth = displaySettings.Width
deviceParameters.BackBufferHeight = displaySettings.Height
deviceParameters.BackBufferFormat = displaySettings.Format
deviceParameters.SwapEffect = SwapEffect.Discard
deviceParameters.PresentationInterval = PresentInterval.Immediate
If fullScreen Then
deviceParameters.Windowed = False
Else
deviceParameters.Windowed = True
End If
loadContent()
End Sub
Public Sub loadContent()
device = New Device(Manager.Adapters.Default.Adapter, DeviceType.Hardware, Form1.Handle, CreateFlags.SoftwareVertexProcessing, deviceParameters)
End Sub
Public Sub Draw()
Do While Not gameExit
device.Clear(ClearFlags.Target, Color.CornFlowerBlue, 1, 0)
device.BeginScene()
device.EndScene()
device.Present() 'C'est ici que ca plante
Application.DoEvents()
Loop
thisExit()
End Sub
Public Sub thisExit()
displaySettings = Nothing
deviceParameters = Nothing
device.Dispose()
device = Nothing
Application.Exit()
End Sub
End Class |
Voici la source de la seule form : (en rouge la ligne qui plante)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| Public Class Form1
Dim game As New GameClass
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Escape Then 'Close the window when the user presses escape
Me.Close() 'yes, close, not dispose.
End If
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.Show()
game.Initialize(True)
game.Draw() 'On est ici quand ca plante
End Sub
End Class |
Auriez vous une idée de la raison de cette erreur ? 8O
Merci beaucoup pour votre aide ! :D