Skip to content

Commit

Permalink
fix bug about invalid "write debug log to file"
Browse files Browse the repository at this point in the history
修复:mac版Player在禁用"Show Debug Console"后, "Write Debug Log to File"无效,见 [Issue chukong#221](https://github.com/dualface/quick-cocos2d-x/issues/221#issuecomment-32004473)
  • Loading branch information
dabing1022 committed Jan 10, 2014
1 parent 771b7da commit b0793fd
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions player/proj.mac/AppController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,14 @@ - (void) openConsoleWindow
consoleController = [[ConsoleWindowController alloc] initWithWindowNibName:@"ConsoleWindow"];
}
[consoleController.window orderFrontRegardless];
}

- (void) startWriteDebugLog
{
//set console pipe
pipe = [NSPipe pipe] ;
pipeReadHandle = [pipe fileHandleForReading] ;

int outfd = [[pipe fileHandleForWriting] fileDescriptor];
if (dup2(outfd, fileno(stderr)) != fileno(stderr) || dup2(outfd, fileno(stdout)) != fileno(stdout))
{
Expand Down Expand Up @@ -226,6 +229,11 @@ - (void) startup
{
[self openConsoleWindow];
}

if(projectConfig.isWriteDebugLogToFile() || projectConfig.isShowConsole())
{
[self startWriteDebugLog];
}

app = new AppDelegate();
bridge = new AppControllerBridge(self);
Expand Down Expand Up @@ -501,11 +509,15 @@ - (void)handleNotification:(NSNotification *)note
NSData *data = [[note userInfo] objectForKey:NSFileHandleNotificationDataItem];
NSString *str = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
//show log to console
[consoleController trace:str];
if(fileHandle!=nil){
if(projectConfig.isShowConsole())
{
[consoleController trace:str];
}
//write log to file
if(fileHandle!=nil)
{
[fileHandle writeData:[str dataUsingEncoding:NSUTF8StringEncoding]];
}

}

- (void) closeDebugLogFile
Expand Down

0 comments on commit b0793fd

Please sign in to comment.