Xamarin.Forms OpenGLView не работает при использовании внутри XAML-страницы - PullRequest
2 голосов
/ 05 июня 2019

Я попытался использовать простой пример, представленный здесь: https://docs.microsoft.com/en-us/dotnet/api/xamarin.forms.openglview?view=xamarin-forms, чтобы попытаться создать представление XAML с классом OpenGLView.Но я сталкиваюсь с проблемами.Это Xamarin.Forms (l, работает на iOS Simulator и использует платформу Prism, macOS Mojave и Visual Studio для Mac 2019 Pro.

Вот мой код XAML:

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage 
   xmlns="http://xamarin.com/schemas/2014/forms" 
   xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
   xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
   xmlns:otk="clr-namespace:OpenTK.Graphics.ES3"    
   x:Class="MyApp.Views.OpenGlPage">

   <StackLayout HorizontalOptions="CenterAndExpand" 
       VerticalOptions="CenterAndExpand">
       <OpenGLView x:Name="openGLView" HasRenderLoop="true"/>
       <Button Command="{Binding Display}" Text="Display"/>
   </StackLayout>
</ContentPage>

икод

using Xamarin.Forms;
using OpenTK.Graphics.ES30;

namespace MyApp.Views
{
    public partial class OpenGlPage : ContentPage
    {
        float red, green, blue;

        public OpenGlPage()
        {
            InitializeComponent();
            Title = "OpenGL";


            openGLView.HeightRequest = 300;
            openGLView.WidthRequest = 300;

            openGLView.OnDisplay = r => {

               GL.ClearColor(red, green, blue, 1.0f);
               GL.Clear((ClearBufferMask.ColorBufferBit | 
ClearBufferMask.DepthBufferBit));

               red += 0.01f;
               if (red >= 1.0f)
                  red -= 1.0f;
               green += 0.02f;
               if (green >= 1.0f)
                  green -= 1.0f;
               blue += 0.03f;
               if (blue >= 1.0f)
                  blue -= 1.0f;
           };
       }
   }
}

В ViewModel не так много, и представление правильно зарегистрировано в Prism, поэтому навигация к этому представлению работает нормально.

Но похоже, что есть какая-то проблемас тем, как OpenGL используется или инициализируется при отбрасывании в XAML, как это. Когда выполнение попадает в любой сбой приложения вызова GL. * Это ошибка:

=================================================================
    Native Crash Reporting
=================================================================
    Got a SIGSEGV while executing native code. This usually indicates
    a fatal error in the mono runtime or one of the native libraries 
    used by your application.
=================================================================

=================================================================
    Basic Fault Adddress Reporting
=================================================================
    instruction pointer is NULL, skip dumping
=================================================================
    Native stacktrace:
=================================================================
    0x10184704d - /Users/user/Library/Developer/CoreSimulator/Devices/602074EE-E100-4319-B9DE-D9460B6264EB/data/Containers/Bundle/Application/7937567A-2C4D-43A6-8A81-B27BFEF73EF6/Prism1.iOS.app/Prism1.iOS : mono_dump_native_crash_info
    0x10183b7a5 - /Users/user/Library/Developer/CoreSimulator/Devices/602074EE-E100-4319-B9DE-D9460B6264EB/data/Containers/Bundle/Application/7937567A-2C4D-43A6-8A81-B27BFEF73EF6/Prism1.iOS.app/Prism1.iOS : mono_handle_native_crash
    0x10184db43 - /Users/user/Library/Developer/CoreSimulator/Devices/602074EE-E100-4319-B9DE-D9460B6264EB/data/Containers/Bundle/Application/7937567A-2C4D-43A6-8A81-B27BFEF73EF6/Prism1.iOS.app/Prism1.iOS : mono_sigsegv_signal_handler
    0x10f329b5d - /usr/lib/system/libsystem_platform.dylib : _sigtramp
    0x18 - Unknown
    0x135d884bf - Unknown
    0x135d88927 - Unknown
    0x101850fa1 - /Users/user/Library/Developer/CoreSimulator/Devices/602074EE-E100-4319-B9DE-D9460B6264EB/data/Containers/Bundle/Application/7937567A-2C4D-43A6-8A81-B27BFEF73EF6/Prism1.iOS.app/Prism1.iOS : mono_jit_runtime_invoke
    0x10196ab78 - /Users/user/Library/Developer/CoreSimulator/Devices/602074EE-E100-4319-B9DE-D9460B6264EB/data/Containers/Bundle/Application/7937567A-2C4D-43A6-8A81-B27BFEF73EF6/Prism1.iOS.app/Prism1.iOS : mono_runtime_invoke_checked
    0x10196e4ce - /Users/user/Library/Developer/CoreSimulator/Devices/602074EE-E100-4319-B9DE-D9460B6264EB/data/Containers/Bundle/Application/7937567A-2C4D-43A6-8A81-B27BFEF73EF6/Prism1.iOS.app/Prism1.iOS : mono_runtime_invoke
    0x101a8142a - /Users/user/Library/Developer/CoreSimulator/Devices/602074EE-E100-4319-B9DE-D9460B6264EB/data/Containers/Bundle/Application/7937567A-2C4D-43A6-8A81-B27BFEF73EF6/Prism1.iOS.app/Prism1.iOS : xamarin_invoke_trampoline
    0x101a89365 - /Users/user/Library/Developer/CoreSimulator/Devices/602074EE-E100-4319-B9DE-D9460B6264EB/data/Containers/Bundle/Application/7937567A-2C4D-43A6-8A81-B27BFEF73EF6/Prism1.iOS.app/Prism1.iOS : xamarin_arch_trampoline
    0x101a8a761 - /Users/user/Library/Developer/CoreSimulator/Devices/602074EE-E100-4319-B9DE-D9460B6264EB/data/Containers/Bundle/Application/7937567A-2C4D-43A6-8A81-B27BFEF73EF6/Prism1.iOS.app/Prism1.iOS : xamarin_x86_64_common_trampoline
    0x1077a8ffd - /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/GLKit.framework/GLKit : -[GLKView _display:]
    0x112231c21 - /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/QuartzCore.framework/QuartzCore : -[CALayer display]
    0x112244003 - /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/QuartzCore.framework/QuartzCore : _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE
    0x1121b33aa - /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/QuartzCore.framework/QuartzCore : _ZN2CA7Context18commit_transactionEPNS_11TransactionE
    0x1121ea584 - /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/QuartzCore.framework/QuartzCore : _ZN2CA11Transaction6commitEv
    0x117924d8a - /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : _UIApplicationFlushRunLoopCATransactionIfTooLate
    0x117a17f5f - /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : __handleEventQueueInternal
    0x10242ebe1 - /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
    0x10242e463 - /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : __CFRunLoopDoSources0
    0x102428b1f - /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : __CFRunLoopRun
    0x102428302 - /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : CFRunLoopRunSpecific
    0x11249f2fe - /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/GraphicsServices.framework/GraphicsServices : GSEventRunModal
    0x11792aba2 - /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : UIApplicationMain
    0x134910932 - Unknown
    0x1349106c3 - Unknown

=================================================================
    Managed Stacktrace:
=================================================================
  at <unknown> <0xffffffff>
  at UIKit.UIApplication:UIApplicationMain <0x00211>
  at UIKit.UIApplication:Main <0x000b2>
  at UIKit.UIApplication:Main <0x00222>
  at Prism1.iOS.Application:Main <0x00092>
  at <Module>:runtime_invoke_void_object <0x00168>
=================================================================

Это происходит независимо от того, какой вызов GL у меня естьтам в обработчике OnDisplay. Если я удаляю вызовы GL, все работает, конечно, минус содержание OpenGL:)

Предупреждения компиляции: Compilation warnings

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...