Storyboard instantiateWithIdentifier cause crash on iOS 13 - uiviewcontroller

Testing my app in Xcode 11 (beta) for iOS-13 (beta) updates and I'm getting crash on when I tried to instantiate viewController from storyboard.
In previous versions its working fine with the following code:
XYZController *controller = [self.storyboard instantiateViewControllerWithIdentifier:#"IDENTIFIER"];
Now for iOS 13 Apple introduces new method i.e.
XYZController *controller = [self.storyboard instantiateViewControllerWithIdentifier:#"IDENTIFIER" creator:^__Kindof UIViewController *__Nullable(NSCoder *_Nonnull coder){
return [XYZController alloc] initWithCoder:coder];
}];
Executing both method in iOS-13 cause crash. While crash shows somewhere else.
Here is my crash report.
Terminating app due to uncaught exception
'NSInternalInconsistencyException', reason:
'' returned nil from -traitCollection, which
is not allowed.

Note: Temporary Solution
I also have face this issue and there are two temporary fixes I have found. First is to create object/property of the controller that need to be instantiate and instantiateViewControllerWithIdentifier in your controllers's viewDidLoad. App will not crash.
Second is to instantiate controller in dispatch_async(dispatch_get_main_queue()). These both tricks worked for me.

Related

SSRS ReportViewer nullreference exception on Disposing

We're currently using a Windows Service to generate PDF files. I was recently optimizing the code and noticed the abusive use of memory. This was caused by the lack of a using statement around var reportViewer = new ReportViewer()
However, after adding this the code threw a runtime nullreference exception after closing the using block, the code originating in the internal Dispose method.
Why does this error occur and how can I dispose the object properly?
The answer, as can be found in Visual Basic here is because for some reason the ReportViewer expects a HttpContext. If none is present, this error will occur.
As a workaround the following lines can be added to resolve the issue:
if (System.Web.HttpContext.Current == null)
{
System.Web.HttpContext.Current = new System.Web.HttpContext(
new System.Web.HttpRequest(System.IO.Path.GetRandomFileName(), "https://www.stackoverflow.com", string.Empty),
new System.Web.HttpResponse(System.IO.TextWriter.Null)
);
}
This will create a fake HttpContext, allowing somehow to dispose the ReportViewer instance properly.

Xamarin.Android no stack trace in async method

Anybody maybe found some workaround for this bug:
https://bugzilla.xamarin.com/show_bug.cgi?id=30513
?
It drives me crazy... the screenshoot is the exception report I got from async method.
Here is another one solution which worked for me.
Just add this handler in your Application or main Activity
AndroidEnvironment.UnhandledExceptionRaiser += delegate(object sender, RaiseThrowableEventArgs args){
typeof (System.Exception).GetField("stack_trace", BindingFlags.NonPublic | BindingFlags.Instance)
.SetValue(args.Exception, null);
throw args.Exception;
};
The explanation is here in the last post https://forums.xamarin.com/discussion/45219/stack-trace-not-captured-properly
Okey guys, so I have found workaround for this bug, here is step by step what to do to handle it and let Xamarin.Insights work.
Add text file to Android project(name doesn't matter)and set it
from "Content" in properties to "AndroidEnvironment"
In the text file you created add that flag:
XA_BROKEN_EXCEPTION_TRANSITIONS=true - this flag mean that we will use old, Xamarin.Android 4.x exception handling
Then add android exception global handler in your droid project, it will handle Android exceptions which normally crashes application before your Xamarin.Insights(or other report tool)would be able to do some work.
AndroidEnvironment.UnhandledExceptionRaiser += (sender, args) =>
{
args.Handled = true;
}
And voila, the Xamarin.Insights is ready to work for you :)

how to resolve stringIndexOutofBoundsException when bitmap is initialized

