How can I troublehshoot _NSCoreDataOptimisticLockingException messages I am getting in the console? or debug it?
I am using background thread to update the core data context and the I am merging the context on the main thread with the main thread object, but I am geting these console message and I am unable to see where they are coming from.
objc[58487]: EXCEPTIONS: catch(_NSCoreDataOptimisticLockingException)
objc[58487]: EXCEPTIONS: unwinding through frame [ip=0x2235ec7 sp=0xb08e8a10] for exception 0x3dd42950
objc[58487]: EXCEPTIONS: unwinding through frame [ip=0x22622a6 sp=0xb08e8ad0] for exception 0x3dd42950
objc[58487]: EXCEPTIONS: handling exception 0x3dd42950 at 0x226234a
objc[58487]: EXCEPTIONS: finishing handler
The first answer from #jonusx talked about using nested contexts to handle this situations, but what can be done to debug these exceptions when targeting the iOS 4 SDK?
Thanks in advance.
That error comes from a change that can't be merged properly from two contexts. How exactly are you doing your background? You should try the new iOS 5 nested contexts for background saves. The parent can be in a private queue and the child (the background context) is in a thread confinement queue. Saves on the child are pushed up to the master context. After you're done in the background, just save the parent context to persist the changes to disk.
Related
I am getting the above mentioned exception in PointerPressed that too only in the case of MFC application hosted using XAML Islands. In normal UWP application it is working fine. Essentially no other Pointer events are fired in this scenario (Released, Canceled, CaptureLost,Exited etc) but we need to handle some UI changes in PointerReleased.
Kindly suggest any workarounds for the same.
I have a WebView in a Page that is used in a NavigationView. When I swicth to the corresponding tab the following exception is thrown:
Exception thrown at 0x75234662 (KernelBase.dll) in MyApp.exe: WinRT originate error - 0x8001010E : 'DispatcherQueueController is already created on this thread.'.
I determined it was the WebView that causes it through a process of elimination. It still occurs if I replace the xaml for the WebView with a sample from the docs. I.e.:
<WebView x:Name="webView1" Source="http://www.contoso.com"/>
Why is this happening? Might it cause problems? I found it while investigating occasional fatal exceptions from ucrtbase.dll. Might that be related?
When responding to an event in a textbox using C++/winrt I need to use ScrollViewer.ChangeView(). Trouble is, nothing happens when the call executes and I expect that is because at that moment the code is in the wrong thread; I have read this is the cause for lack of visible results from ChangeView(). It appears that the proper course is to use CoreDispatcher.RunAsync to update the scroller on the UI thread. The example code for this is provided only in C# and managed C++, however, and it is a tricky matter to figure out how this would look in normal C++. At any rate, I am not getting it. Does anyone have an example of the proper way to call a method on the UI thread in C++/winrt? Thanks.
[UPDATE:] I have found another method that seems to work, which I will show here, though I am still interested in an answer to the above. The other method is to create an IAsyncOperation that boils down to this:
IAsyncOperation<bool> ScrollIt(h,v, zoom){
co_await m_scroll_viewer.ChangeView(h,v,zoom);
}
The documentation entry Concurrency and asynchronous operations with C++/WinRT: Programming with thread affinity in mind explains, how to control, which thread runs certain code. This is particularly helpful in context of asynchronous functions.
C++/WinRT provides helpers winrt::resume_background() and winrt::resume_foreground(). co_await-ing either one switches to the respective thread (either a background thread, or the thread associated with the dispatcher of a control).
The following code illustrates the usage:
IAsyncOperation<bool> ScrollIt(h, v, zoom){
co_await winrt::resume_background();
// Do compute-bound work here.
// Switch to the foreground thread associated with m_scroll_viewer.
co_await winrt::resume_foreground(m_scroll_viewer.Dispatcher());
// Execute GUI-related code
m_scroll_viewer.ChangeView(h, v, zoom);
// Optionally switch back to a background thread.
// Return an appropriate value.
co_return {};
}
In my WinRT application running on an ARM tablet (ie Surface), I'm trying to get events from the accelerometer sensor but it's not working. I attach to it this way, basically from Microsoft's example:
mAccelerometer = Accelerometer::GetDefault();
mListenerToken = mAccelerometer->ReadingChanged::add(ref new TypedEventHandler<Accelerometer^, AccelerometerReadingChangedEventArgs^>(this, &AccelerometerWin8Delegate::ReadingChanged));
Unfortunately, this doesn't work. When an accelerometer event occurs, instead of getting my handler called, I get an error message in the output.
First-chance exception at 0x7539396B (KernelBase.dll) in EAMTestApp.exe: 0x40080202: WinRT transform error (parameters: 0x80004002, 0x00000000, 0x00000027, 0x04B1F280).
The exception is thrown in KernelBase.dll!7539396a()
Any idea what could be causing this? The error message is very cryptic.
I've run the Microsoft example here with no problems on the Surface.
Background
I'm using UKCrashReporter in my app.
I've installed my own Uncaught
Exception Handler.
I'm setting up the
managedObjectContext of the object
activeItemController in
applicationDidFinishLaunching (1)
The Problem
If the managedObjectContext method throws an exception, the crash reporter dialog box only flashes up before the app crashes and so the user never gets to report the crash.
I want my app to continue only after the crash has been reported, not whilst the window is showing.
What I've tried
If UKCrashReporterCheckForCrash()
were an objective C method, I assume
I could call
performSelectorOnMainThread:waitUntilDone:YES
but it's not.
I've looked at some other Stack
Overflow questions about using
Conditional Locks to pause apps,
but I can't understand how I'd use it
for a C function.
How would I go about doing this in a nice way? Do people have any advice
for me? Any responses would be much
appreciated.
The Code
// In app delegate
-(void)applicationWillFinishLaunching:(NSNotification *)aNotification {
UKCrashReporterCheckForCrash(); // A C function which then creates a window if
// it detects a crash has happened.
}
-(void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[activeItemController setMoContextDisk:[self managedObjectContext]];
[activeItemController setMoContextMemory:[self managedObjectContextMemory]];
}
Update 1
I've been asked for more details on what I'm trying to do, so here goes.
The bug that triggered this thinking was an exception when merging managedObjectModels. My app got caught in a loop printing "Uncaught exception" to the console every few milliseconds.
And when I installed the uncaught exception handler before this exception happened, I'd get the described behaviour - my app would fire up, display the crash report dialog briefly, then continue to load and crash again.
Summary - I want to be able to handle errors that happen on startup.
(1) I'm not using bindings to do this, as I thought bindings would make testing the class more problematic.
I think your problem is with thinking of it as "pausing" your app. Think of it more as a different initial UI state. Your attempts to block the run loop will prevent any interactive window from ... well, being interactive. :-)
Your best bet is to show your main UI (and connect data sources, etc) only if the "am I prompting the user to submit a crash report" method says "no, go ahead and start normally". Otherwise, show your window and, when the user sends or declines to send the report, close the window and ask your app controller to continue the normal startup.
I looked at UKCrashReporterCheckForCrash() and it doesn't appear to create a window of any kind. It merely submits the crash. Could you describe what you're doing with more detail?