Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error reading JPEG file #47

Closed
chuen1118 opened this issue Aug 7, 2018 · 19 comments
Closed

Error reading JPEG file #47

chuen1118 opened this issue Aug 7, 2018 · 19 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@chuen1118
Copy link

chuen1118 commented Aug 7, 2018

I am using ARToolkitX (iOS) with Unity (5.6.5f1). It works fine in the editor, however it crashed when deployed to iPad. Here is the error log:

[info] 
### Surface No.1 ###
[info]   Read ImageSet.
[info] Imageset contains 7 images.
[error] Error reading JPEG file.
[warning] Falling back to reading '/var/containers/Bundle/Application/8FC6DF5C-A6AB-4BC4-A1C5-134C0C9B73F4/SomeApp.app/Data/Raw/ARToolKit/Images/relief_eng-1.iset' in ARToolKit v4.x format.
SomeApp(3259,0x386c7000) malloc: *** mach_vm_map(size=1900408832) failed (error code=3)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
[error] Out of memory!!

I've been using this set of data before (ARTK v5.3) and had no problem.
Regenerate the dataset with artoolkitx_genTexData threw the same error.
Example from arunityx threw this too.

Looks like this line jpeg_create_decompress(&cinfo); in jpeg.c throws an error
Wrong JPEG library version: library is 62, caller expects 80

@philip-lamb
Copy link
Member

The last line points to the problem. Somehow an old version of libjpeg is being linked in, possibly even by Unity itself.

Are you able to test against Unity 2018.2?

@chuen1118
Copy link
Author

That's Unity causing the problem then? I would like to avoid upgrading the Unity version as best I can since that may cause other problems to the project.
Do you know if there is any way to manually replace the libjpeg?

@chuen1118
Copy link
Author

I've tried Unity2018.2.2 and Unity2017.4.8 but the same error.

@ThorstenBux
Copy link

Thanks for testing. I was on it today too but for some reason I can't get arunityX plugin to work :(.

@philip-lamb might it be that our libjpeg inside artoolkitX repo is the wrong version? Don't know how to tell the version number. Unity is just pulling in that lib

@chuen1118
Copy link
Author

Thanks for your effort.
I tried replacing the libjpeg.a with one from old projects: ARTK 5.3, 5.4, 6, they all looked the same and throws the same error.
Maybe that was some thing else gone wrong.
I didn't mention before, I have rebuilt the libARX.a so that it could skip connecting the calibration server and print out the error message. I am not familiar with this compiling thing and simply do that by running the build.sh. Would the rebuild process affect the linked libraries, like some old version on my machine got dragged into the rebuilt libARX.a?

@ThorstenBux
Copy link

ThorstenBux commented Aug 8, 2018 via email

@chuen1118
Copy link
Author

chuen1118 commented Aug 9, 2018

