Memory corruption warning

Blitz3D Forums/Blitz3D Programming/Memory corruption warning

Warren(Posted 2004) [#1]
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.


John Pickford(Posted 2004) [#2]
Why do you need the clearsurface command at all?


Warren(Posted 2004) [#3]
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...


John Pickford(Posted 2004) [#4]
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.


Warren(Posted 2004) [#5]
No, no error in debug. It just corrupts silently.


John Pickford(Posted 2004) [#6]
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.


Michael Reitzenstein(Posted 2004) [#7]
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



Rob(Posted 2004) [#8]
Fail on a non entity? slow? good posting lads.


Warren(Posted 2004) [#9]
Think you missed the joke there, Rob.