Page 1 of 1

Application crashes without error

Posted: Wed Apr 10, 2013 4:58 pm
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

Re: Application crashes without error

Posted: Wed Apr 10, 2013 5:09 pm
by ts-soft
I think, you use DeleteElement without to have a actual Element, but without working code ...

Re: Application crashes without error

Posted: Wed Apr 10, 2013 8:02 pm
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?).

Re: Application crashes without error

Posted: Wed Apr 10, 2013 8:14 pm
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!