LibGDX on resume function - opengl-es

I have issues with OpenGL ES context loss under LibGDX, so I'm trying to figure out how to solve the problem. My first step was to actually re-initialize all my textures when the resume function is called in one my classes that extends Screen. Like this:
#Override
public void resume() {
Tile.initTiles();
}
The resume function re-creates all my tiles (including their textures), so I thought this would work. However, according to the documentation:
ApplicationListener Docs
The resume function should never be called on a desktop. Now, resume is never called on my Android phone, but on my desktop I tell the program to print "true" to the console in the resume method, and voila, the resume function is actually called on the desktop.
My main questions are:
Why would the resume function be called on my desktop but not on my Android phone?
How can I reload my textures on resume for my Android phone? Currently my textures are white on resuming the game after hitting the back key. Interestingly enough the textures reload fine when exiting through the home button.

I'll quickly explain how I do it, and for me it worked out so far without problems on both desktop and Android.
First of all I use an AssetManager for all my assets, including Texture. I usually load all my assets before entering the actual gameplay screen via a loading screen. But it should also work when you load them in your Screen.show() method.
Whenever I need an asset, the only way I retrieve them is via AssetManager.get(...). My AssetManager is actually a public static member of the base game class, so it can be accessed from anywhere in my code and there is only a single one of them.
In my Screen.resume() method I put an AssetManager.finishLoading(), though I'm not sure this is really necessary.
Right after the game starts and your AssetManager is instantiated, I call the static method Texture.setAssetManager(...).
This closes the circle. When on Android your OGL context is lost, LibGDX will actually revive it for you. Since you've set the AssetManager for your Textures, the manager will be able to find the textures after they have been reloaded. The AssetManager.finishLoading() will wait until the reloading has been finished. After that, everything should work as before the context loss.
Why Screen.resume() is not called, I cannot say. For me it is called on Android. Maybe you need to update your LibGDX version.

Related

Allow off-screen touches with TouchInjection windows 8+ api?

I have a situation where I need to embed some 3rd party closed-source Unity applications into our own. I'm injecting a DLL which creates a DX11 shared texture from their swapchain. This part works and it's done.
Additionally I want to hide the form wrapping the Unity app (you can set their parent handle with a command line luckily) so I can have 100% control what happens to its texture in our own app (+ so it wouldn't interfere with the overall look of our own app). Which also works fine, I get the texture without a problem even when the Unity form is completely off-screen.
Now my problem is that this Unity application requires to be used with multitouch and after some fair amount of googling/stack overflow reading I kinda concluded that there's no way (or I haven't found any way) to compose valid WM_POINTER* messages just for one window in Windows. (this is kinda supported by the fact that you need to call a separate WinApi function to get all the data of a Pointer/Touch based on their ID which is received in the lParam of WM_POINTER* message)
So I'm using the TouchInjection Windows API (InitializeTouchInjection and InjectTouchInput) (information about these API's on the internet are misleading at their best but I solved actually all their quirks) and it works fine if the Unity form is visible on the screen. Or in other words if the touch position is inside the screen boundaries.
And now finally the problem: When I specify an offscreen coordinate for the injected touches, I get an ERROR_INVALID_PARAMETER (87 / 0x57) system error message. Otherwise it works. Is there a way to turn off this check in windows? Or anybody who solved this problem before some other way?
(Our app is not an end-user one, we have full control over the environment it runs inside, system-wide modifications are also OK.)
Thanks in advance!
You can't turn off error code checking because it's a return value inside the function, and represents a failure of the function call, then the function return or change nothing but error code. If the error code can be disabled, then what the status of the function call? succeed or fail?
You need to check coordinate manually and detect what to do.

Xamarin Android Activities and Disposing of Disposables

