I see .. the error could occur, because GetSurface() should be in the range 1..CountSurfaces().
If your model contains a hierarcy, you'll need to search through the structure to find meshes that contain surfaces. If that is the problem, look at the printoutchildren() function below.
As for the Z-order problem, I'm not sure what to do about it. You could however, solve it in a different way. You can't delete specific triangles on a surface, however, you can clear all triangles using clearsurface. If you kept a copy of it, you can rebuild it, leaving out the triangles you don't want:
Graphics3D 800, 600, 0, 2
SetBuffer BackBuffer()
;create camera
camera = CreateCamera()
MoveEntity camera, 0, 0, -15
CameraClsColor camera, 0, 255, 0
;create cube
cube = CreateCube()
;get first surface
surf = GetSurface(cube, 1)
;copy cube
cube2 = CopyMesh(cube)
HideEntity cube2
;get other surface
surf2 = GetSurface(cube2, 1)
;clear surface triangles
ClearSurface surf, 0, 1
;rebuild surface, using copy of it
For i = 0 To CountTriangles(surf2) - 1
;add all triangles, except triangle no 5
If i <> 5 Then
;get 3 vertices of triangle
v0 = TriangleVertex(surf2, i, 0)
v1 = TriangleVertex(surf2, i, 1)
v2 = TriangleVertex(surf2, i, 2)
AddTriangle surf, v0, v1, v2
End If
Next
;main loop
Repeat
TurnEntity cube, 0, 1, 0
RenderWorld()
Flip
Until KeyHit(1)
Cls
Locate 0, 0
PrintOutChildren cube
FlushKeys()
WaitKey()
End
Function PrintOutChildren(mesh, lvl = 0)
Print String$(" ", lvl) + "mesh " + mesh + " has " + CountSurfaces(mesh) + " surfs"
Print String$(" ", lvl) + "children:"
If CountChildren(mesh) = 0 Then
Print String$(" ", (lvl + 1)) + "none"
End If
For i = 1 To CountChildren(mesh)
PrintOutChildren(GetChild(mesh, i), lvl + 1)
Next
End Function