Cant get it workin

Loffen

Regular
Joined
Mar 21, 2004
Messages
51
Location
Akershus, Norway
Cant get it workin (Crashes without errors)

My (VB.Net 2003) program crashes EVERYTIME i try to run it. I rewrote it a couple of times, I have read all posts from last page to page 5 (well, almost. I did exclude those not saying anything about errors). I ran some of the demos (theyre workin), I almost copyed and pasted the demo code (still no result). I am using dbmon.exe (dont understand what it want, so i attached a picture). Plus, I cant figure where the error(s) occurs, The window: opens, swaps to fullscreen (without changin color to Color.Navy), then crashes (withour errors).

Form1 code:
Code:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Show()

        Engine = New Engine

        Engine.FBackBufferWidth = 1280
        Engine.FBackBufferHeight = 1024
        Engine.FBackBufferFormat = Format.R5G6B5
        Engine.FBackBufferCount = 1
        Engine.FPresentInterval = PresentInterval.Immediate
        Engine.FSwapEffect = SwapEffect.Copy
        Engine.FCreateFlags = CreateFlags.SoftwareVertexProcessing
        Engine.FDeviceType = DeviceType.Hardware

        If Engine.InitDevice(Me) Then
            FRunning = True
        End If

        While FRunning = True
            Application.DoEvents()

            Engine.Render()

            Application.DoEvents()
        End While

        End

    End Sub

The engine:

Code:
Public Class Engine
    Public FBackBufferWidth As Integer
    Public FBackBufferHeight As Integer
    Public FBackBufferFormat As Format
    Public FBackBufferCount As Integer

    Public FPresentInterval As PresentInterval
    Public FSwapEffect As SwapEffect

    Public FCreateFlags As CreateFlags
    Public FDeviceType As DeviceType

    Private FRoot As Manager
    Private FDevice As Device
    Private FPP As PresentParameters
    Private DeviceLost As Boolean

    Public Function InitDevice(ByVal FTarget As System.Windows.Forms.Form)
        FPP = New PresentParameters

        FPP.BackBufferWidth = FBackBufferWidth
        FPP.BackBufferHeight = FBackBufferHeight
        FPP.BackBufferFormat = FBackBufferFormat
        FPP.BackBufferCount = FBackBufferCount
        FPP.Windowed = False

        FPP.PresentationInterval = FPresentInterval
        FPP.SwapEffect = FSwapEffect

        FDevice = New Device(0, FDeviceType, FTarget, FCreateFlags, FPP)

        DeviceLost = False
    End Function

    Public Function Render()
        FDevice.Clear(ClearFlags.Target, Color.Navy, 1.0F, 0)
        FDevice.BeginScene()

        FDevice.EndScene()
        FDevice.Present()
    End Function

End Class
 

Attachments

Last edited:
I can't test this right now, but try not to clear the ZBuffer since you are not using one. Change the third argument in the device.Clear() call to 0.0F.
 
I have tried all possible values everywhere, including that one. These values are just those i used when posting the code. I will try to call clear() like this when i come home:

Code:
FDevice.clear(ClearFlags.Target, Color.Navy, nothing, 0)

But in the examples (and demos) i've seen they use both 1.0F and 0.0F. Yup, 2D examples :P

BTW: I want to try to make some titlebased game, dunno what settigs are optimized for that.. suggestions??

EDIT: both using 0.0f and nothing gave no results :confused:

--Loffen
 
Last edited:
hmmm my vb.net is a bit rusty (not that it was that hot to begin with) since i started working in c# - so i may have the complete wrong end of the stick..but one thing pops into my head...

Inside your function Engine.InitDevice()...where are you setting the return value of the function to true?

seems its just falling through your while/render() loop and not rendering since FRunning is always false...

ED - curiosity got the of me so i kicked up vb and tried it - yes it will hapilly let you run if/while loops on a function with no return at all...

so youll need to tag a Boolean return onto InitDevice() - look for exceptions from device creation...return false if you get one...true if not..

at least so it seems hehe not exactly brimming with confidence on my programming skills :P
 
