Debugging Fun!

Blitz3D Forums/Blitz3D Programming/Debugging Fun!

If you understand the sarcasm in my post you know that debugging is anything but fun. Worse is when you have an error that occours very infrequently, appears seemingly at random and does not appear to be triggered by any specific piece of code. I'm stuck with one of those right now.

After a few hours looking at it I figure it can't hurt to have someone else maybe give some insight.

Here it is:
In my game several of my enemies use the same model (more are made through CopyEntity() ) the only difference being the brush they use and their size. Whats happening is that the models appear to be switching between brushes seemingly at random and only for a second at most.

Notes:
Aside from the original PaintEntity during setup I don't Paint any of them in my main code loop. So it would *seemingingly* be impossible for them to spontaneously change color (brushes) back and forth.

While I can't verify this, (it takes me a few minutes of testing before I can recreate the error) the error does appear to occour during camera angle shifts. Note that the color change is a complete change from one to the other, there is no stretched lines that might occour if one had several, different colored entities all occupying the same space as a result of the z-buffer.

So, does anyone have any idea what might cause this spontaneous shift in brush color? I'll post some code snippets (I'm sure you don't want to look through the entire 3000+ lines). Bear in mind these are relevant snippets of the actual code that involve the use of meshes and brushes.

ENEMY CREATION CODE:
Palette\Glagar = CreateEnemy()
 Palette\Glagar\HandleNum = LoadAnimMesh("media/Visuals/Enemies/Glagars/Glagar.b3d")
 File$ = "media/Visuals/Enemies/Glagars/Glagar_hurt.b3d"
 Palette\Glagar\AnimHurt = LoadAnimSeq(Palette\Glagar\HandleNum, File$)
 File$ = "media/Visuals/Enemies/Glagars/Glagar_die.b3d"
 Palette\Glagar\AnimDie = LoadAnimSeq(Palette\Glagar\HandleNum, File$)
 ;Palette\Glagar\BrushNum = LoadBrush("media/Visuals/Enemies/Glagars/GlagarMap.bmp")
 ;PaintEntity Palette\Glagar\HandleNum, Palette\Glagar\BrushNum
 ;HERE IS THE SECOND ENEMY, NOTE THAT THE ERROR WILL OCCOUR ON BOTH OF THEM
 Palette\RedGlagar = CreateEnemy()
 CopyEnemy(Palette\RedGlagar, Palette\Glagar)
 Palette\RedGlagar\AttackSpeed = 2000
 Palette\RedGlagar\Attack\Explosion\Damage# = 125
 Palette\RedGlagar\MaxHealth# = 1750
 Palette\RedGlagar\AI_BATTLE = BATTLE_INTERCEPT
 Palette\RedGlagar\BrushNum = LoadBrush("media/Visuals/Enemies/Glagars/RedGlagar.bmp")


ENEMY COPYING CODE

Function CopyEnemy(Hold.Enemy, Copy.Enemy, Hide = False)
 CopyVect(Hold\Position, Copy\Position)
 Hold\HandleNum = CopyEntity(Copy\HandleNum)
 If Hide Then HideEntity Hold\HandleNum
 CopyVect(Hold\Move, Copy\Move)
 CopyVect(Hold\Impulse, Copy\Impulse)
 CopyVect(Hold\Rotation, Copy\Rotation)
 CopyVect(Hold\OldPos, Copy\OldPos)
 CopyVect(Hold\Destination, Copy\Destination)
 Hold\BrushNum = Copy\BrushNum
 Hold\Speed# = Copy\Speed#
 Hold\M# = Copy\M#
 Hold\XRadius# = Copy\XRadius#
 Hold\YRadius# = Copy\YRadius#
 EntityType Hold\HandleNum, COL_ENEMY 
 EntityRadius Hold\HandleNum, Hold\XRadius#, Hold\YRadius#
 Hold\AttackSpeed = Copy\AttackSpeed
 Hold\RecoverSpeed = Copy\RecoverSpeed
 Hold\LastAttack = Copy\LastAttack
 Hold\AttackDelay = Copy\AttackDelay
 Hold\MaxHealth# = Copy\MaxHealth#
 Hold\AI_BATTLE = Copy\AI_BATTLE
 Hold\AI_SHOOT = Copy\AI_SHOOT
 Hold\AI_PATROL = Copy\AI_PATROL
 Hold\DieSpeed = Copy\DieSpeed
 CopyMissile(Hold\Attack, Copy\Attack)
 Hold\Leash = Copy\Leash
 CopyVect(Hold\Spawn, Copy\Spawn)
 CopyVect(Hold\VOffset, Copy\VOffset)
 Hold\AnimAttack = Copy\AnimAttack
 Hold\AnimHurt = Copy\AnimHurt
 Hold\AnimDie = Copy\AnimDie
 Hold\AnimSpeed# = Copy\AnimSpeed#
 Hold\ShootRange = Copy\ShootRange
 Hold\ChaseRange = Copy\ChaseRange
 Hold\SoundAttack = Copy\SoundAttack
 Hold\SoundHurt = Copy\SoundHurt
 Hold\SoundDie = Copy\SoundDie
 Hold\OneThruster = Copy\OneThruster
 Hold\Spray = Copy\Spray
End Function 


ENEMY SPAWNING CODE
Function SpawnEnemy.Enemy(Template.Enemy, Position.Vector)
 ;This will spawn an enemy given a template and a position to spawn
 E.Enemy = CreateEnemy()
 CopyEnemy(E, Template)
 CopyVect(E\Spawn, Position)
 CopyVect(E\Position, Position)
 E\Initialized = True
 E\Health# = Template\MaxHealth#
 CopyVect(E\Destination, E\Spawn)
 E\Offset = CreatePivot()
 PositionEntity E\Offset, E\Position\X#, E\Position\Y#, E\Position\Z#
 E\DetectHandle = CreatePivot(E\HandleNum)
 E\AimHandle = CreatePivot()
 PositionEntity E\DetectHandle, 0, 0, (.5*E\ChaseRange#)
 EntityParent E\HandleNum, E\Offset
 X# = -E\VOffset\X#
 Y# = -E\VOffset\Y#
 Z# = -E\VOffset\Z#
 PositionEntity E\HandleNum, X#, Y#, Z#
 EntityAutoFade E\HandleNum, 600, 800
 EntityRadius E\HandleNum, E\XRadius#
 EntityType E\HandleNum, COL_ENEMY
 Return E
End Function

Thank you for your help!