I am learning to develop a game using libgdix.I follow the book Learning LibGDX game development,second edition.
I am getting stuck on using Bitmapfont.
public class AssetsFonts
{
public final BitmapFont defaultSmall;
public final BitmapFont defaultNormal;
public final BitmapFont defaultBig;
public AssetsFonts()
{
defaultSmall = new BitmapFont(Gdx.files.internal("images/arial-15.fnt"),true);
defaultNormal = new BitmapFont(Gdx.files.internal("images/arial-15.fnt"),true);
defaultBig = new BitmapFont(Gdx.files.internal("images/arial-15.fnt"),true);
defaultSmall.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
defaultNormal.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
defaultBig.getRegion().getTexture().setFilter(TextureFilter.Linear,TextureFilter.Linear);
}
}
when i run this am getting the following error
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Error loading font file: images/arial-15.fnt
at com.badlogic.gdx.graphics.g2d.BitmapFont$BitmapFontData.load(BitmapFont.java:650)
at com.badlogic.gdx.graphics.g2d.BitmapFont$BitmapFontData.<init>(BitmapFont.java:465)
at com.badlogic.gdx.graphics.g2d.BitmapFont.<init>(BitmapFont.java:115)
at com.packtpub.libgdx.canyonbunny.game.Assets$AssetsFonts.<init>(Assets.java:125)
at com.packtpub.libgdx.canyonbunny.game.Assets.init(Assets.java:49)
at com.packtpub.libgdx.canyonbunny.CanyonBunnyMain.create(CanyonBunnyMain.java:22)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:143)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:120)
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -7
at java.lang.String.substring(String.java:1918)
at com.badlogic.gdx.graphics.g2d.BitmapFont$BitmapFontData.load(BitmapFont.java:476)
... 7 more
The exception you've got is this one. Practically saying that something went wrong while loading the file. The inner exception shows what went wrong while loading:
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -7
at java.lang.String.substring(String.java:1918)
at com.badlogic.gdx.graphics.g2d.BitmapFont$BitmapFontData.load(BitmapFont.java:476)
Since there's no call to String#substring at line 476, this is an indication that you're using an older version of libgdx (which is to be expected, because a lot has changed to that file recently). So I'd suggest that you update to the latest nightly (or check the github history at the time of the version you're using), so you know which call is actually causing the error.
Either way, the fact that a substring call failed while loading your file is a good indication that the file is likely to be corrupt or doesnt meet the expected format in another way. Assuming you want to use the font that the libgdx tests uses, then you can download the correct version here and the required image here. Make sure to place the image in the same folder as the fnt file.
Your real problem is that it can't find the font file...
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Error loading font file: images/arial-15.fnt
Make sure the file is in the correct place, which is probably android/assets/images but depends on your project setup.
Also ensure that your run the desktop version with android/assets as the working folder.

iOS 8- viewController my_shouldAutorotate crash while presentViewController

i am using Uinavigationcontroller as windows root view controller. IN some otherview i am presentingviewcontroller but my app is crashing in iOS 8.It was working perfect in ios7. It says
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
'-[InfoVC my_shouldAutorotate]: unrecognized selector sent to instance 0x15cd42780'.
where InfoVC is viewcontroller. what is my_shouldAutorotate
In your InfoVC class write following method:
-(BOOL)shouldAutorotate{ return NO; }

libc++abi.dylib: terminate_handler unexpectedly threw an exception - 0 stack trace iOS7 / iOS 8

Randomly (that's why I ask the question), my application crashes when want to display data into textView.
The only error message I've got in my debug console is :
libc++abi.dylib: terminate_handler unexpectedly threw an exception
I Googled but can't get a clue to find how correct this and how this happens.
I got the same error and a "clean" didn't resolve it.
It was caused by my internet testing flow, I check to see if WiFi is connected but not if that WiFi has an active internet connection that can resolve a supplied URL. It performs a dataWithContentsOfURL: that will ultimately fail. A similar thread made this suggestion to this question here by user Keith that helped me identify the problem -- which was to add breakpoints to C++ exceptions.
To enable -- click your breakpoints view and the very bottom click the '+' to add a breakpoint. Set it up as follows and the stack trance will be more meaningful.
Clean the project.
Check each constraints and remove the corrupted one.
Clean project again, it should works.
This can be caused by an outlet that is no longer existing (might have been renamed or removed).
Here is a tip on how to check outlets:
Select the container view of the suspected outlet, pay attention to "!" marks in the connections inspector.
I got this question ,because I set [self addObserver:self forKeyPath:#"_defaultAgType" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil];, but I did not remove it in dealloc. I solved this by [self removeObserver:self forKeyPath:#"_defaultAgType"]; in dealloc function.
Another reason why it could happen is when you have a UI element declared but never added to the screen but still you try to do changes on them.
In my case I had a UIBarButtonItem declared in the code but I never added it to View. When I try to remove it without adding it, I had this issue.
If you renamed/moved your view controller class, make sure you've checked Inherit Module From Target on Identity inspector for your scene on the storyboard