Libgdx AndroidApplication native(?) crash - libgdx

I have a strange problem. I use a nightly from last week. If I recall correctly it's from 23/3.
What happens is that I run a Libgdx Activity and it runs fine. Than I finish the app. I start the libgdx activity again and it crashes... This happens a lot but not all the time.
In debug mode it doesn't happen at all. Any ideas? It doesn't print any crash log but I think it has something to do with this log: http://pastebin.com/3BFrjbES
My code doesn't do any thing special right now. It's just printing the FPS in a stage....
I think there is an error in the log that may be connected: EGL error: EGL_BAD_CONTEXT.
This is printed just before the previous log.
Thanks.

What does "finish the app" mean? A pause (pressing home) or a destroy?
I wonder if it is any way related to LibGDX attempting to preserve the EGL Context. The default for Android is to not preserve it but LibGDX attempts to enable it if you are on SDK >= 11. You could try to disable preservation in your AndroidApplication subclass by doing something like:
View view = ((AndroidGraphics)Gdx.graphics).getView();
try {
Method method = null;
for (Method m : view.getClass().getMethods()) {
if (m.getName().equals("setPreserveEGLContextOnPause")) {
method = m;
break;
}
}
if (method != null) {
method.invoke((GLSurfaceView20)view, false);
}
} catch (Exception e) {
}

I found out the problem. The problem disappeared after I removed hardwareAccelaration="true" from my application tag in the manifest. I don't know why it matters as my device is 4.0.4 which means that it's enabled by default.

Related

Can't Unlock Windows IOT Process after Debug

Trying to debug a Universal Windows app (MyTest) for Windows IOT using Local Machine. It starts the app but only displays the X screen, not my MainPage.xaml. OK, probably some bug I made. But I can't debug it and I can't unlock it. I try to put a breakpoint at App() constructor or OnLaunched and it never hits. If I Stop Debugging the X window stays up. Worse, if I kill the X window, using the window close (button in the top right), the app looks like it stops but the MyTest.exe remains locked, forever stopping me from trying to delete the exe, rebuild project, etc.
There is no MyTest app in the TaskManager (processes or details).
If I terminate ApplicationFrameHost process, the X screen will go away, but the MyTest.exe file remains locked as though the exe is still in use.
I've tried FileAssassin and it can't remove the lock.
The only thing that unlocks MyTest.exe is rebooting the machine...kind of a pain if you only get 1 debug run before rebooting the machine each time!
if you are using tasks you must terminate all.
example
BackgroundTaskDeferral _defferal;
public void Run(IBackgroundTaskInstance taskInstance)
{
_defferal = taskInstance.GetDeferral();
taskInstance.Canceled += TaskInstance_Canceled;
}
private void TaskInstance_Canceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason)
{
//a few reasons that you may be interested in.
switch (reason)
{
case BackgroundTaskCancellationReason.Abort:
//app unregistered background task (amoung other reasons).
break;
case BackgroundTaskCancellationReason.Terminating:
//system shutdown
break;
case BackgroundTaskCancellationReason.ConditionLoss:
break;
case BackgroundTaskCancellationReason.SystemPolicy:
break;
}
_defferal.Complete();
}
source: Windows 10 IOT Lifecycle (or: how to property terminate a background application)

Error -999 when loading multiple webViews

The iOS app I am making can have multiple webViews loading the same url at the same time. Resulting in this error:
Error Domain=NSURLErrorDomain Code=-999 "The operation couldn’t be completed.
(NSURLErrorDomain error -999.)" UserInfo=0x176b7bc0 {NSErrorFailingURLKey=https://example.com,
NSErrorFailingURLStringKey=https://example.com}
I read this happens when a new request is started before the old request has been completed. How do I prevent this from happening? Thanks
I spent weeks worrying about this error. I was getting it randomly while accessing web pages. In my case I put it down to pages being requested too quickly back to back as the web access was driven by a state machine in code and not by a user.
After much searching, in the end I found a few discussions which could not explain why the error was occuring, but it was felt that it was feature of UIWebView rather than something you should worry about. The guidance was to ignore it. I will see if I can find the article and update this answer later if I can find it.
I updated my code as follows, and so far have seen no ill effects at all since adding it. This would suggest it is almost a notification and anything which causes it seems to get corrected inside UIWebView. Hopefully this is the same in your case.
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
VSSLog(#"Entry: error = %#",error);
// Added this based on net advice. Its a bogus error.
if ([error code] == NSURLErrorCancelled) {
return;
}
... Normal error handling code for proper errors.
}
I am not one for out of sight out of mind, but this I believe is one of those cases where it is ok.
Finally if you are using iOS8 only, you could try moving to use the new WKWebView rather than UIWebView.
Use the delegate methods. Determine which view fired the method then fire the next if you're looking to run them sequentially.
- (void) webViewDidFinishLoad:(UIWebView *)webview{
if ( webview == self.wView1 )
{
// stuff
} else if ( webview == self.wView2 ) {
// stuff 2
}
}
UITableViewDelegate Protocol Reference

