Quote: "If a user wants to end it and clicks on cross of the window the programm crashes."
This is not standard behaviour for a DBP application. Are you using any plugins? It could be that if you aren't ending a plugin that requires it there might be a crash. One standard way around this is to compile the application as "fulldesktop" and give the user another way to end the app such as if they hit the escapekey it triggers a "Do you want to quit (y/n)?" event.
rem before your LOOP
disable escapekey
rem during your LOOP
if escapekey() then quitgame()
rem after your LOOP
function quitgame()
while done=0
ink rgb(0,0,0),0
box 0,0,screen width(),screen height()
ink rgb(255,255,255),0
center text screen width()/2,screen height()/2,"Do you want to quit(y/n)?"
if keystate(21)
rem END ANY PLUGINS THAT NEED IT HERE!!!!
end
endif
if keystate(49) then done=1
sync
endwhile
endfunction
Untested and written on the fly but try it and see how you get on.
Hope that helps...