Libgdx + Glide - Couldn't load dependencies of asset - libgdx

Unlike all the issues involving this error, this one is a bit tricky.
I have the following:
Downloading a .png image with Glide v3 into my app's internal storage, using SimpleTarget to get a bitmap and saving it into a file.
I know by fact that this sometimes is saving a corrupted file, maybe due timeout issues.
This is ok.
The problem comes when libgdx's AssetManager tries to render this file.
It throws the "Couldn't load dependencies of asset" error.
Which is ok.
So, what I need to know is:
Is there any way to catch that error getting the file name to delete it and start a new download call?
What I tried to do already:
Looking for AssetManager functions to check the files integrity, theres none as far as I could check
Checking the file with FileHandleResolver and Gdx.files.absolute(fileName).exists, but this is usesless because the file indeed exists and its size isnt 0.
Catching the GdxRuntimeException, parsing it to get the file name, but this is kinda the worst way.
Thank you guys in advance.

You can add an AssetErrorListener to your AssetManager. This will give you the AssetDescriptor for the particular asset which failed to load as well as the associated exception. Those two pieces of information should allow you to get what you need to redownload and retry.

Related

PDF.js: file origin does not match viewer's

I am trying to serve PDF files from a bucket on Amazon-S3, using PDF.js in the browser. I have amended the relevant CORS policy in S3. However, I am receiving the following error message in the browser:
PDF.js v2.2.71 (build: 80135378)
Message: file origin does not match viewer's
After a search, I have found several related questions, such as this question here, as this appears to be a relatively common issue. It is fairly obvious therefore that I need to allow Amazon S3 as a host origin. Therefore, I amend my viewer.js file to include the host, like so:
var HOSTED_VIEWER_ORIGINS = ['null',
'http://mozilla.github.io',
'https://mozilla.github.io',
'https://thepdfbucket.s3.eu-west-
2.amazonaws.com'];
However, if I do a hard reload and inspect sources, I can see that the error is thrown in webpack:///web/app.js:
Uncaught (in promise) Error: file origin does not match viewer's
at validateFileURL (app.js:1482)
at webViewerInitialized (app.js:1541)
If I examine app.js, I can see the HOSTED_VIEWER_ORIGINS array, mapped from the viewer.js file. However, it does not include the amended array, i.e. my addition of https://thepdfbucket.s3.eu-west-2.amazonaws.com.
I cannot get this to work. I believe I probably have a cache issue, however, I have cleared all the browser's cache, I have even built PDF.js again from github and tried to amend the viewer.js file, prior to compilation.
If I have amended the viewer.js file, and app.js is mapped from viewer.js, but it does not reflect the recent changes, my conclusion is that it must be using a cached file. How do I clear this cache, and get app.js to reflect the changes I have made?
I really would appreciate any help here, as I've spent the whole of yesterday on this issue, and I cannot get my head around how this all fits together.
Many Thanks.
I also ran into this problem and investigated.
Version of PDF.js: pdfjs-3.3.122
The reason is that when debugging in the browser, the debug information is from viewer.js.map and not the actual working viewer.js source code.
The quickest way to debug is to delete viewer.js.map.
Perhaps the reason for the error is a mis-specified value.
That was the case for me.
Incorrect: https://google.com/
Correct: https://google.com
Translated with www.DeepL.com/Translator (free version)

Upload video to YouTube via V3-API with Flex/AS3

I am currently working on an AIR-Application to upload videos to youtube. Since I got the very absurd requirement to upload files up to 80GB (we do not need to discuss this, I also think it´s nonsense) I decided to use the resumable upload for uploading chunks, like descriped on https://developers.google.com/youtube/v3/guides/using_resumable_upload_protocol
But for some reason, if I add the Content-Range header, I always receive an Error #2032. If I do not add the Content-Range header, the upload works, but only for the first chunk.
Has anyone managed to upload a file with the V3 API in AS3/Flex ?
Error 2032 usually occurs when your program or running application goes non-responsive. Some common reasons for this..
Your Proxy Settings may be not valid
Your Website must be in the list of restrictions
Your cookies must be corrupted
Your ADD-ON's on your browser may be responsible
Your registry must be corrupted
Source : Adobe Forums
Okay, I found out, what the "problem" is.
After uploading a chunk, the youtube servers return HTTP 308, which will be assessed as an error. Actually it isn't, it is youtubes status for "Resume incomplete". So the solution is simply to add an EventListener for HTTP_RESPONSE_STATUS, check for status 308 and then keep sending the next chunk. HTTP 200, and therefore the COMPLETE-Event will only be fired after uploading the last chunk

LWJGL Sound manager issue

I have been working on the Asteroids Game example code that they give in the tutorials section of the wiki and I ran into a strange error.
The code works just fine in my development environment, Eclipse. The game runs without error and exits normally.
I go through the export process in the file menu and create an executable jar that when run with this batch file code
java -Djava.library.path=D:\Tools\lwjgl-2.8.4\lwjgl-2.8.4\native\windows -jar SpaceInvaders.jar
Starts the display and the fails when it trys to load a wav file. Giving this error.
Exception in thread "main" java.lang.NullPointerException
I traced to where in the code this is happening and it is at the location where the wavs are being loaded. Apprently outside of the environment it can't locate the files even though they are right next to the code? All my wav files and gif files are just in the same directory as the java class files right now so calling them from the code looks likes this:
http://i.imgur.com/2gnN1.png
Searching for stuff on google it tells me to zip them into a seperate file and then import to the class folder and refrence from there. I was wondering if there was a way to keep the files inside my main jar file instead of having to create a seperate entity.
Thanks for the replys! Let me know if more information is needed.
You may want to consider using a higher-level API, such as the 3d soundsystem from paulscode. SoundSystem can read from inside the jar(like you are asking), and automatically switch to java sound if LWJGL sound isn't supported on the current hardware.

Pass file from AS3 into embedded AS2 wrapper to load

I have a Flash AS3 application that uses FileReference.browse() to request a SWF from the user. If the chosen SWF is AS3, I'm good to go. However, if it's AS2, I need to load it into an AS2 wrapper first (so my app can alter it). All of these files (including my app and wrapper) are intended to exist locally on the user's machine, but the file they select can exist in any directory. So to be clear: Main application (AS3) -> Wrapper (AS2) -> User's file (AS2)
I know how to get the uploaded file's ActionScript version from the Loader's loaderInfo.actionScriptVersion variable, and that's working correctly. My issue is how to pass the file from the AS3 application to the AS2 wrapper so it can load it.
My first thought was to dump the ByteArray from the FileReference's load() function into a SharedObject "cookie". This method seemed pretty bad from a user-experience point of view, but it seemed most likely to work. However, I've been unable to find any method within AS2 to load the ByteArray as a movie (in fact, AS2 doesn't even seem to have a ByteArray class). So the first potential solution to my problem would be if anyone knew of a method for loading a movie from a ByteArray in AS2.
My second thought was to pass the uploaded file's path to my wrapper via the already-setup LocalConnection bridge, and then just have it load the file from that. However, I can't find any way to get the file's path, and my Googling suggests the security model intentionally prevents it. Not to mention, I'm not sure I can load an arbitrary file from the user's machine.
My "hands up in the air; I give up" solution was to just create separate buttons for loading AS3 and AS2 files (leaving it up to the users to guess which it is!) and have the AS2 button actually within the AS2 wrapper. However, it looks like AS2 doesn't have a file browsing uploading API, and the PHP-hybrid solutions I've found aren't an option (because this is meant to be run locally).
So, I would be eternally grateful if anyone could point me in the right direction for solving any of these three roadblocks. Alternative workarounds are of course welcome.
(Edit)
Ok, I found the documentation for AS2's version of the FileReference class. It supports the same file-browsing capability, but does not support directly loading the selected file into the SWF.
However, the security sandbox doesn't seem as strict for local files as I expected, and it looks like I can load any SWF on the user's machine once I have a path to it. So I should be able use JavaScript and an HTML form with a file input to get and pass the file path to my application. It's not ideal having to do all of this from within a web browser, but it should work. If it turns out satisfactorily I'll submit it as an answer.
(Edit 2)
Scratch the HTML-form idea. Looks like the path is hidden from JavaScript for the same reasons Flash hides it. The only option I can think of now is to have the user copy and paste the path to the file...
After reading over your post, you may be able to retry one of your previous attemps with some new information. Actionscript 2 DOES have a method for looking up files from a browser, same as AS3 does. AS2 also has a FileReference class. Check out the documentation here:
http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00001040.html
Also, here is a tutorial:
http://markshu.ca/imm/flash/tutorial/fileReference.html
Well, all of my other leads have dried up, so I'm submitting the two answers that will actually work, although neither is ideal:
A) Use Adobe AIR, which will give more access to the filesystem (such as for getting path info) at the cost of requiring the separate AIR runtime to be installed.
B) Have the user enter the path to the file themselves (cumbersome for the user)

Is it possible to access raw file data as FileReference.load() loads it in memory?

I think it's not, but maybe I'm wrong. Anyone?
UPDATE:
It's not.
i think you can, at least there is nothing in the docs that states otherwise. try adding a ProgressEvent on the FileReference object to read it's data (ByteArray) property after calling load().
however, if you're loading a file with URLLoader, a URLLoader's data property is only populated once the load operation has completed.
[EDIT]
so it's, after all, not possible to access live fileReference data while loading. the docs should explicitly state that it's not possible since it's a valid request.
however, after a some stumbling thru the docs i realized that you can do this by using the URLStream class, which provides methods to read data while it's loading - it's designed to do exactly what you are looking for.
the only catch, in this case, is that URLStream requires a full URL path (URLRequest object), which is not obtainable with FileReference for security reasons - it's only possible to get the name of a selected file, not the complete path. obtaining a local file path in AIR is very easy, but since you want your application to be browser-resistant i'm not quite sure how you'll be able to access file paths from the user's computer - unless they type in the file path, but requiring your users to do so would seriously degrade UX.
It is not possible currently...