Windows Phone: playing a recorded sound throws exception

I am using an AudioVideoCaptureDevice to record some sound from the microphone. I want to give the user feedback on what he recorded so I want to be able to play it.
When putting that sound into a Song and playing it via Microsoft.Xna.Framework.Media.MediaPlayer, I am getting an exception:
{System.InvalidOperationException: Song playback failed.
Please verify that the song is not DRM protected.
DRM protected songs are not supported for creator games.
---> System.InvalidOperationException: An unexpected error has occurred.
--- End of inner exception stack trace ---
at Microsoft.Xna.Framework.Media.MediaQueue.Play(Song song)}
Looking into the details of the song in the watch, the IsProtected() seems to cause issues. (If playback works, I get correctly that the song is not protected.) I am using AAC and ACM codecs, both give same results.
I can play the song after closing and opening the view again, but have not found any related initialization that would explain this.
I also tried copying the file, in case some process was still holding a lock on it, still, there is no improvement, same with isolated storage.
After not closing app but re-entering view the song plays without problems.
How can I directly play the recorded audio without any problems?
I used the AudioRecorder sample from http://independentinnovation.net/blogs/independentinnovation/archive/2012/12/11/Windows-Phone-8-Audio-Recording-using-Windows.Phone.Media.Capture.aspx .
(Note: right now this link is not working, domain expired.. anyway, I used someone else's code.)
It turns out, that in the Record() function, a stream is opened, that in the Stop() function is never properly flushed and disposed.
I don't understand how this could have caused the problem, since I did copy the resulting file, just to make sure that all handles are valid.
Still, old handling was definitely wrong and new handling is a lot cleaner, and, btw, works.
public async void StopRecording()
{
try
{
if (dev != null)
{
await dev.StopRecordingAsync();
dev = null;
// these 2 lines I had to add
await recordingStream.FlushAsync();
recordingStream.Dispose();
}
var length = new System.IO.FileInfo(fileName).Length;
System.Diagnostics.Debug.WriteLine("Recorded " + fileName + " with length " + length);
}
catch (System.Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
}
}
edit: to give credits, I found the answer I used here http://www.postseek.com/meta/9fddd403d0cde523a542be42b7a4b057

Appwarp fails to re-connect after user disconnects from the server (using cocos2d-x)

I am trying to work through connection issues at this stage of the app writing process. When the user leaves the game board, I call ...
void HelloWorld::onExit()
{
isMultiPlayer = CCUserDefault::sharedUserDefault()->getBoolForKey("MULTIPLAYER", false);
if(isMultiPlayer)
{
AppWarp::Client::getInstance()->disconnect();
CCUserDefault::sharedUserDefault()->setBoolForKey("MULTIPLAYER", false);
}
CCDirector::sharedDirector()->getTouchDispatcher()->removeDelegate(this);
CCLayer::onExit();
}
From here, if I try to re-join the lobby, I get a
onConnectDone .. FAILED with unknown reason..session=0
Error in my log file. It seems like I need to wait around 5 minutes or so before this error disappears. Am I doing something wrong with my disconnect code, or is this kind of behavior the norm?
#PWiggin - this issue has now been fixed in our SDK update. You can pick the latest release from our GIT repo. Here is the link
https://github.com/shephertz/AppWarpCocos2DX/tree/master/V_1.5.1

AIR UrlMonitor doesn't dispatch StatusEvent.STATUS

As the title says, I've got a air.net.URLMonitor that sometimes doesn't dispatch a StatusEvent in case the specified site cannot be reached.
Let me show you my code:
_serverURL = "http://192.168.0.20:8080/"
_monitor = new URLMonitor(new URLRequest(_serverURL));
_monitor.pollInterval = 1000;
_monitor.addEventListener(StatusEvent.STATUS, serverStatusResult);
_monitor.start();
And here is my problem, when my iPad (this is a mobile AIR application btw) is in the correct network, so the one where the specified server is available, the StatusEvent is correctly dispatched. When I'm not in that network, nothing happens and I really don't know why.
Shouldn't it dispatch the event anyway?
This isn't an isolated issue, when our production environment server gets updated and isn't online, the same issue appears, however when the iPad is in offline mode and cannot reach the server because of that, the StatusEvent fires.
Is there a reasonable explanation for that, and if so, how can I correctly implement this?
Should I use a standard HTTPService instead and simply listen for ResultEvent and FaultEvent?
As usual, any help would be greatly appreciated!
Cheers.
What do you have in your serverStatusResult function?
Something like:
public function serverStatusResult(e:StatusEvent):void {
if (! monitor.available) {
//connection has dropped so do something
}
}
I also found that setting a poll interval has a very detrimental effect on iPad CPU usage.
The solution is very simple:
StatusEvent has a parameter called code.
Variable code is a string and it can be :
"Service.available"
"Service.unavailable"
Ok, now let's see an implementation:
public function serverStatusResult(e:StatusEvent):void {
switch(e.code)
{
case "Service.available":online();break;
case "Service.unavailable":offline();break;
}
}
Hope it helps :)