При перезапуске моей игры он выходит из строя с предупреждениями с низкой памятью. Я ищу способ закрыть EAGLView и остановить все процессы. Я не уверен, что вам показать, поэтому, пожалуйста, запросите дополнительную информацию в случае необходимости.Закрытие EAGLView и прекращение всех процессов
У меня есть EAGLView с mainGameLoop, как следует.
- (void)mainGameLoop {
// Create variables to hold the current time and calculated delta
CFTimeInterval time;
float delta;
// This is the heart of the game loop and will keep on looping until it is told otherwise
while(true) {
// Create an autorelease pool which can be used within this tight loop. This is a memory
// leak when using NSString stringWithFormat in the renderScene method. Adding a specific
// autorelease pool stops the memory leak
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// I found this trick on iDevGames.com. The command below pumps events which take place
// such as screen touches etc so they are handled and then runs our code. This means
// that we are always in sync with VBL rather than an NSTimer and VBL being out of sync
while(CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.02, TRUE) == kCFRunLoopRunHandledSource);
// Get the current time and calculate the delta between the lasttime and now
// We multiply the delta by 1000 to give us milliseconds
time = CFAbsoluteTimeGetCurrent();
delta = (time - lastTime) * 1000;
// Go and update the game logic and then render the scene
[self updateScene:delta];
[self renderScene];
// Set the lasttime to the current time ready for the next pass
lastTime = time;
// Release the autorelease pool so that it is drained
[pool release];
}
}
Во-первых, вам понадобится способ вырваться из игрового цикла. Вы думали о том, что ваше условие 'while()' фактически проверяет значение? Кроме того, использование цикла while() не может быть лучшим способом для обновления вашего дисплея. Вы действительно должны изучить использование CADisplayLink для этого. Наконец, [EAGLView не является классом какао-акций] (http://stackoverflow.com/a/8438138/19679), это просто пользовательский UIView, в котором размещается OpenGL ES CAEAGLLayer, который иногда используется в примере кода Apple, поэтому некоторые люди может не знать, что это такое. –
Примером является исходный mainGameLoop. Я думал, что у кого-то есть возможность сделать это. Atm я использую while (self.hidden == FALSE) и скрываю представление при отображении оценок и т. Д. Моя игра прерывается во время (CFRunLoopRunInMode (kCFRunLoopDefaultMode, 0,02, TRUE) == kCFRunLoopRunHandledSource); прямо сейчас, после повторного воспроизведения игры несколько раз. – Lohardt
Почему бы вам не использовать NSTimer или CADisplayLink? – Max