Tried that, but the same :(
I downloaded the arunityx repo this morning and followed the Quick start guide. (Since I don't have GitHub installed I downloaded a zip file. I can see that some folder was updated but that folder in the downloaded zip is empty, not sure if that's normal.)
Run the build.sh for ios and macos, made a new package with Unity2018.2.2f1, imported it to an empty project, in the Editor it threw many EntryPointNotFoundException so I didn't play it, replaced the libARX.a and export an Xcode project for iOS. It crashed again.
I've also removed the libjpeg.a from the "Linked Frameworks and Libraries" section to see if there would be any different. The app can still be built and run and threw the same error.

@ThorstenBux
Copy link

ThorstenBux commented Aug 9, 2018 via email

@ThorstenBux
Copy link

Hm, after building to Android and macOS I can finally build to iOS. Now lets see if I get your error

@ThorstenBux
Copy link

I'm at the same stage now. What did you change in the code to get the jpeg error message you are sharing?

@ThorstenBux
Copy link

Adding a breakpoint in XCode the line in question is here:

arMalloc( imageSet->scale[i]->imgBW, ARUint8, imageSet->scale[i]->xsize * imageSet->scale[i]->ysize);

@chuen1118
Copy link
Author

chuen1118 commented Aug 9, 2018

it's getting strange.
I wanted to do the whole rebuild from the start again, so I just re-download the artoolkitx repo.

In ARX/AR2/jpeg.c, uncomment line 147: (*cinfo->err->output_message) (cinfo); to print out error message (the lib version mismatch error was print from this)
In ARX/ARVideo/cparamSearch.c, line 625, changed http://www.google.com to https://www.google.com, for some reason with http:// it hold up the app for several minutes.

Then build for ios and macos.
Then I put ARX.bundle to the Unity project. The Unity editor crashed when open SimepleNFTScence, but it was safe to open other scenes. This didn't happen before. If I switch back to the provided bundle, no crash.

There were errors like this when rebuilding the bundle, but build succeed anyway:
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/install_name_tool: no LC_RPATH load command with path: /<path_to>/artoolkitx-master20180809/Source/build-macos/ARX/Release found in: /<path_to>/artoolkitx-master20180809/Source/../SDK/bin/artoolkitx_image_database2d (for architecture x86_64), required for specified option "-delete_rpath /<path_to>/artoolkitx-master20180809/Source/build-macos/ARX/Release"

@chuen1118
Copy link
Author

It ran into the arMalloc line because it failed here

jpgImage = ar2ReadJpegImage2(fp); // Caller must free result.

and fell back to the old v4.x iset format. Since the iset file is in fact a new one, it failed.

The ar2ReadJpegImage2 call lead to jpeg.c and fail here

jpeg_create_decompress(&cinfo);

which gives
Wrong JPEG library version: library is 62, caller expects 80

@ThorstenBux
Copy link

yes, figured that.

I've tried with another libjpeg but no success.

@chuen1118
Copy link
Author

After some more googling, I found a temp fix by adding -force_load $(PROJECT_DIR)/Libraries/Plugins/iOS/libjpeg.a in Other Linker Flags. Forcing the code to use the libjpeg.a from ARToolkitX :)

This might be irrelevant.
I read somewhere that some old version of opencv framework might include old version of libjpeg. However I can't find any document about the libjpeg version to confirm that saying.
Anyway, I decided to try to build a custom opencv2.framework following https://github.com/artoolkitx/artoolkitx/wiki/Building-artoolkitX-prerequisites.
However the resulting framework did not support architecture arm64.
In additional, I also tried OpenCV 3.4.2 (libjpeg v62 again) and 2.4.13.6 (not support arm64) from https://opencv.org/releases.html.

@ThorstenBux
Copy link

So basically the libjpeg from artoolkitX works but from somewhere it calls a wrong one on iOS

@chuen1118
Copy link
Author

chuen1118 commented Aug 13, 2018

I'm now convinced that it is opencv2.framework that caused the mismatch.
As ARToolkitX download the newest version from opencv.org, that version build with libjpeg-turbo which based on libjpeg 6b (ver. no. 62). I've tried to build from the opencv github repo and disable the use of libjpeg-turbo, the default built was with libjpeg 9 (ver. no. 90) and I got a new mismatch message accordingly.
Unfortunately I can't build one with libjpeg 8 to match

#define JPEG_LIB_VERSION 80 /* Compatibility version 8.0 */
#define JPEG_LIB_VERSION_MAJOR 8
#define JPEG_LIB_VERSION_MINOR 3

Would you consider sharing your working opencv2.framework instead of downloading the live version?

========================================================================
Furthermore, now I have another problem.
The Unity Editor crash every time I put in my custom ARX.bundle for macos, only the official bundle is working. The "http://www.google.com" long waiting time is really bugging me, I need to wait for more than 5 minutes every time for the camera to run, even I stop the play it would still be blocking the Editor.
Should I open a new thread for this?

@ThorstenBux
Copy link

I fear we don't have a working version with iOS and NFT on Unity3D I've run in the same issues. I can see that we have builds for all platforms except iOS. https://github.com/artoolkitx/opencv/releases
So I guess that is one thing we need to fix soonish.