I've found that whilst there are a lot of tutorials on Xamarin Android, there does not seem to be a great deal on how to dispose of resources. More particularly, when they are disposed of.
For example, in the OnCreate handler of an activity, I am making several Rx subscriptions, each of which returns an IDisposable. I have tried to dispose of those in various other handlers (e.g. OnDestroy), but those handlers never get invoked. But the subscriptions seem to pile up because OnCreate runs every time the activity is navigated to.
In addition to those subscriptions, there's all the UI controls (TextViews, Buttons etc.) which I am assigning to class-level variables (fields). And those also implement IDisposable.
For all I know, I've got memory leaks all over the place.
Is there a guidance on this anywhere?
#SushiHangover is correct (thanks Sushi). OnPause and OnResume were the events I was after. I also had a bit of a challenge in that when I clicked my custom "Back to Start" button, I needed to go right back to the start screen (skipping the intermediate screen along the way).
The way to do that is use the ClearTop ActivityFlag (Android.Content.ActivityFlags.ClearTop) when starting the Home screen activity. Raw Android code version of this can be seen here https://stackoverflow.com/a/5794572/540156
When you do that, you can clean things up on the activities which get popped off the back-stack as they get popped (in the OnDestroy handler, from recollection).

Where is it best to place the code that initializes my UI for an OS X app?

If I am NOT using NIB/XIB files for my UI then where is it best to place/launch the code that initialises my GUI?
The logical place seems to be the App Delegate's applicationDidFinishLaunching: method...or perhaps there is a window controller or delegate that should be used? Or perhaps in the main.swift file?
It all depends on what your program does and the preffered order of operations.
If you want to call a view controller right away then you can put it in the applicationDidFinishLaunching: method like you mentioned but you could also put it in methods of other classes if you want something some operations to run in the background first.
The main thing to remember is that you want the user to feel like your application isn't frozen. So add a progress indicator or such if it will be a longer loading time than average. Apple requires a loading screen for all published iOS apps so that is a perfect place to put a loading image.

WP7: Is it possible to intercept the backstack before the journal thumbnail is created/stored

You all know the Windows Phone backstack right. If you go through some apps, tap the Home key after starting each app. Now tap and hold the Backkey to see the Backstack. You can now see some small images of your apps, and can pick which one to go to right.
Question:
Is it possible to intercept before the backstack image is created? I have tried to blur my page in various events (include OnNavigatingFrom) to no avail.
My guess is some other event (probably something we don't have access to) is triggered and a bitmap is created, because when you use the Backstack to navigate you can just see a slight transition from the saved image to a real page IMO.
Does anyone know if its possible to intercept or manipulate these images on the backstack?
Example screenshot from WP emulator of the Backstack thumbnails
Following my comment, I've just tried this:
Set a breakpoint anywhere in the code
Start the app with the debugger attached, then let it reach the breakpoint
While the execution is stopped by the debugger, long press on the back button
The task switching UI is displayed even though the managed code execution is stopped
From there, I think we can safely conclude that the task switching and the thumbnail are handled entirely by native code. Therefore, there's nothing you can do.
I recently wrote a blogpost in which I discuss the ways I tried to hide data from the application snapshot. (You can read it here: http://corstianboerman.com/trying-to-hide-crucial-data-from-an-application-snapshot/)
The outcome: You just can't hide it.

Creating splash screen Cocoa

I have been looking for a way to display a splash screen on a cocoa app im making(not iphone) and am very new im not asking if you think its a good idea or not because i know how it could be annoying for users. Its helping me learn.
I was wondering if there was a way to create a splash screen on a timer?
could anyone breifly walk me through it or point me in the right direction?
Easiest way I can think of is to add the splash screen's window to MainMenu.xib, and mark it as visible at launch - that way you don't need to worry about loading and showing it, all that will happen by default. In your app delegate's -applicationDidFinishLaunching:, start an NSTimer instance. When it fires, send your splash window a -close message.
(Edit) Okay, I know you didn't ask if it's a good idea or not, but here's my two cents anyway - if your app needs to load & initialize a bunch of plugins or perform some other lengthy operation before it's ready to be used, then a splash screen with an updating status would be less annoying than having to sit there just wondering what's going on...
(Edit.2) More about the plugin loading. You could write a method that loads one plugin, then uses NSTimer to call itself with zero delay if there are more plugins to load. Doing it via zero-delay timers, instead of a simple for() or while() loop, would allow the run loop to stay active, so you could update a progress bar and avoid the spinning technicolor pizza of death.

Resources