OsX[AppleEvents]: try to avoid some crash by delaying the function which is called

by such events...

Fixes #292
This commit is contained in:
ALONSO Laurent
2022-07-14 12:56:10 +02:00
committed by Celtic Minstrel
parent eea6166b11
commit e2a4fcc788
8 changed files with 79 additions and 6 deletions

View File

@@ -166,4 +166,13 @@ const int UI_LAYER_MENUBAR = 1200;
const int talk_gword_offset_x = 19;
const int talk_gword_offset_y = 7;
#ifdef __APPLE__
enum eMenuChoice {
MENU_CHOICE_NONE,
MENU_CHOICE_GENERIC,
MENU_CHOICE_MONSTER_INFO,
MENU_CHOICE_SPELL
};
#endif
#endif

View File

@@ -109,6 +109,11 @@ extern long anim_ticks;
static void init_boe(int, char*[]);
static void showWelcome();
#ifdef __APPLE__
eMenuChoice menuChoice=eMenuChoice::MENU_CHOICE_NONE;
short menuChoiceId=-1;
#endif
int main(int argc, char* argv[]) {
#if 0
void debug_oldstructs();
@@ -264,6 +269,26 @@ void handle_events() {
cFramerateLimiter fps_limiter;
while(!All_Done) {
#ifdef __APPLE__
if (menuChoiceId>=0) {
eMenuChoice aMenuChoice=menuChoice;
menuChoice=eMenuChoice::MENU_CHOICE_NONE;
switch(aMenuChoice) {
case eMenuChoice::MENU_CHOICE_GENERIC:
handle_menu_choice(eMenu(menuChoiceId));
break;
case eMenuChoice::MENU_CHOICE_SPELL:
handle_menu_spell(eSpell(menuChoiceId));
break;
case eMenuChoice::MENU_CHOICE_MONSTER_INFO:
handle_monster_info_menu(menuChoiceId);
break;
case eMenuChoice::MENU_CHOICE_NONE:
break;
}
menuChoiceId=-1;
}
#endif
while(mainPtr.pollEvent(currentEvent)) handle_one_event(currentEvent);
// It would be nice to have minimap inside the main game window (we have lots of screen space in fullscreen mode).

View File

@@ -1,6 +1,10 @@
#include <SFML/Graphics.hpp>
#ifdef __APPLE__
extern eMenuChoice menuChoice;
extern short menuChoiceId;
#endif
int main(int argc, char* argv[]);
void update_everything();
void redraw_everything();

View File

@@ -16,6 +16,9 @@
#include "boe.consts.hpp"
#include "spell.hpp"
extern eMenuChoice menuChoice;
extern short menuChoiceId;
extern short on_spell_menu[2][62];
extern short on_monst_menu[256];
extern bool party_in_memory;
@@ -282,16 +285,22 @@ void menu_activate() {
-(void) monstMenu:(id) sender {
cMonster* monst = [[sender representedObject] monst];
(void) monst; // Mark variable as unused
handle_monster_info_menu([monster_info_menu indexOfItem: sender] - 1);
menuChoice=eMenuChoice::MENU_CHOICE_MONSTER_INFO;
menuChoiceId=short([monster_info_menu indexOfItem: sender] - 1);
//handle_monster_info_menu([monster_info_menu indexOfItem: sender] - 1);
}
-(void) spellMenu:(id) sender {
SpellWrapper* spell = [sender representedObject];
handle_menu_spell(cSpell::fromNum([spell type], [spell num]));
menuChoice=eMenuChoice::MENU_CHOICE_SPELL;
menuChoiceId=short(cSpell::fromNum([spell type], [spell num]));
//handle_menu_spell(cSpell::fromNum([spell type], [spell num]));
}
-(void) menuChoice:(id) sender {
handle_menu_choice(eMenu([[sender representedObject] intValue]));
menuChoice=eMenuChoice::MENU_CHOICE_GENERIC;
menuChoiceId=short([[sender representedObject] intValue]);
//handle_menu_choice(eMenu([[sender representedObject] intValue]));
}
@end

View File

@@ -24,6 +24,10 @@
#include "tools/prefs.hpp"
#include "tools/framerate_limiter.hpp"
#ifdef __APPLE__
short menuChoiceId=-1;
#endif
cUniverse univ;
rectangle pc_area_buttons[6][4] ; // 0 - whole 1 - pic 2 - name 3 - stat strs 4,5 - later
@@ -168,6 +172,12 @@ void handle_events() {
cFramerateLimiter fps_limiter;
while(!All_Done) {
#ifdef __APPLE__
if (menuChoiceId>=0) {
handle_menu_choice(eMenu(menuChoiceId));
menuChoiceId=-1;
}
#endif
while(mainPtr.pollEvent(currentEvent)) handle_one_event(currentEvent);
redraw_everything();

View File

@@ -15,6 +15,8 @@
#error pc.menus.mm is Mac-specific code; try compiling pc.menus.win.cpp instead
#endif
extern short menuChoiceId;
using MenuHandle = NSMenu*;
extern cUniverse univ;
@@ -102,7 +104,8 @@ void drawMenuBar() {
@implementation MenuHandler
-(void) menuChoice:(id) sender {
eMenu opt = eMenu([[sender representedObject] intValue]);
handle_menu_choice(opt);
menuChoiceId=short([[sender representedObject] intValue]);
//eMenu opt = eMenu([[sender representedObject] intValue]);
//handle_menu_choice(opt);
}
@end

View File

@@ -30,6 +30,10 @@
#include "tools/event_listener.hpp"
#include "tools/drawable_manager.hpp"
#ifdef __APPLE__
short menuChoiceId=-1;
#endif
/* Globals */
bool All_Done = false;
sf::RenderWindow mainPtr;
@@ -227,6 +231,12 @@ void handle_events() {
cFramerateLimiter fps_limiter;
while(!All_Done) {
#ifdef __APPLE__
if (menuChoiceId>=0) {
handle_menu_choice(eMenu(menuChoiceId));
menuChoiceId=-1;
}
#endif
while(mainPtr.pollEvent(currentEvent)) handle_one_event(currentEvent);
// Why do we have to set this to false after handling every event?

View File

@@ -12,6 +12,8 @@
#include "tools/winutil.hpp"
#include "tools/undo.hpp"
extern short menuChoiceId;
using MenuHandle = NSMenu*;
MenuHandle menu_bar_handle;
MenuHandle file_menu, edit_menu, app_menu, scen_menu, town_menu, out_menu, help_menu;
@@ -166,6 +168,7 @@ void update_edit_menu() {
@implementation MenuHandler
-(void) menuChoice:(id) sender {
handle_menu_choice(eMenu([[sender representedObject] intValue]));
menuChoiceId=short([[sender representedObject] intValue]);
//handle_menu_choice(eMenu([[sender representedObject] intValue]));
}
@end