@philip-lamb
Copy link
Member

I've managed to isolate one possible source of the error. We've got multiple libjpeg versions because we're linking a verion of opencv on ios and macos which is a static framework (yes, such a thing exists) and that framework contains the symbols for whatever version of libjpeg is in opencv.

I will work on a build of opencv which doesn't expose the libjpeg symbols.

@philip-lamb philip-lamb added the bug Something isn't working label Oct 5, 2018
@philip-lamb philip-lamb self-assigned this Oct 5, 2018
@philip-lamb philip-lamb added this to the 1.0.5 milestone Oct 5, 2018
ThorstenBux added a commit to augmentmy-world/artoolkitx that referenced this issue Aug 15, 2019
* commit '68245e9edfea9c86585fc29572f8a8a75e0df1bc': (38 commits)
  Fix line endings.
  Sort Windows line-endings.
  ARTrackableSquare: Fix out of bounds access
  Minor documentation updates.
  Bump version for Android.
  Change onCreate to protected because per default Android Studio create onCreate as protected. Makes integration of lib easier.
  Android SDK 28.
  Update Android SDK, NDK versions.
  Version 1.0.5.
  Provide accessors for adaptive thresholding parameters. Also, improve bracketing thresholding mode to decelerate rate of change when adjusting brackets.
  Provide accessors for square parameters. Also, improve bracketing thresholding mode to use actual rather than prospective matches.
  Add redirect in opencv download from github.
  Sort out conflicting libjpeg implementations by using the same libjpeg-turbo as used by OpenCV. Fixes artoolkitx#47.
  Package 1.0.4, with minor fixes.
  Enforce minimum inlier probability in robust multimarker pose estimation. Also adding accessors.
  Windows compilation fixes + bump version.
  Fix memory leak of images read by STBImage by correcting return type to follow RAII.
  Make JPEG reading consistent.
  add support for selecting another cmake generator under windows
  Update bitrise status image URLs.
  ...

# Conflicts:
#	Source/ARX/AR2/CMakeLists.txt
#	Source/ARX/ARTrackableSquare.cpp
#	Source/ARX/ARVideo/CMakeLists.txt
#	Source/ARX/OCVT/CMakeLists.txt
#	Source/CMakeLists.txt
#	Source/build.sh
ThorstenBux added a commit to ThorstenBux/artoolkitX_em_2d that referenced this issue Aug 28, 2019
* commit '3710b8236efb629c30bb189a3e9d7e196a00662e': (44 commits)
  stb_image in emscripten depends folder only for linux
  fixing the path in CMakeLists.txt, adding stb_image folder to emscripten
  fix to be able to build with emscripten
  fix merge issue
  gitignote
  fix for emscripten build with libjpeg
  Fix line endings.
  Sort Windows line-endings.
  ARTrackableSquare: Fix out of bounds access
  Minor documentation updates.
  Bump version for Android.
  Change onCreate to protected because per default Android Studio create onCreate as protected. Makes integration of lib easier.
  Android SDK 28.
  Update Android SDK, NDK versions.
  Version 1.0.5.
  Provide accessors for adaptive thresholding parameters. Also, improve bracketing thresholding mode to decelerate rate of change when adjusting brackets.
  Provide accessors for square parameters. Also, improve bracketing thresholding mode to use actual rather than prospective matches.
  Add redirect in opencv download from github.
  Sort out conflicting libjpeg implementations by using the same libjpeg-turbo as used by OpenCV. Fixes artoolkitx/artoolkitx#47.
  Package 1.0.4, with minor fixes.
  ...

# Conflicts:
#	.gitignore
#	Source/ARX/AR2/CMakeLists.txt
#	Source/ARX/ARVideo/CMakeLists.txt
#	Source/ARX/CMakeLists.txt
#	Source/ARX/OCVT/CMakeLists.txt
#	Source/CMakeLists.txt
#	Source/build.sh
#	Source/depends/emscripten/libjpeg/liblibjpeg.a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants