Results 1 to 9 of 9

Thread: [DirectX 8] Error

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2007
    Posts
    84

    [DirectX 8] Error

    My error: Something about variable block set.
    My error line: the line that has " 'error " on it.
    My Code:
    vb Code:
    1. Dim Dx As DirectX8
    2. Dim D3d As Direct3D8
    3. Dim D As D3DX8
    4. Dim D3DDevice As Direct3DDevice8
    5. Dim MainFont As D3DXFont
    6. Dim MainFontDesc As IFont
    7. Dim TextRect As RECT
    8. Dim fnt As New StdFont
    9. Dim TextToDraw As String
    10.  
    11. Public Sub DrawText(Text As String, X As Long, Y As Long)
    12.     fnt.Name = "Verdana"
    13.     fnt.Size = 18
    14.     fnt.Bold = True
    15.     Set MainFontDesc = fnt
    16.     'Error Set MainFont = D.CreateFont(D3DDevice, MainFontDesc.hFont)
    17.     TextRect.Top = 1
    18.     TextRect.Left = 1
    19.     TextRect.Bottom = Y
    20.     TextRect.Right = X
    21.     D3DDevice.BeginScene
    22.     D.DrawText MainFont, &HFFCCCCFF, Text, TextRect, DT_TOP Or DT_CENTER
    23.     D3DDevice.EndScene
    24.     D3DDevice.Present ByVal 0, ByVal 0, 0, ByVal 0
    25. End Sub
    26.  
    27. Public Sub Init()
    28.     Dim DispMode As D3DDISPLAYMODE
    29.     Dim D3DWindow As D3DPRESENT_PARAMETERS
    30.     Set Dx = New DirectX8
    31.     Set D3d = Dx.Direct3DCreate()
    32.     D3d.GetAdapterDisplayMode D3DADAPTER_DEFAULT, DispMode
    33.     D3DWindow.Windowed = 1
    34.     D3DWindow.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC
    35.     D3DWindow.BackBufferFormat = DispMode.Format
    36.     Set D3DDevice = D3d.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, Client.hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, D3DWindow)
    37. End Sub

  2. #2
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: [DirectX 8] Error

    People here actually understand error statements. Don't give us what the error was about, but rather what the error actually was.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2007
    Posts
    84

    Re: [DirectX 8] Error

    object variable or with block not set on line Set MainFont = D.CreateFont(D3DDevice, MainFontDesc.hFont)

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: [DirectX 8] Error

    Like many common errors, this one is described in the article What does this error mean, and how do I fix it? from our Classic VB FAQs (in the FAQ forum, which is shown near the top of our home page)

    The problem is that you are trying to use an object that you haven't set up yet.. and on that line you have a few objects: MainFont, D, D3DDevice, and MainFontDesc
    • MainFont is not the issue, as that is the one you are trying to Set.
    • MainFontDesc is not an issue either, as that has been Set on the previous line.
    • Assuming that the Init() routine has run, D3DDevice also will have been Set already.

    That leaves us with D, and I can't see any code which sets it - so that is almost certainly the cause. I haven't used DirectX enough to know how it should be set up, but hopefully you will be able to find out from whatever source(s) you have built the other code from (or via a search of this forum).

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2007
    Posts
    84

    Re: [DirectX 8] Error

    I think I found the problem, this line:
    "vb Code:
    1. Dim D as D3DX
    2. 'Needs to be
    3. Dim D as New D3DX

  6. #6
    Fanatic Member
    Join Date
    Aug 2003
    Posts
    601

    Re: [DirectX 8] Error

    Shouldn't Set MainFont = D.CreateFont(D3DDevice, MainFontDesc.hFont) only be called once?

  7. #7

    Thread Starter
    Lively Member
    Join Date
    May 2007
    Posts
    84

    Re: [DirectX 8] Error

    First time I use it it crashes.

  8. #8
    New Member
    Join Date
    May 2008
    Posts
    13

    Re: [DirectX 8] Error

    Quote Originally Posted by psychotomus
    Shouldn't Set MainFont = D.CreateFont(D3DDevice, MainFontDesc.hFont) only be called once?
    YES!

  9. #9
    New Member
    Join Date
    May 2008
    Posts
    13

    Re: [DirectX 8] Error

    VB Code:
    1. Dim Dx As DirectX8
    2. Dim D As D3DX8

    Must be:

    VB Code:
    1. Dim Dx As New DirectX8
    2. Dim D As New D3DX8

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width