Skip to content

Commit ad9fb61

Browse files
authored
Merge pull request #2120 from Unity-Technologies/unity-2022.3-main-mac-bundle-error-message
Add a more explicit error message on MacOS when dlOpen fails on Editor side
2 parents 6b38912 + 76aa238 commit ad9fb61

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

mono/metadata/native-library.c

+19-6
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,7 @@ legacy_probe_for_module_relative_directories (MonoImage *image, const char *file
11771177
}
11781178

11791179
static MonoDl *
1180-
legacy_probe_for_module (MonoImage *image, const char *new_scope)
1180+
legacy_probe_for_module (MonoImage *image, const char *new_scope, char **load_error)
11811181
{
11821182
char *full_name, *file_name;
11831183
char *error_msg = NULL;
@@ -1202,7 +1202,8 @@ legacy_probe_for_module (MonoImage *image, const char *new_scope)
12021202

12031203
if (mono_get_find_plugin_callback ())
12041204
{
1205-
const char* unity_new_scope = mono_get_find_plugin_callback () (new_scope);
1205+
gboolean hasError = FALSE;
1206+
const char* unity_new_scope = mono_get_find_plugin_callback () (new_scope, &hasError);
12061207
if (unity_new_scope == NULL || !unity_new_scope[0])
12071208
{
12081209
mono_trace (G_LOG_LEVEL_WARNING, MONO_TRACE_DLLIMPORT,
@@ -1212,6 +1213,9 @@ legacy_probe_for_module (MonoImage *image, const char *new_scope)
12121213

12131214
else
12141215
new_scope = g_strdup (unity_new_scope);
1216+
1217+
if (hasError)
1218+
*load_error = mono_dl_current_error_string ();
12151219
}
12161220

12171221
/*
@@ -1280,7 +1284,7 @@ legacy_probe_for_module (MonoImage *image, const char *new_scope)
12801284
}
12811285

12821286
static MonoDl *
1283-
legacy_lookup_native_library (MonoImage *image, const char *scope)
1287+
legacy_lookup_native_library (MonoImage *image, const char *scope, char **load_error)
12841288
{
12851289
MonoDl *module = NULL;
12861290
gboolean cached = FALSE;
@@ -1294,7 +1298,7 @@ legacy_lookup_native_library (MonoImage *image, const char *scope)
12941298
cached = TRUE;
12951299

12961300
if (!module)
1297-
module = legacy_probe_for_module (image, scope);
1301+
module = legacy_probe_for_module (image, scope, load_error);
12981302

12991303
if (module && !cached) {
13001304
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_DLLIMPORT,
@@ -1330,6 +1334,7 @@ lookup_pinvoke_call_impl (MonoMethod *method, MonoLookupPInvokeStatus *status_ou
13301334
const char *orig_scope = NULL;
13311335
const char *new_scope = NULL;
13321336
char *error_msg = NULL;
1337+
char *load_error = NULL;
13331338
MonoDl *module = NULL;
13341339
gpointer addr = NULL;
13351340

@@ -1427,7 +1432,7 @@ lookup_pinvoke_call_impl (MonoMethod *method, MonoLookupPInvokeStatus *status_ou
14271432
flags = 0;
14281433
module = netcore_lookup_native_library (alc, image, new_scope, flags);
14291434
#else
1430-
module = legacy_lookup_native_library (image, new_scope);
1435+
module = legacy_lookup_native_library (image, new_scope, &load_error);
14311436
#endif // ENABLE_NETCORE
14321437

14331438
if (!module) {
@@ -1436,7 +1441,14 @@ lookup_pinvoke_call_impl (MonoMethod *method, MonoLookupPInvokeStatus *status_ou
14361441
new_scope);
14371442

14381443
status_out->err_code = LOOKUP_PINVOKE_ERR_NO_LIB;
1439-
status_out->err_arg = g_strdup (new_scope);
1444+
if (load_error != NULL && load_error[0])
1445+
{
1446+
status_out->err_arg = g_strdup(load_error);
1447+
}
1448+
else
1449+
{
1450+
status_out->err_arg = g_strdup(new_scope);
1451+
}
14401452
goto exit;
14411453
}
14421454

@@ -1463,6 +1475,7 @@ lookup_pinvoke_call_impl (MonoMethod *method, MonoLookupPInvokeStatus *status_ou
14631475
g_free ((char *)new_import);
14641476
g_free ((char *)new_scope);
14651477
g_free (error_msg);
1478+
g_free (load_error);
14661479
return addr;
14671480
}
14681481

mono/metadata/unity-utils.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ MONO_API extern void burst_mono_update_tracking_pointers(MonoDomain* domain,Mono
7373
MONO_API gboolean
7474
unity_mono_method_is_generic (MonoMethod* method);
7575

76-
typedef const char*(*UnityFindPluginCallback)(const char*);
76+
typedef const char*(*UnityFindPluginCallback)(const char*, gboolean*);
7777

7878
MONO_API void
7979
mono_set_find_plugin_callback(UnityFindPluginCallback find);

0 commit comments

Comments
 (0)