Memory bug?

Miscellaneous Forums/General Discussion/Memory bug?

I use CollideImage to check for collisions between bullets and enemies in my game. Everything worked just fine.

Then I added music to the game. The game finds all OGG files in a subdirectory and loads them when the game starts up.

Suddenly, one of the weapons doesn't collide anymore. If I use another image to check the collisions with it works again.
I use the now non-collideable image to draw the weapon so I know the image loads. It's just that CollideImage doesn't detect any collisions with it anymore.

To summarize: Image loads and is drawn correctly. CollideImage doesn't return any collisions anymore. It did before I added the music.

This had me to believe it's some kind of memory bug. But it's just a whild guess. Anyone had a similar problem? How could I kill this bug and move on with the game?

Edit: Whoops. Should probably be in BlitzMax programming or something instead. :P

Can you confirm that removing the music again fixes the issue?

Removing the music doesn't fix the issue. This suprises me a lot.
I know the weapon worked before I added the music. (I playtest my games a lot)

Just one of the funny bugs that appears from time to time I guess. Yesterday my game froze if I started the game with my joypad pluged in. It works just great today...

Ahh, the chances are, and this happens to me once in a while, you might have hit the keyboard or forgot that you updated seemingly unrelated.

Got any code to look at?

Yeah, if removing the music doesn't fix the issue, then you probably changed the collision code by accident without noticing.

All weapons are children to the tBullet type. All wepons overload the collision method. Here is the relevant parts of tBullet:

	Function update_ammo( dt:Float )
		If Not blist Then Return
		
		For Local b:tBullet = EachIn blist
			b.update(dt)
			b.check_collision()
		Next
	EndFunction


	Method collision:Object[]()
		Return CollideImage( gfx_bullet, x,y,0, 1,0 )
	EndMethod

	Method check_collision()
		' Collision with anything?
		Local objarr:Object[] =  collision() 
			
		For Local o:Object = EachIn objarr
			
			If tSoldier(o) Then
				tSoldier(o).Kill()
				impact()
				player_shot_hits:+1
				
				If tLaser(Self) player_shots:+1
				
			ElseIf tPlane(o) Then
				
				If tLaser(Self) Then

					' Don't want the laser to hurt the plane
					' all the way through. Just once and then
					' move on...

					player_shots:+1
					If tPlane(o).laser_immunity <> Self Then
						tPlane(o).take_damage( damage )
						player_shot_hits:+1
					EndIf
				
					' Make sure this laser beam doesn't hurt this
					' plane again.
					tPlane(o).laser_immunity = tLaser(Self)

				Else
					tPlane(o).take_damage( damage )				
					player_shot_hits:+1
				EndIf
				
				impact()
			
			ElseIf tCrate(o) Then
			
				If tEntity.list.contains(o) Then
					If tLaser(Self) player_shots:+1

					tCrate(o).remove()
					impact()
				
					get_random_ammo()
					player_shot_hits:+1
		
				EndIf
				
			Else
				Print "Unknown object hit"	
			EndIf
								
		Next		
	EndMethod


It's the Nail bomb that I have problems with. All it needs to overwrite is the collision method:

	Method collision:Object[]() ' --- This one does not work
		Return CollideImage( gfx_nailbomb, x,y,0, 1,0 )
	EndMethod

	'Method collision:Object[]() ' --- This one works just fine
	'	Return CollideImage( gfx_scatter, x,y,0, 1,0 )
	'EndMethod

The impact() method is different for each type of weapons. In some cases it does nothing, in other it spawns explosions or more bullets (as in the nailbomb type)
I know for sure that the impact() function isn't called at all for the nailbomb.

gfx_nailbomb loads without any problems and displays correctly when the game calls tnailbomb.draw(). It's when it's used in collision the bug appears.
Funny thing is that other images loaded after gfx_nailbomb doesn't have this problem.

CollideImage returns an empty array when I use gfx_nailbomb.


edit:
Yeah, if removing the music doesn't fix the issue, then you probably changed the collision code by accident without noticing.

The only thing that I could accidently change is the collision method inside tNailBomb. But it looks like all the others. except that it uses gfx_nailbomb.

This is a really wierd bug! :/
Or perhaps I'm just blind. I really hope you find a typo somewhere in the code.