Skip to content

Commit 4b1f6fc

Browse files
committed
Passing detailed reason for image load failure back to the unity editor via callback.
1 parent 226a895 commit 4b1f6fc

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

mono/metadata/image.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1345,7 +1345,10 @@ do_mono_image_load (MonoImage *image, MonoImageOpenStatus *status,
13451345
invalid_image:
13461346
if (errors) {
13471347
MonoVerifyInfo *info = (MonoVerifyInfo *)errors->data;
1348-
g_warning ("Could not load image %s due to %s", image->name, info->message);
1348+
char* log_message = g_strdup_printf("Could not load image %s due to %s\nRun the peverify utility against this for more information.", image->name, info->message);
1349+
if (!mono_unity_log_error_to_editor(log_message))
1350+
g_warning (log_message);
1351+
g_free(log_message);
13491352
mono_free_verify_list (errors);
13501353
}
13511354
MONO_PROFILER_RAISE (image_failed, (image));

mono/metadata/unity-utils.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,23 @@ MONO_API int mono_unity_gc_is_disabled()
976976
#endif
977977
}
978978

979+
// Logging
980+
static UnityLogErrorCallback editorLoggingCallback;
981+
MONO_API void mono_unity_set_editor_logging_callback(UnityLogErrorCallback callback)
982+
{
983+
editorLoggingCallback = callback;
984+
}
985+
986+
gboolean mono_unity_log_error_to_editor(const char *message)
987+
{
988+
if (editorLoggingCallback)
989+
{
990+
editorLoggingCallback(message);
991+
return TRUE;
992+
}
993+
return FALSE;
994+
}
995+
979996
MONO_API void
980997
mono_unity_install_unitytls_interface(unitytls_interface_struct* callbacks)
981998
{

mono/metadata/unity-utils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ MONO_API void mono_unity_gc_disable();
169169
// Deprecated. Remove when Unity has switched to mono_unity_gc_set_mode
170170
MONO_API int mono_unity_gc_is_disabled();
171171

172+
// logging
173+
typedef void (*UnityLogErrorCallback) (const char *message);
174+
MONO_API void mono_unity_set_editor_logging_callback(UnityLogErrorCallback callback);
175+
gboolean mono_unity_log_error_to_editor(const char *message);
172176

173177
//misc
174178
MonoAssembly* mono_unity_assembly_get_mscorlib();

0 commit comments

Comments
 (0)