Black Screen

Blitz3D Forums/Blitz3D Programming/Black Screen

Omnicode(Posted 2015) [#1]
Hello,
Recently I've taken another crack at replicating a voxel engine with Blitz. I've done a few versions dealing with the concept but they seem to always meet some sort of snag. This project being no different.



Right now there's some sort of issue where after a bunch of patches have been rendered and or deleted/freed from memory the screen goes black, though the program continues to run. It evades debug mode and randomly creates a MAV about 50% of the time whenever the black screen occurs.

The Error Line points to 'Addmesh V\Mesh,EC\Mesh'



Is this an indication of memory leak or i've run out of VIDMEM?

I'm aware there's a cap for triangles within one given surface at around 65k. I've capped the generation to ONLY allow a maximum of 49999 tris per patch. I'd planned to incorporate some tri combining, but since i've hit this snag.

Unless there's some quirk about the amount of surfaces that can be rendered at one given time.


Stevie G(Posted 2015) [#2]
If I remember, the cap is on vertices rather than triangles. To be safe I would keep this at around 32k vertices, although I think it's dpendant on the card.

You could display the AvailVidMem and TotalVidMem to check if this is also an issue..


RemiD(Posted 2015) [#3]
Yes, to be safe, no more than around 32000 vertices/triangles per surface, i have seen the same problem on some computers, it seems to be due to the graphic card capabilities.


Rroff(Posted 2015) [#4]
Yeah the number of vertices in a single surface can be limited by GPU support but any GPU in the last like 20 years should support 64K - however there are other limitations to the complexity of single surfaces (including normals and something else I can't remember) that mean you generally hit the limit at just over 32768 so capping to 32000 is usually best.

I'd usually use a grid of multiple single surface systems (not too many) as it makes it trivial to cull the longer distance ones in one go if your using distance based LOD systems for performance (more relevant if your using progressive LOD however rather than fog based fading out to a hard max Z range beyond which everything is culled).


Omnicode(Posted 2015) [#5]
~Update~
The cap is indeed on vertices. Though my program accounts for faces that are redundant via the code I put above, it doesn't check to see if vertices are redundant. I'll have to run some pass to perhaps combine 'shared' verts, luckily I wouldn't need to parse per voxel rather, the resultant mesh.

At the moment the problem is being sloppily tackled by asserting 'trisrendered' as a main indicator of the impending black screen effect.

I attempted a CSG routine of my own, checking per resultant mesh for same y, thru x and z. Replacing what was found with a large voxel accounting for the 'sameness'. I couldn't get it to not overlap. The ScaleMesh command isn't my friend on that Nor Fitmesh.

I've added the ability to fully manipulate individual voxels on the fly.

The world is cache'd and referenced on reload for faster main initialization.

http://youtu.be/2mG4_psrxws


Stevie G(Posted 2015) [#6]

I'll have to run some pass to perhaps combine 'shared' verts, luckily I wouldn't need to parse per voxel rather, the resultant mesh.



A welding routine might help. The following recreates the mesh, removing shared vertices. It assumes the mesh has only 1 surface but can be easily adapted.

Function MESHweld( mesh )

	Local copy, cs, s, t, v0, v1, v2
	Local nv0, nv1, nv2

	copy = CopyMesh( mesh )
	cs = GetSurface( copy, 1 )
	
	s = GetSurface( mesh, 1 )
	ClearSurface s
		
	For t = 0 To CountTriangles(cs) - 1
		v0 = TriangleVertex( cs, t, 0 )
		v1 = TriangleVertex( cs, t, 1 )
		v2 = TriangleVertex( cs, t, 2 )
		nv0 = MESHfindvertex( s, VertexX( cs, v0 ) , VertexY( cs, v0 ) , VertexZ( cs, v0 ) )
		If nv0 = -1 nv0 = AddVertex( s, VertexX( cs, v0 ) , VertexY( cs, v0 ) , VertexZ( cs, v0 ) )
		nv1 = MESHfindvertex( s, VertexX( cs, v1 ) , VertexY( cs, v1 ) , VertexZ( cs, v1 ) )
		If nv1 = -1 nv1 = AddVertex( s, VertexX( cs, v1 ) , VertexY( cs, v1 ) , VertexZ( cs, v1 ) )
		nv2 = MESHfindvertex( s, VertexX( cs, v2 ) , VertexY( cs, v2 ) , VertexZ( cs, v2 ) )
		If nv2 = -1 nv2 = AddVertex( s, VertexX( cs, v2 ) , VertexY( cs, v2 ) , VertexZ( cs, v2 ) )
		AddTriangle s, nv0, nv1, nv2
	Next	
	
	FreeEntity copy
	
End Function

;================================================================================

Function MESHfindvertex( s , x#, y#, z# )

	Local v

	For v = 0 To CountVertices(s) - 1
	
		If VertexX( s, v ) = x 
			If VertexY( s, v ) = y 
				If VertexZ( s, v ) = z
					Return v
				EndIf
			EndIf
		EndIf
		
	Next
	
	Return -1
	
End Function



Omnicode(Posted 2015) [#7]
Thank you, ive modded the above code to only combine verts that are of the same location and have the same color. This was very useful, brought the idea of smooth lighting back into the project a bit. I'm still tweaking it though.




bytecode77(Posted 2015) [#8]
Cool, now add dungeons to it :)