InvalidCallExceptionUnhandled
This is in visual basic 2008. I'm unfamiliar with this error and the only clue its giving me is this line of code:
device.StretchRectangle(image, source_rect, backbuffer, dest_rect, 0)
Here is the whole code:
Imports Microsoft.DirectX
Imports Microsoft.DirectX.Direct3D
Public Class Form1
REM define some useful constants
Const SCREENW As Integer = 800
Const SCREENH As Integer = 600
Dim BLACK As Integer = RGB(0, 0, 0)
REM Direct3D device variable
Dim device As Direct3D.Device
REM create image from a Direct3D surface
Dim image As Direct3D.Surface
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles Me.Load
REM resize the form
Me.Size = New Size(SCREENW, SCREENH)
Me.Text = "Bitmap Loading Demo"
Me.Setstyle(Controlstyles.AllPaintingInWmPaint Or _
Controlstyles.Opaque, True)
REM get the desktop display mode
Dim adapterNumber As Integer = Manager.Adapters.Default.Adapter
Dim mode As DisplayMode
mode = Manager.Adapters.Default.CurrentDisplayMode
REM set up the presentation parameters
Dim params As New PresentParameters
params.Windowed = True
params.SwapEffect = SwapEffect.Copy
params.AutoDepthStencilFormat = DepthFormat.D16
params.EnableAutoDepthStencil = True
params.MultiSample = MultiSampleType.None
params.BackBufferCount = 1
params.BackBufferWidth = SCREENW
params.BackBufferWidth = SCREENH
REM check video card capabilities
Dim flags As CreateFlags
flags = CreateFlags.HardwareVertexProcessing
flags += CreateFlags.PureDevice
REM Create the Direct3D device
device = New Device(adapterNumber, DeviceType.Hardware, _
Me, flags, params)
REM load the bitmap file
image = device.CreateOffscreenPlainSurface(SCREENW, SCREENH, _
Format.A8R8G8B8, Pool.Default)
SurfaceLoader.FromFile(image, "sky.bmp", Filter.None, BLACK)
End Sub
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
REM begin rendering
device.BeginScene()
REM clear the back buffer
device.Clear(ClearFlags.Target + ClearFlags.ZBuffer, Color.Green, 1.0, 0)
REM specify the drawing rectangles for the image
Dim source_rect As New System.Drawing.Rectangle(0, 0, SCREENW, SCREENH)
Dim dest_rect As New System.Drawing.Rectangle(0, 0, SCREENH, SCREENW)
REM get reference to the back buffer
Dim backbuffer As Direct3D.Surface
backbuffer = device.GetBackBuffer(0, 0, BackBufferType.Mono)
REM draw the image
device.StretchRectangle(image, source_rect, backbuffer, dest_rect, 0)
REM stop rendering
device.EndScene()
REM copy back buffer to the screen
device.Present()
End Sub
Private Sub Form1_KeyDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
REM check key code for ESC key
If e.KeyCode = Keys.Escape Then
REM destroy the Direct3D device
device.Dispose()
REM destroy the image
image.Dispose()
REM end the program
End
End If
End Sub
End Class
Thanks!
The exceptions or errors generated by Direct3D are cryptic at best. However, if you enable the debug runtimes it should give you much more information about what's going wrong. See the Debugging Tips in the SlimDX documentation for more help on configuring the runtimes and accessing the debugging information (it doesn't matter if you're using MDX or SlimDX, it's Direct3D itself that generates the messages).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement