Application crashes without error

Just starting out? Need help? Post your questions and find answers here.
Thiefbrain
New User
New User
Posts: 8
Joined: Wed Apr 10, 2013 4:43 pm

Application crashes without error

Post by Thiefbrain »

Hi guys,

I registered here because my application is crashing without error.. I'm trying to write a maze generation algorithm while the maze is displayed on the user's screen. Here is the procedure within the application crashes (I think, since OGRE doesn't give any error). The Procedure MazeGen is called as a thread.

Code: Select all

Structure Cell
	x.a
	y.a
EndStructure

Global NewList VisitedCells.Cell()
Global NewMap Cells.a()
Global NewMap Walls.l()

Procedure HasUnvisitedNeighbours(x, y)
	If x = 0
		ProcedureReturn Bool(Cells(Str((x + 1) << 5 | y)) Or Cells(Str(x << 5 | (y + 1))) Or Cells(Str(x << 5 | (y - 1))))
	ElseIf x = 23
		ProcedureReturn Bool(Cells(Str((x - 1) << 5 | y)) Or Cells(Str(x << 5 | (y + 1))) Or Cells(Str(x << 5 | (y - 1))))
	ElseIf y = 0
		ProcedureReturn Bool(Cells(Str((x - 1) << 5 | y)) Or Cells(Str((x + 1) << 5 | y)) Or Cells(Str(x << 5 | (y + 1))))
	ElseIf y = 23
		ProcedureReturn Bool(Cells(Str((x - 1) << 5 | y)) Or Cells(Str((x + 1) << 5 | y)) Or Cells(Str(x << 5 | (y - 1))))
	Else
		ProcedureReturn Bool(Cells(Str((x - 1) << 5 | y)) Or Cells(Str((x + 1) << 5 | y)) Or Cells(Str(x << 5 | (y - 1))) Or Cells(Str(x << 5 | (y + 1))))
	EndIf
EndProcedure

Procedure GenMaze(*var)
	Protected x.a = Random(23), y.a = Random(23), dir.a
	Repeat
		While HasUnvisitedNeighbours(x, y)
			dir = Random(3)
			If dir = 0 And y > 0 And Walls(Str(x << 5 | y))
				DeleteMapElement(Cells(), Str(x << 5 | y))
				AddElement(VisitedCells())
				VisitedCells()\x = x : VisitedCells()\y = y
				FreeEntity(Walls(Str(x << 5 | y)))
				DeleteMapElement(Walls(), Str(x << 5 | y))
				y = y - 1
			ElseIf dir = 1 And x < 23 And Walls(Str(1024 | (x + 1) << 5 | y))
				DeleteMapElement(Cells(), Str(x << 5 | y))
				AddElement(VisitedCells())
				VisitedCells()\x = x : VisitedCells()\y = y
				x = x + 1
				FreeEntity(Walls(Str(1024 | x << 5 | y)))
				DeleteMapElement(Walls(), Str(1024 | x << 5 | y))
			ElseIf dir = 2 And y < 23 And Walls(Str(x << 5 | (y + 1)))
				DeleteMapElement(Cells(), Str(x << 5 | y))
				AddElement(VisitedCells())
				VisitedCells()\x = x : VisitedCells()\y = y
				y = y + 1
				FreeEntity(Walls(Str(x << 5 | y)))
				DeleteMapElement(Walls(), Str(x << 5 | y))
			ElseIf dir = 3 And x > 0 And Walls(Str(1024 | x << 5 | y))
				DeleteMapElement(Cells(), Str(x << 5 | y))
				AddElement(VisitedCells())
				VisitedCells()\x = x : VisitedCells()\y = y
				FreeEntity(Walls(Str(1024 | x << 5 | y)))
				DeleteMapElement(Walls(), Str(1024 | x << 5 | y))
				x = x - 1
			EndIf
			Delay(100)
		Wend
		DeleteElement(VisitedCells())
		x = VisitedCells()\x
		y = VisitedCells()\y
	Until MapSize(Cells()) = 0
EndProcedure
So why is the application crashing? Is it because of the massive calls of maps/lists?

~ Thiefbrain
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Application crashes without error

Post by ts-soft »

I think, you use DeleteElement without to have a actual Element, but without working code ...
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Thiefbrain
New User
New User
Posts: 8
Joined: Wed Apr 10, 2013 4:43 pm

Re: Application crashes without error

Post by Thiefbrain »

You may be right, ts-soft, but when I do a little test-code where it tries to delete an not-existing linked list element, it gives me an error. If I do the same with maps, it doesn't give me any error (maybe that should output an error, too?).
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Application crashes without error

Post by ts-soft »

yes, the should give an error, but ...

The best is to use ForEach : Next for your list and after DeleteElement a Continue!
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Post Reply