Last edited:
Next thing... :p (read all posts about 'Device Lost'): When i hit 'Alt + Tab' i change focus to VS.Net. This crashed DX. I fixed this part, it doesnt crash when loosing focus, but when it gets focus back...
Code:
    Public Function Render()
        If FDeviceLost Then
            If FTarget.Focus Then
                Try
                    FDevice.TestCooperativeLevel()
                    FDevice.Reset(FPP)
                    FDeviceLost = False
                Catch
                    Return False
                End Try
            End If
        End If

        Try
            FDevice.TestCooperativeLevel()
            FDevice.Clear(ClearFlags.Target, Color.Navy, Nothing, 0)
            FDevice.BeginScene()

            FDevice.EndScene()
            FDevice.Present()
        Catch Exception As DeviceLostException
            FDeviceLost = True
        End Try
    End Function

EDIT: New dbmon pic + added FDevice.TestCoopLevel in if FTarget.Focus Then

EDIT2: It seems like it cant restore the device? And the weird thing it crashes on the Application.DoEvents() line??

Suggestions?? dbmon.exe output this:
 

Attachments

Last edited:
ooook....

well to be honest ive never looked at recovering from a lost device before...its something my current project needs but Ive kept putting it off lol...anyways I had a go at it and lo and behold...got it working...

I did the same as you and searched through all posts on the topic (not early enough hehe) and found what was needed in one of drunkenhyena's tuts

My guess as to the problem in your code is that while your catching the DeviceLost exception...your not catching the DeviceNotReset exception (ie the device was lost...has come back and is ready to be reset)

Have a look at this code (my rendering routine as modded after reading DrunkenHyena's tut) - its c# but you should get the gist and be able to adapt to vb.

Code:
			int CheckResult;

			if (d3ddevice == null) // if no device...why are we here?
				return;
		
			if (d3ddevice.CheckCooperativeLevel(out CheckResult)) // is the device feeling cooperative?...
			{
				try
				{
					d3ddevice.Clear(ClearFlags.Target, System.Drawing.Color.Black, 1.0f, 0);// black base screen
		
					d3ddevice.RenderState.SourceBlend = Blend.SourceAlpha;
					d3ddevice.RenderState.DestinationBlend = Blend.InvSourceAlpha;

					d3ddevice.RenderState.AlphaBlendEnable= true;
			
					d3ddevice.BeginScene();
			
					d3dsprite.Begin(SpriteFlags.DoNotModifyRenderState);
			
					if (d3ddevice.CheckCooperativeLevel()) // no changes to gamestate if device is messing around
					{
						Game.Render();
					}

					d3dsprite.End();

					d3ddevice.EndScene();
				
					d3ddevice.Present();
				
				}
				catch (Microsoft.DirectX.Direct3D.DeviceLostException) // catch the DeviceLost exception - decide what to do later
				{
					d3ddevice.CheckCooperativeLevel(out CheckResult);
				}
				catch (Microsoft.DirectX.Direct3D.DeviceNotResetException)// catch the DeviceNotReset exception - decide what to do later
				{
					d3ddevice.CheckCooperativeLevel(out CheckResult);
				}
			}
			if (CheckResult == (int)Microsoft.DirectX.Direct3D.ResultCode.DeviceLost)
			{
				//wait a bit :) - device was lost...still is....
			}
			if (CheckResult == (int)Microsoft.DirectX.Direct3D.ResultCode.DeviceNotReset)
			{
				d3ddevice.Reset(presentParams); // haha! our device has returned to the fold!...reset it and back to business
			}

Hope that helps a bit :)
 
Hmm....

I believe i 'translated' it correctly. I can still 'loose my device', but when i get focus back, my cpu works very hard for about 5 sec, Then same ol error....

My new render function:
Code:
    Public Function RenderLoop()
        Dim FDeviceCoopState As Integer

'tried both this:
        FDevice.CheckCooperativeLevel(FDeviceCoopState)

        If FDeviceCoopState = ResultCode.Success Then

'and this
        If FDevice.CheckCooperativeLevel(FDeviceCoopState) Then


            Try
                FDevice.TestCooperativeLevel()

                FDevice.Clear(ClearFlags.Target, Color.Navy, Nothing, 0)
                FDevice.BeginScene()

                FRender()

                FDevice.EndScene()
                FDevice.Present()
            Catch ex As DeviceLostException
                FDevice.CheckCooperativeLevel(FDeviceCoopState)
            Catch ex2 As DeviceNotResetException
                FDevice.CheckCooperativeLevel(FDeviceCoopState)
            End Try
        ElseIf FDeviceCoopState = ResultCode.DeviceLost Then
            'do nothing
        ElseIf FDeviceCoopState = ResultCode.DeviceNotReset Then
            FDevice.Reset(FPP)
        End If

        Return True
    End Function
 
Back
Top