Trouble shooting can be harsh and sometimes the biggest errors are due to very very small mistakes that even can't be seen by the best programmers
The solution is simple, you use a while expression but you don't end it with a wait instruction.
Normally the engine should indicate an endless loop event but I guess your if-clause overrules the call since you use a 'x++ algoritme' at the end AFAIK. Thus, when ending the application, the thing will crash as you end the 'x++ algoritme'.
Cheers
Frazzle