From 38b17e11123d7da014d6c53c28f3d181a15517eb Mon Sep 17 00:00:00 2001 From: François Revol Date: Sun, 25 Nov 2012 19:47:48 +0100 Subject: beos: Partial replicant instanciation fix * use the correct resources * work around a deadlock, allows BeHappy to start, though removing the replicant from Tracker crashes --- beos/fetch_rsrc.cpp | 2 +- beos/gui.cpp | 28 +++++++++++++++++++++++++++- beos/gui.h | 2 ++ beos/scaffolding.cpp | 22 +++++++++++++++------- 4 files changed, 45 insertions(+), 9 deletions(-) (limited to 'beos') diff --git a/beos/fetch_rsrc.cpp b/beos/fetch_rsrc.cpp index 563f43145..d841a1d3b 100644 --- a/beos/fetch_rsrc.cpp +++ b/beos/fetch_rsrc.cpp @@ -66,7 +66,7 @@ struct fetch_rsrc_context { static struct fetch_rsrc_context *ring = NULL; -static BResources *gAppResources = NULL; +BResources *gAppResources = NULL; static bool fetch_rsrc_initialise(lwc_string *scheme) { diff --git a/beos/gui.cpp b/beos/gui.cpp index 9e26d44ff..dacdee909 100644 --- a/beos/gui.cpp +++ b/beos/gui.cpp @@ -457,6 +457,12 @@ int main(int argc, char** argv) options.Append("x-vnd.NetSurf"); } + if (!replicated) { + // create the Application object before trying to use messages + // so we can open an alert in case of error. + new NSBrowserApplication; + } + char* messages = "/boot/apps/netsurf/res/en/Messages"; /* initialise netsurf */ @@ -472,6 +478,27 @@ int main(int argc, char** argv) return 0; } +/** called when replicated from NSBaseView::Instantiate() */ +int gui_init_replicant(int argc, char** argv) +{ + setbuf(stderr, NULL); + + BPath options; + if (find_directory(B_USER_SETTINGS_DIRECTORY, &options, true) == B_OK) { + options.Append("x-vnd.NetSurf"); + } + + char* messages = "/boot/apps/netsurf/res/en/Messages"; + + /* initialise netsurf */ + netsurf_init(&argc, &argv, options.Path(), messages); + + gui_init(argc, argv); + gui_init2(argc, argv); + + return 0; +} + /* Documented in desktop/options.h */ void gui_options_init_defaults(void) { @@ -487,7 +514,6 @@ void gui_init(int argc, char** argv) if (pipe(sEventPipe) < 0) return; if (!replicated) { - new NSBrowserApplication; sBAppThreadID = spawn_thread(bapp_thread, "BApplication(NetSurf)", B_NORMAL_PRIORITY, (void *)find_thread(NULL)); if (sBAppThreadID < B_OK) return; /* #### handle errors */ diff --git a/beos/gui.h b/beos/gui.h index 6bbfa1dd1..af35677f1 100644 --- a/beos/gui.h +++ b/beos/gui.h @@ -30,6 +30,8 @@ #define CALLED() fprintf(stderr, "%s()\n", __FUNCTION__); extern bool replicated; +int gui_init_replicant(int argc, char** argv); + #if 0 /* GTK */ //extern GladeXML *gladeWindows; diff --git a/beos/scaffolding.cpp b/beos/scaffolding.cpp index e52e20963..c83cf959f 100644 --- a/beos/scaffolding.cpp +++ b/beos/scaffolding.cpp @@ -174,6 +174,10 @@ static int32 nsbeos_replicant_main_thread(void *_arg); // in beos_gui.cpp extern int main(int argc, char** argv); +// in fetch_rsrc.cpp +extern BResources *gAppResources; + + #warning XXX #if 0 /* GTK */ static gboolean nsbeos_window_url_activate_event(beosWidget *, gpointer); @@ -521,6 +525,10 @@ NSBaseView::Instantiate(BMessage *archive) //netsurf_init(2, info->args); //return NULL; + // do as much as possible in this thread to avoid deadlocks + + gui_init_replicant(2, info->args); + replicant_done_sem = create_sem(0, "NS Replicant created"); thread_id nsMainThread = spawn_thread(nsbeos_replicant_main_thread, "NetSurf Main Thread", B_NORMAL_PRIORITY, info); @@ -531,7 +539,8 @@ NSBaseView::Instantiate(BMessage *archive) return NULL; } resume_thread(nsMainThread); - while (acquire_sem(replicant_done_sem) == EINTR); + //XXX: deadlocks BeHappy + //while (acquire_sem(replicant_done_sem) == EINTR); return view; } @@ -650,12 +659,11 @@ NSBrowserWindow::WindowActivated(bool active) int32 nsbeos_replicant_main_thread(void *_arg) { struct replicant_thread_info *info = (struct replicant_thread_info *)_arg; - int32 ret; - ret = main(2, info->args); - //netsurf_main_loop(); - //netsurf_exit(); + int32 ret = 0; + + netsurf_main_loop(); + netsurf_exit(); delete info; - //release delete_sem(replicant_done_sem); return ret; } @@ -1761,7 +1769,7 @@ void BBitmapButton::SetBitmap(const char* attrname) { #ifdef __HAIKU__ size_t size = 0; - const void* data = BApplication::AppResources()->LoadResource('VICN', attrname, &size); + const void* data = gAppResources->LoadResource('VICN', attrname, &size); if (!data) { printf("CANT LOAD RESOURCE %s\n", attrname); -- cgit v1.2.3