I can nail down the exact reason for the crash but just from snippet you have posted I can already see a few 'unclean' things.
1st: Why are you even setting 'self.window=0' at all? There's no need for that and even though Lua isn't strictly typed, this could cause issues more than be helpful. It should actually be hard to even detect window being nil with that in the code. You should be seeing type issues instead.
Judging from that I somehow fear that you are setting self.window to nil somewhere in the lines you didn't post.
2nd: Setting 'windowstyle = window.FullScreen' will cause issues while keeping if 'System:GetProperty("fullscreen")=="1" then windowstyle=windowstyle+window.FullScreen end' if somebody actually ever uses command line option for fullscreen, as window.FullScreen .titlebar are actually just constant numbers that, when added, give a sum that can be uniquely traced back to the flags that were set. Adding the same constant twice should never happen here.
I would strongly recommend pasting the entire App.lua contents unless you are hiding the secret sauce there.