Skip to content
This repository was archived by the owner on Dec 18, 2021. It is now read-only.

Commit d368007

Browse files
committed
Prevent the global variable from retaining the game core.
1 parent 439ad81 commit d368007

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

SMSGameCore.mm

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,14 @@ @interface SMSGameCore () <OESMSSystemResponderClient, OEGGSystemResponderClient
5555

5656
@implementation SMSGameCore
5757

58-
static SMSGameCore *current;
58+
static __weak SMSGameCore *_current;
5959

6060
#pragma mark Callbacks
6161

6262
void videoCallback(const unsigned short* frame, unsigned width, unsigned height, unsigned modeId, bool secondGG)
6363
{
64+
GET_CURRENT_AND_RETURN();
65+
6466
current->width = width;
6567
current->height = height;
6668

@@ -71,6 +73,8 @@ void videoCallback(const unsigned short* frame, unsigned width, unsigned height,
7173

7274
static void audioCallback(signed sampleLeft, signed sampleRight, unsigned soundChip)
7375
{
76+
GET_CURRENT_AND_RETURN();
77+
7478
if(soundChip == SMS_SOUND_SN76489)
7579
{
7680
[[current ringBufferAtIndex:0] write:&sampleLeft maxLength:2];
@@ -95,6 +99,8 @@ static void audioCallback(signed sampleLeft, signed sampleRight, unsigned soundC
9599

96100
static signed inputCallback (unsigned port, unsigned deviceId, unsigned objectId)
97101
{
102+
GET_CURRENT_AND_RETURN(0);
103+
98104
if(deviceId == SMS_DEVICE_JOYPAD)
99105
{
100106
if(port == SMS_PORT_1)
@@ -122,7 +128,7 @@ - (id)init
122128
controllerMask1 = 0;
123129
controllerMask2 = 0;
124130

125-
current = self;
131+
_current = self;
126132
}
127133
return self;
128134
}

0 commit comments

Comments
 (0)