"Access violation reading location 0x0000000000000000" means the program is trying to read from location 0 in memory, which isn't allowed. This is typically caused by using a pointer which is null.
If you run the program in a debugger, it should stop on the actual location of the null dereference. The code you provided might not actually be where things are failing (if it is, then probably either window or entity are null).