I can only see part of your code. Do you have a larger for loop, not seen, around the whole thing? It looks like you have a game loop and you recreate the udg every time? You only need to create the udg once and then you can start your game loop. Move the code in lines 62 to 75 to the beginning and make sure it is only run once.