Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

...object created with New

 

...program runs

 

...users changes settings

 

...object is disposed and set to nothing

 

...object is created with New again

 

...program errors later down the line object not set?

 

Question:

 

So if I dispose an object to clean up the create it again using the New keyword will this fail as I disposed the object?

My website
  • *Experts*
Posted

No, because you are creating a new instance of the object and

then setting it to the variable. You are not modifying the current

object in the variable; you are merely replacing it with another

object.

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted

This is as I suspected, but consider this..

 

I have a render loop, when the loop ends I dispose the object. Then when the render loop needs to start again I create a new object which does not error. But when I try to load the mesh file I get an error saying the object is not set?

 

If I remover the dispose code I don't get an eror and all works OK??

My website
Posted

Sure:)

 

this is the rendering part:

 

' stay in render loop until flag turns false

Do While m_blnRenderScene

  ' call render code

   Render()

  ' allow application time to do its stuff

   Application.DoEvents()

Loop

' dump current 3D object

If Not m_obj3DDevice Is Nothing Then

  m_obj3DDevice.Dispose()
  m_obj3DDevice = Nothing

End If

 

Once the code above has run prior to the render loop running again this code runs and returns true?

 

Public Function Init3D(ByVal D3DDeviceType As DeviceType) As Boolean

       ' attempt to setup a 3D device

       ' save the adapter number

       Dim intAdapter As Integer = Manager.Adapters.Default.Adapter

       ' get the current display format

       Dim dspDispMode As DisplayMode = Manager.Adapters(intAdapter).CurrentDisplayMode

       ' create a new presentation parameter object

       m_objPresentationParameters = New PresentParameters

       ' setup the presentation parameters

       m_objPresentationParameters.Windowed = True
       m_objPresentationParameters.SwapEffect = SwapEffect.Discard
       m_objPresentationParameters.BackBufferFormat = dspDispMode.Format
       m_objPresentationParameters.AutoDepthStencilFormat = DepthFormat.D16
       m_objPresentationParameters.EnableAutoDepthStencil = True

       ' try to create a 3D device

       Try

           m_obj3DDevice = New Device(Me.cboAdapter.SelectedIndex, D3DDeviceType, Me.picViewPort.Handle, CreateFlags.SoftwareVertexProcessing, m_objPresentationParameters)

           ' success

           Return True

       Catch objException As Exception

           ' failure

           Return False

       Finally

           ' tidy up

           dspDispMode = Nothing

           m_objPresentationParameters = Nothing

       End Try

End Function

 

The error occurs when I try to then load in the mesh file selected by user:

 

m_mshMesh = Mesh.FromFile(m_strMeshFile, MeshFlags.SystemMemory, m_obj3DDevice, extMaterials)

 

The error says object not set to an instance of...

 

If I remove the dispose bit of code above everything works fine. I can't understand why this should be happening??

My website

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...