Re: [hatari-devel] Patch to fix pause bug on Mac

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Did the patch work as an attachment?


On Tue, 20 Sept 2022 at 21:16, Chris Jenkins <cdpjenkins@xxxxxxxxx> wrote:
Hi Eero,

Apologies. I thought pasting the patch inline would make life easier but apparently not :-/

Let me know if this attachment works.

Cheers,
Chris


On Mon, 19 Sept 2022 at 22:17, Eero Tamminen <oak@xxxxxxxxxxxxxx> wrote:
Hi Chris,

Could you send your patch as attachment, instead of pasting it directly
to the mail?

(It looks OK, but is messed up.)

        - Eero

On 19.9.2022 22.59, Chris Jenkins wrote:
> Here is a patch to fix an annoying bug in the Mac GUI where performing
> certain actions when paused will cause emulation to be unpaused once the
> action is complete.
>
> *Steps to reproduce:*
> - Pause emulation
> - Perform one of the following:
>    - Open preferences
>    - Create a blank floppy
> - Close the resulting dialog box
>
> *Expected results:*
> - Emulation is still paused
>
> *Actual results:*
> - Emulation is unpaused
>
> The problem is that emulation is paused before running a modal dialog and
> unpaused afterwards., regardless of whether emulation was already paused.
> The patch implements the same pattern that is already implemented in the
> SDL GUI: Only unpause if emulation was not paused in the beginning.
>
> I confess I'm not entirely comfortable with writing exactly the same code
> that is found in the SDL GUI here. I'd really like to create an abstraction
> at a lower level within Hatari that can take care of this case where we
> want to pause, do something, unpause if not already paused. But I don't
> know how to do something like that cleanly in C.
>
> All feedback on this patch very much appreciated.
>
> Cheers,
> Chris
>
>>From 7fa9ed94a3c29ac04531bcc75b0a72f80d63bb9e Mon Sep 17 00:00:00 2001
>
> From: Chris Jenkins <cdpjenkins@xxxxxxxxx>
>
> Date: Mon, 19 Sep 2022 20:50:26 +0100
>
> Subject: [PATCH] Don't unpause if emulation was already paused
>
>
> ---
>
>   src/gui-osx/SDLMain.m |  6 ++++--
>
>   src/gui-osx/Shared.h  |  2 +-
>
>   src/gui-osx/Shared.m  | 10 ++++++----
>
>   3 files changed, 11 insertions(+), 7 deletions(-)
>
>
> diff --git a/src/gui-osx/SDLMain.m b/src/gui-osx/SDLMain.m
>
> index a65e0064..f6bcfc42 100644
>
> --- a/src/gui-osx/SDLMain.m
>
> +++ b/src/gui-osx/SDLMain.m
>
> @@ -426,7 +426,7 @@ char szPath[FILENAME_MAX] ; // for general use
>
>    // commit back to the configuration settings if choosing user confirm)
>
>    CurrentParams = ConfigureParams;
>
>
>
> - GuiOsx_Pause(true);
>
> + bool bWasRunning = GuiOsx_Pause(true);
>
>
>
>    newCfg = [NSApp hopenfile:NO defoDir:nil defoFile:ConfigFile] ;
>
>
>
> @@ -446,7 +446,9 @@ char szPath[FILENAME_MAX] ; // for general use
>
>    ConfigureParams = CurrentParams;   //Restore previous Params.
>
>    } ;
>
>
>
> - GuiOsx_Resume();
>
> + if (bWasRunning) {
>
> + GuiOsx_Resume();
>
> + }
>
>   }
>
>
>
>   /*----------------------------------------------------------------------*/
>
> diff --git a/src/gui-osx/Shared.h b/src/gui-osx/Shared.h
>
> index e6654766..e07847b4 100644
>
> --- a/src/gui-osx/Shared.h
>
> +++ b/src/gui-osx/Shared.h
>
> @@ -30,7 +30,7 @@
>
>   void GuiOsx_ExportPathString(NSString* path, char* szTarget, size_t
> cchTarget);
>
>
>
>   // Pauses emulation and gets ready to use Cocoa UI
>
> -void GuiOsx_Pause(bool);
>
> +bool GuiOsx_Pause(bool);
>
>
>
>   // Switches back to emulation mode and resume emulation
>
>   void GuiOsx_Resume(void);
>
> diff --git a/src/gui-osx/Shared.m b/src/gui-osx/Shared.m
>
> index bb383c33..bd9f6b77 100644
>
> --- a/src/gui-osx/Shared.m
>
> +++ b/src/gui-osx/Shared.m
>
> @@ -27,13 +27,15 @@
>
>    [window setDelegate:self];
>
>
>
>    // Change emulation and UI state
>
> - GuiOsx_Pause(true);
>
> + bool bWasRunning = GuiOsx_Pause(true);
>
>
>
>    // Run it as modal
>
>    [NSApp runModalForWindow:window];
>
>
>
>    // Restore emulation and UI state
>
> - GuiOsx_Resume();
>
> + if (bWasRunning) {
>
> + GuiOsx_Resume();
>
> + }
>
>   }
>
>
>
>   // On closure of the NSWindow, end the modal session
>
> @@ -67,10 +69,10 @@ void GuiOsx_ExportPathString(NSString* path, char*
> szTarget, size_t cchTarget)
>
>   /*Pauses emulation */
>
>   /* Added the visualize option for 2.0.0 */
>
>   /*----------------------------------------------------------------------*/
>
> -void GuiOsx_Pause(bool visualize)
>
> +bool GuiOsx_Pause(bool visualize)
>
>   {
>
>    // Pause emulation
>
> - Main_PauseEmulation(visualize);
>
> + return Main_PauseEmulation(visualize);
>
>   }
>
>
>
>   /*-----------------------------------------------------------------------*/
>




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/