Hi everyone,
Using:
VB.NET 2010 Express
MTV3D65
.NET 3.5
My program has to display some basic meshes (only a few dozen of boxes and spheres) in a picturebox within an MDIchild-form. The scene needs to be redrawn when I change something, like adding a sphere. It always starts ok, but after about a minute it crashes with this nice error:
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.The basic structure of the code of the MDIchild:
Imports MTV3D65
Public Class View3DForm
Private TV As TVEngine
'(...)
Public Sub View3DForm_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
'(Gather some data from the main form etc.)
StartScene()
End Sub
Private Sub SetupScene(ByVal hWnd As IntPtr)
bLoop = True
TV = New TVEngine
Scene = New TVScene
Input = New TVInputEngine
Cam = New TVCamera
Mats = New TVMaterialFactory
Texs = New TVTextureFactory
Maths = New TVMathLibrary
Light = New TVLightEngine
TV.DisplayFPS(False)
TV.Init3DWindowed(Me.pic.Handle.ToInt32, True)
TV.SetAngleSystem(CONST_TV_ANGLE.TV_ANGLE_DEGREE)
Input.Initialize(True, True)
Light.CreatePointLight(New TV_3DVECTOR(300, 300, 300), 1, 1, 1, 1000)
Light.EnableLight(IDLight, True)
Light.SetSpecularLighting(True)
For i = 0 To PlayerCheckListBox.Items.Count - 1 '(A list containing meshes; don't bother the arrays hereunder)
If PlayerCheckListBox.CheckedIndices.Contains(i) Then
Dim PlayerMesh As TVMesh
PlayerMesh = Scene.CreateMeshBuilder("Mesh")
PlayerMesh.CreateSphere(radarr(i), 100, 100)
PlayerMesh.SetScale(weiarr(i, 0), weiarr(i, 1), weiarr(i, 2))
PlayerMesh.SetPosition(posarr(i, 0), posarr(i, 1), posarr(i, 2))
IDTex = Texs.CreateTexture(1, 1, False)
Texs.SetPixel(IDTex, 0, 0, -PlayerForm.Grid.Rows(i).Cells(3).Value)
PlayerMesh.SetMaterial(IDMat)
PlayerMesh.SetTexture(IDTex)
PlayerMesh.SetLightingMode(CONST_TV_LIGHTINGMODE.TV_LIGHTING_OFFSETBUMPMAPPING_TANGENTSPACE)
End If
Next
End Sub
Private Sub Main_Loop()
While bLoop = True
fTime = TV.AccurateTimeElapsed()
TV.Clear()
Scene.RenderAllMeshes()
TV.RenderToScreen()
UpdateScene()
Application.DoEvents()
End While
TV.ReleaseAll()
TV = Nothing
End Sub
Private Sub UpdateScene()
Dim vNew As TV_3DVECTOR = Maths.MoveAroundPoint(New TV_3DVECTOR(0, 0, 0), fx, fy, fz)
Cam.SetCamera(vNew.x, vNew.y, vNew.z, 0, 0, 0)
'(Camera movement)
End Sub
Private Sub StartScene()
pic.Focus() '(pic contains the TV3D image)
PlayerCheckListBox.ClearSelected()
Try
TV.ReleaseAll()
TV = Nothing
Catch
End Try
bLoop = False
Try
TV.ReleaseAll()
TV = Nothing
Catch
End Try
SetupScene(Me.Handle)
Main_Loop()
End Sub
Private Sub PlayerCheckListBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PlayerCheckListBox.SelectedIndexChanged
StartScene()
'(So when I check an item in the listbox, the corresponding mesh is added)
End Sub
End Class
Thanks in advance.