Memory corruption warning

Blitz3D Forums/Blitz3D Programming/Memory corruption warning

Just a heads up to my fellow Blitzers. Clearing a surface after freeing the mesh it belongs to silently corrupts memory until your app dies in some random fashion.

I just spent 2 days trying to figure out why my new rendering code was dying in random places and for seemingly no good reason.

The problem was that I had...

FreeEntity( MyMesh )
ClearSurface( MySurf )

...and what I needed to have was...

ClearSurface( MySurf )
FreeEntity( MyMesh )

Seems obvious, but Blitz gives -no- kind of runtime error or warning about doing this. Memory is silently corrupted behind the scenes and the app will eventually die.

So be aware.

Why do you need the clearsurface command at all?

I dunno. The documentation isn't clear about how to get rid of surfaces. I guess they magically disappear when you free the mesh they belong to.

However, the warning still stands. Silent memory corruption sucks...

I agree. Does this generate an error in debug mode?

Surfaces are definitely cleared by freeentity. Clearsurface is only there to delete a particular surface within a mesh; usually prior to rebuilding.

No, no error in debug. It just corrupts silently.

I just did a quick test and you are right.

Clearsurface() has no error checking at all. You can give it any value you like.

Freeentity() will report an error in debug mode.

I sense the possibility for an EntityExists( ) command!

Function EntityExists( Entity )
	
	For Count = 1 To 10000
		
		Surf = GetSurface( Entity, 0 )
		ClearSurface Surf
		
	Next
	
	;If it gets to here, the entity exists!	
	Return True
	
End Function


Fail on a non entity? slow? good posting lads.

Think you missed the joke there, Rob.