hog Posted January 12, 2004 Posted January 12, 2004 ...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? Quote My website
*Experts* Bucky Posted January 12, 2004 *Experts* Posted January 12, 2004 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. Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
hog Posted January 13, 2004 Author Posted January 13, 2004 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?? Quote My website
Administrators PlausiblyDamp Posted January 13, 2004 Administrators Posted January 13, 2004 Could you post the code in question? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
hog Posted January 14, 2004 Author Posted January 14, 2004 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?? Quote My website
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.