Browse Source

'Fix' crash when performing a key press caused by keypresses being delivered to the wrong instance of the GameView.

I am as of yet unsure what the proper fix to this is.
Sam Jaffe 6 years ago
parent
commit
3de0ed88b4
1 changed files with 10 additions and 0 deletions
  1. 10 0
      danmaku/GameView.mm

+ 10 - 0
danmaku/GameView.mm

@@ -124,6 +124,11 @@ namespace env { namespace detail {
 }
 
 - (void)keyDown:(NSEvent *)theEvent {
+  if (!game) {
+    // This is a really ugly hack because, for dumb reasons, there are two
+    // GameView objects, one that I initialize, and one that I don't
+    return [(GameView*)[[self window] delegate] keyDown:theEvent];
+  }
   if ([theEvent isARepeat])
     return;
   
@@ -156,6 +161,11 @@ namespace env { namespace detail {
 }
 
 - (void)keyUp:(NSEvent *)theEvent {
+  if (!game) {
+    // This is a really ugly hack because, for dumb reasons, there are two
+    // GameView objects, one that I initialize, and one that I don't
+    return [(GameView*)[[self window] delegate] keyDown:theEvent];
+  }
   NSLog(@"keyUp -> { 0x%04x, 0x%08lx }", [theEvent keyCode],
         [theEvent modifierFlags]);
   NSString *str = [theEvent charactersIgnoringModifiers];