diff --git a/desmume/src/cocoa/main_window.m b/desmume/src/cocoa/main_window.m index 1539f98fc..bb5063c88 100644 --- a/desmume/src/cocoa/main_window.m +++ b/desmume/src/cocoa/main_window.m @@ -81,8 +81,6 @@ NSMenuItem *subBG2_item; NSMenuItem *subBG3_item; NSMenuItem *screenshot_to_file_item; -//fixme: if video_output_view does not load properly, loading a game, then loading a save state doesn't work - @implementation VideoOutputWindow - (void)setStatusText:(NSString*)value @@ -156,8 +154,7 @@ NSMenuItem *screenshot_to_file_item; rect.origin.y = status_bar_height; rect.size.width = DS_SCREEN_WIDTH; rect.size.height = DS_SCREEN_HEIGHT_COMBINED; - //video_output_view = [[VideoOutputView alloc] initWithFrame:rect]; //no nil check - will do it's own error messages - video_output_view = nil; + video_output_view = [[VideoOutputView alloc] initWithFrame:rect]; //no nil check - will do it's own error messages [video_output_view setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable]; //view will automatically resize with the window [[window contentView] addSubview:video_output_view]; @@ -231,14 +228,15 @@ NSMenuItem *screenshot_to_file_item; int i; for(i = 0; i < MAX_SLOTS; i++) if([self saveStateExists:i] == YES) - [saveSlot_item[i] setState:NSOnState]; + if([saveSlot_item[i] target] == self)[saveSlot_item[i] setState:NSOnState]; else - [saveSlot_item[i] setState:NSOffState]; + if([saveSlot_item[i] target] == self)[saveSlot_item[i] setState:NSOffState]; + } else { int i; for(i = 0; i < MAX_SLOTS; i++) - [saveSlot_item[i] setState:NSOffState]; + if([saveSlot_item[i] target] == self)[saveSlot_item[i] setState:NSOffState]; } return result; @@ -1152,8 +1150,9 @@ NSMenuItem *screenshot_to_file_item; [loadSlot_item[i] setTarget:self]; if([self saveStateExists:i] == YES) + { [saveSlot_item[i] setState:NSOnState]; - else + } else [saveSlot_item[i] setState:NSOffState]; } @@ -1359,6 +1358,7 @@ NSMenuItem *screenshot_to_file_item; if(item == rotation90_item)return NO; if(item == rotation180_item)return NO; if(item == rotation270_item)return NO; + if(item == screenshot_to_file_item)return NO; } return YES; diff --git a/desmume/src/cocoa/nds_control.m b/desmume/src/cocoa/nds_control.m index 24bd5ef1b..5a96e58bc 100644 --- a/desmume/src/cocoa/nds_control.m +++ b/desmume/src/cocoa/nds_control.m @@ -101,6 +101,9 @@ struct NDS_fw_config_data firmware; NDS_CreateDummyFirmware(&firmware); //3D Init + NSOpenGLContext *prev_context = [NSOpenGLContext currentContext]; + [prev_context retain]; + bool gl_ready = false; NSOpenGLPixelFormatAttribute attrs[] = @@ -167,13 +170,22 @@ struct NDS_fw_config_data firmware; } } - if(gl_ready) + if(context) { + [context makeCurrentContext]; + NDS_3D_SetDriver(GPU3D_OPENGL); if(!gpu3D->NDS_3D_Init()) messageDialog(NSLocalizedString(@"Error", nil), @"Unable to initialize OpenGL components"); } + if(prev_context != nil) //make sure the old context is restored, and make sure our new context is not set in this thread (since the other thread will need it) + { + [prev_context makeCurrentContext]; + [prev_context release]; + } else + [NSOpenGLContext clearCurrentContext]; + //Sound Init if(SPU_ChangeSoundCore(SNDCORE_OSX, 735 * 4) != 0) messageDialog(NSLocalizedString(@"Error", nil), @"Unable to initialize sound core"); @@ -927,6 +939,7 @@ struct NDS_fw_config_data firmware; //Set the GPU context (if it exists) incase the core needs to load anything into opengl during state load NSOpenGLContext *prev_context = [NSOpenGLContext currentContext]; + [prev_context retain]; [context makeCurrentContext]; BOOL result = NO; @@ -935,8 +948,13 @@ struct NDS_fw_config_data firmware; [execution_lock unlock]; - [prev_context makeCurrentContext]; - + if(prev_context != nil) + { + [prev_context makeCurrentContext]; + [prev_context release]; + } else + [NSOpenGLContext clearCurrentContext]; + return result; } @@ -963,11 +981,11 @@ struct NDS_fw_config_data firmware; if(slot < 0)return NO; BOOL result = NO; - [execution_lock lock]; //Set the GPU context (if it exists) incase the core needs to load anything into opengl during state load NSOpenGLContext *prev_context = [NSOpenGLContext currentContext]; + [prev_context retain]; [context makeCurrentContext]; loadstate_slot(slot + 1); //no exection handling? @@ -975,8 +993,13 @@ struct NDS_fw_config_data firmware; [execution_lock unlock]; - [prev_context makeCurrentContext]; - + if(prev_context != nil) + { + [prev_context makeCurrentContext]; + [prev_context release]; + } else + [NSOpenGLContext clearCurrentContext]; + return result; }