From 2247275646669f318890ca40a5a953e86d24e828 Mon Sep 17 00:00:00 2001 From: bsupnik Date: Sun, 17 Nov 2013 22:55:03 -0500 Subject: [PATCH] bug fix for crash-on-quit with async load on 10.25 and earlier SDK - work around by not using async. also covers not using async on v9. --- src/XPMPMultiplayerCSL.cpp | 1 + src/XPMPMultiplayerObj8.cpp | 34 ++++++++++++++++++++++++++-------- src/XPMPMultiplayerObj8.h | 2 ++ 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/XPMPMultiplayerCSL.cpp b/src/XPMPMultiplayerCSL.cpp index 8dd88216b..0047050cb 100644 --- a/src/XPMPMultiplayerCSL.cpp +++ b/src/XPMPMultiplayerCSL.cpp @@ -256,6 +256,7 @@ static bool LoadOnePackage(const string& inPath, int pass); bool CSL_Init( const char* inTexturePath) { + obj_init(); bool ok = OBJ_Init(inTexturePath); if (!ok) XPLMDump() << "XSB WARNING: we failed to find XSB's custom lighting texture at " << inTexturePath << ".\n"; diff --git a/src/XPMPMultiplayerObj8.cpp b/src/XPMPMultiplayerObj8.cpp index af5405781..830cde013 100644 --- a/src/XPMPMultiplayerObj8.cpp +++ b/src/XPMPMultiplayerObj8.cpp @@ -24,13 +24,11 @@ #include "XPMPMultiplayerObj8.h" #include "XPMPMultiplayerVars.h" #include "XPLMScenery.h" +#include "XPLMUtilities.h" #include #include using namespace std; -#define WANT_ASYNC 1 - - struct one_inst { one_inst * next; @@ -52,6 +50,27 @@ struct one_obj { static one_obj * s_worklist = NULL; +static void (*XPLMLoadObjectAsync_p)( + const char * inPath, + XPLMObjectLoaded_f inCallback, + void * inRefcon)=NULL; + +void obj_init() +{ + int sim, xplm; + XPLMHostApplicationID app; + XPLMGetVersions(&sim,&xplm,&app); + // Ben says: we need the 2.10 SDK (e.g. X-Plane 10) to have async load at all. But we need 10.30 to pick up an SDK bug + // fix where async load crashes if we queue a second load before the first completes. So for users on 10.25, they get + // pauses. + if(sim >= 10300 && xplm >= 210) + { + XPLMLoadObjectAsync_p = (void (*)(const char *, XPLMObjectLoaded_f, void *)) XPLMFindSymbol("XPLMLoadObjectAsync"); + } +} + + + static void draw_objects_for_mode(one_obj * who, int want_translucent) { while(who) @@ -98,11 +117,10 @@ void obj_schedule_one_aircraft( if(model->handle == NULL && !model->file.empty()) { - #if WANT_ASYNC - XPLMLoadObjectAsync(model->file.c_str(),obj_loaded_cb,(void *) &model->handle); - #else - model->handle = XPLMLoadObject(model->file.c_str()); - #endif + if(XPLMLoadObjectAsync_p) + XPLMLoadObjectAsync_p(model->file.c_str(),obj_loaded_cb,(void *) &model->handle); + else + model->handle = XPLMLoadObject(model->file.c_str()); model->file.clear(); } diff --git a/src/XPMPMultiplayerObj8.h b/src/XPMPMultiplayerObj8.h index 7ee04519e..c78732275 100644 --- a/src/XPMPMultiplayerObj8.h +++ b/src/XPMPMultiplayerObj8.h @@ -59,6 +59,8 @@ struct obj_for_acf { struct CSLPlane_t; +void obj_init(); + bool obj_load_one_attached_obj( const char * file_name, bool needs_anim,