I was following the advice from Stuart on MVVMCross iOS: how to bind a command with Custom transition when switching to different View model
When I switch to using my custom presenter derived from MvxModalNavSupportTouchViewPresenter then my app crashes (System.NullReferenceException: Object reference not set to an instance of an object) in AppDelegate::FinishedLaunching when calling .Start():
IMvxAppStart startup = Mvx.Resolve<IMvxAppStart>();
startup.Start();
Callstack is:
0x7 in Cirrious.MvvmCross.Touch.Views.Presenters.MvxTouchViewPresenter.get_CurrentTopViewController C#
0x2 in Cirrious.MvvmCross.Touch.Views.Presenters.MvxTouchViewPresenter.PresentModalViewController C#
0x4E in Cirrious.MvvmCross.Touch.Views.Presenters.MvxModalNavSupportTouchViewPresenter.Show C#
0xB in Cirrious.MvvmCross.Touch.Views.Presenters.MvxTouchViewPresenter.Show C#
0x28 in Cirrious.MvvmCross.Touch.Views.MvxTouchViewDispatcher. C#
0x28 in Cirrious.MvvmCross.Touch.Views.MvxTouchUIThreadDispatcher.RequestMainThreadAction C#
0x24 in Cirrious.MvvmCross.Touch.Views.MvxTouchViewDispatcher.ShowViewModel C#
0x30 in Cirrious.MvvmCross.ViewModels.MvxNavigatingObject.ShowViewModelImpl C#
0x6 in Cirrious.MvvmCross.ViewModels.MvxNavigatingObject.ShowViewModel C#
0xE in Cirrious.MvvmCross.ViewModels.MvxNavigatingObject.ShowViewModel<TestCustomPresenter.Core.ViewModels.FirstViewModel> C#
0x17 in Cirrious.MvvmCross.ViewModels.MvxAppStart<TestCustomPresenter.Core.ViewModels.FirstViewModel>.Start C#
> 0x3A in TestCustomPresenter.iOS.AppDelegate.FinishedLaunching at e:\Src\test\TestCustomPresenter\TestCustomPresenter.iOS\AppDelegate.cs:54 C#
0x9F in MonoTouch.UIKit.UIApplication.UIApplicationMain C#
0x52 in MonoTouch.UIKit.UIApplication.Main at /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38 C#
0x8 in TestCustomPresenter.iOS.Application.Main at e:\Src\test\TestCustomPresenter\TestCustomPresenter.iOS\Main.cs:23 C#
As far as I can tell, there is no current top view controller but I don't know how to set that up as I followed all the steps from Stuart's answer. ( I couldn't reply to his answer as I have 9 rep too few :( )
I've uploaded a test project that reproduces the error to http://www.cliffcawley.net/TestCustomPresenter.zip
What do I have to do to get the example to work and to see the custom transition when you click the button?
A modal view controller is shown on top of something else. See https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html
I haven't downloaded your sample, but from your stack trace my guess is you are showing the modal as your first view - so there's nothing to show it on top of.
An easy solution for this is to try showing another view first - even if it's just a placeholder or backdrop.
Beyond the easy solution, if you are new to uikit, it's worth taking some time to hack a demo app (non-mvx) where you experiment with pushing and popping viewcontrollers as modals, within navigationcontrollers, etc - once you get comfortable with this, then you can quickly write your own navigation/presentation logic in any mvx app.
Related
I am working on a DirectX 11 app and I am having difficulties creating an instance of IDXGIFactory7. I could not find a CreateDXGIFactory7() function so I am using CreateDXGIFactory2() like this:
IDXGIFactory7* factory;
HRESULT hr = ::CreateDXGIFactory2(DXGI_CREATE_FACTORY_DEBUG, __uuidof(IDXGIFactory7), (void**)&factory);
The difficulty I am having is that this call throws an exception when attempting to use the graphics debugger in Visual Studio 2019. I also tried IDXGIFactory6 which also throws an exception. If I change it to IDXGIFactory2 it works and I can use the graphics debugger.
This code does run and debug fine using the regular debugger, but not the graphics debugger. I get the following exception:
Exception thrown at 0x00007FFAE1513B29 in DirectXTemplated.exe: Microsoft C++ exception: GRFXTool::ToolException at memory location 0x0000004D28BFE010.
I downloaded the sample from https://www.3dgep.com/introduction-to-directx-11/ and modified it to use IDXGIFactory7 and CreateDXGIFactory2() instead of IDXGIFactory in the QueryRefreshRate() function. You will need to set g_EnableVSync = TRUE at the top of main.cpp for it to create the factory. This does generate the exception when attempting to use the graphics debugger.
This is a Windows 10 Pro x64 installation with Visual Studio v16.7.6.
Based on the comment from Roman R., the way to get around the problem seems to be to use CreateDXGIFactory2() to create an IDXGIFactory2 and use QueryInterface() on that to obtain the one for IDXGIFactory7.
Doing it this way avoids the exception and the app runs under the graphics debugger without issue.
I want to create an application using Xamarin.Forms. I have created a single content page and added a DatePicker Control over it.
The first time the activity is started, date picker work just fine ... however, whenwe close the application via mobile back button and relaunch the app it throws an un-handled exception on opening date picker saying this exception:
0x21 in System.Diagnostics.Debugger.Mono_UnhandledException_internal C#
0x1 in System.Diagnostics.Debugger.Mono_UnhandledException C#
0x26 in object.56027ba0-2dd5-40f3-bfa1-daf5399d2134 C#
0x63 in Android.Runtime.JNIEnv.CallVoidMethod at /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/b5dc5ce9/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:490,138 C#
0x4E in Android.App.Dialog.Show at /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/b5dc5ce9/source/monodroid/src/Mono.Android/platforms/android-19/src/generated/Android.App.Dialog.cs:2497,5 C#
0x73 in Xamarin.Forms.Platform.Android.DatePickerRenderer.OnTextFieldClicked C#
0xB in Xamarin.Forms.Platform.Android.DatePickerRenderer.TextFieldClickHandler.OnClick C#
0x13 in Android.Views.View.IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ at /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/b5dc5ce9/source/monodroid/src/Mono.Android/platforms/android-19/src/generated/Android.Views.View.cs:1840,1223 C#
0x17 in object.56027ba0-2dd5-40f3-bfa1-daf5399d2134 C#
If you're using older Xamarin.Forms version it could be a bug: Take a look at possible fix: bugzilla.xamarin.com/show_bug.cgi?id=24773 (first comment)
I am using the Redpark Serial SDK 1.4 r270 to help with i/o features for the iphone. One of the issues, that I am currently having is reading the data given using
- (void) readBytesAvailable:(UInt32)numBytes {
Here are my errors.
Feb 8 15:27:50 iapd[897] <Warning>: ERROR - /SourceCache/iapd/iapd-1065.23/iapd/IAPSession.mm:-[IAPSessionBasic _sessionBufferToAppHasSpaceAvailable] - 823 session=0x1 for connectionID=0x1e12ea00 failed to write bytes, errno = 32
Feb 8 15:27:50 iOS[7428] <Warning>: ERROR - /SourceCache/ExternalAccessory/ExternalAccessory-213/EASession.m:-[EASession dealloc] - 137 unable to close session for _accessory=0x20047eb0 and sessionID=65536
Feb 8 15:27:50 iOS[7428] <Warning>: ERROR - /SourceCache/ExternalAccessory/ExternalAccessory-213/EAOutputStream.m:-[EAOutputStream write:maxLength:] - 212 failed to write 229 bytes (wrote -1) with error 9
Feb 8 15:27:50 iOS[7428] <Warning>: ERROR - /SourceCache/ExternalAccessory/ExternalAccessory-213/EAInputStream.m:-[EAInputStream _readInputFromAccThread] - 357 error waiting for read data, errno = 9
This works perfectly works fine with a single view application.
Suppose there is a UINavigationController with view A and view B where A => B when a button is clicked. View B is using the RscMgr thread where all the magic happens to read from the serial port.
At the first instance of the UINavigationController at view B, it works perfectly fine if we stay on this view. We are able to disconnect, connect the port and we will continue streaming the data.
However, if I go back to view A then back to view B. Everything goes to hell. I cannot read the data anymore from this function, and I found (MULTIPLE) errors in the console. Does anyone have a good reason as to why this happened and how we can fix it? I know we have popped the UIViewController off the stack and everything resets and the RscMgr thread is created again but nothing is being viewed. I am unsure on how to clear the buffer using the SDK since it is not provided.
This is simpler than the solution above. Define your function in a different .m file, and have this launch from AppDelegate, not the ViewController.
I had this issue with former apps I wrote. The other option is to declare RscMgr in App Delegate, but then have it initialized in the given ViewController.
The scope you've declared
- (void) readBytesAvailable:(UInt32)numBytes {
in is likely the problem. I would declare this somewhere that does not go away when you open and close B. Such as on the UINavigationController, or on your AppDelegate.
Better yet, create a new singleton class that manages the interface to RedPark, and query it from the rest of your app as needed.
I was wondering if anyone has had a similar experience. I am trying to trace the source of a problem but am coming up with nil. I have a project in Delphi 5 which has Report Builder reports on it. I needed an upgraded version of reportbuilder so I tried running the project in Delphi 7. When my project runs and I click a button to view a report, it views fine. However, if I use a paramstr to run the report (showmainform is set false) and show report procedure runs, I get get a stack overflow error.
The original code was :
if lowercase(ParamStr(1)) = 'termsexceeded' then begin
reportsdata.termsexceeded.close;
reportsdata.termsexceeded.open;
reports.ppTermsExceeded.print;
reportsdata.termsexceeded.close;
application.terminate;
end;
And it gave me the stack overflow error on the .print function.
The code that works in Delphi 7 is :
if lowercase(ParamStr(1)) = 'termsexceeded' then begin
reportsdata.termsexceeded.close;
reportsdata.termsexceeded.open;
reports.left := -10000;
reports.show;
reports.ppTermsExceeded.print;
reportsdata.termsexceeded.close;
application.terminate;
end;
Has anybody got a suggestion on how I could debug this to see if the problem lies with my Delphi 7 or with Reportbuilder ?
There are no events on the .show event of the reports form.
Any advice on how to get to the bottom of this would be appreciated.
Regards
When you get a stack overflow, use the debugger. It will interrupt your program when the OS throws the exception, and at that time, you can use the debugger's call stack window to see the path a function calls that lead there. You'll probably see a certain function or sequence of functions repeated many times.
When you've found the repeating pattern, check the code to see why it's repeating. Look for a condition is supposed to have changed, but doesn't.
I get a strange crash when using the new PageCurl effect reading a PDF with MonoTouch and iOS 5.0.
I've made a simple test case project for MonoDevelop 2.8 and uploaded on GitHub here:
https://github.com/Emasoft/IpaziaPDFReader
It seems that something is getting GCd too early and killing the application, but I can't find what. I've tried to dispose everything in many ways, but in vain. I've already submitted the project tarball to the Xamarin team, but they weren't able to solve the problem.
Is there something broken in the iOS NavigationController memory management? Or am I missing something?
Any help is appreciated, thanks!
UPDATE: I've tried to remove all subviews and sublayers before disposing the objects in all classes, but it still crashing. The only way I found to avoid the crash is to NEVER dispose of the PDF pages, adding them to a List before releasing them, but this is not a viable solution, because in that way memory is consumed rapidly for PDF with many pages and the app crashes anyway when unable to allocate memory for the next page.
Another way to avoid the crashes is to dispose of the PDF pages BEFORE turning the pages, forcing the dispose method on the page controller before creating a new page controller, but in this way the current page will become blank and the transition curls an useless empty page. No solution seems to work.
I've updated project on GitHub with the 3 different solutions I've tried (look in the PageDataSource class), you can uncomment them one at time to see the problems.
//SOLUTION 1
void ForcingPageControllerDispose (BookPageController oldPageController)
{
// --- IF YOU UNCOMMENT THIS, THE CRASHES GO AWAY, BUT THE PAGE IN THE TRANSITION IS BLANK, SO IS NOT VIABLE
currentPageController.View.RemoveFromSuperview ();
currentPageController.Dispose ();
}
//SOLUTION 2
void DisposeThePageControllerWhenDidFinishAnimating (BookPageController oldPageController, UIPageViewController pageViewController)
{
// --- IF YOU UNCOMMENT THIS, THE CRASHES STILL HAPPEN
pageViewController.DidFinishAnimating += delegate(object sender, UIPageViewFinishedAnimationEventArgs e) {
if (currentPageController != null) {
currentPageController.View.RemoveFromSuperview ();
currentPageController.Dispose ();
Console.WriteLine ("currentPageController disposed for page: " + currentPageController.PageIndex);
}
};
}
//SOLUTION 3
void BackupUnusedPagesToAvoidBeingGCd (BookPageController oldPageController)
{
// --- IF YOU UNCOMMENT THIS, THE CRASHES GO AWAY, BUT THE PAGES ARE NOT GARBAGE COLLECTED AND AFTER MANY PAGES IPHONE IS OUT OF MEMORY AND IT CRASHES THE APP
if (parentController.book_page_controllers_reference_list.Contains (currentPageController) == false)
parentController.book_page_controllers_reference_list.Add (currentPageController);
}
I've already submitted the project tarball to the Xamarin team, but they weren't able to solve the problem.
I'm pretty sure the person assigned to your case will come up with the solution. The bigger the test case the more time it can take.
From a quick view the following, in your AppDelegate.cs, is wrong:
PageTurnViewController viewController = new PageTurnViewController ("PageTurnViewController", null);
window.AddSubview (viewController.View);
since the local viewController instance won't have any reference to it once FinishedLaunching returns and the GC will be able to collect it. However it's needed (on the native side) for keep the View fully valid. This can lead to crashes (there could be other cases too, that's the first and only file I checked this morning).
The solution is to promote the viewController to a field. That will make it alive even when the method returns, making it unavailable to collection.
UPDATE
I had a quick look at your code on github.
You are adding (sub)view but you never remove them (when the GC will Dispose them it won't remove them from the super view);
You are losing references to views, e.g. in PageDataSource.cs
newPageController = new BookPageController (nextPageIndex, parentController.currentPDFdocument, parentController);
return newPageController;
After the first page there will already be a reference stored in newPageController which will be overwritten and make the object collectable bug the GC. Since (sub)views are never removed there could still be native reference to them leading to crashes.
For debugging you can add your own finalizers, e.g.
~BookPageController ()
{
Console.WriteLine ("bu-bye");
}
and put breakpoints in them. If they get hit, while you think it's still in use, then you likely found a problem.
Since you are taking a dependency on iOS 5 new features, you should also adopt the new View Controller Containment APIs in iOS 5 that solve a few problems with view controllers.
I suggest you check the WWDC Video and slides for for Session 102 "Implement UIViewController Containment".