Sometimes on my android live wallpaper I get this exception on RESIZE: IllegalArgumentException: Bad position 8/0
latest libgdx
java.lang.IllegalArgumentException: Bad position 8/0
at java.nio.Buffer.position(Buffer.java:249)
at com.badlogic.gdx.graphics.glutils.VertexArray.bind(VertexArray.java:118)
at com.badlogic.gdx.graphics.Mesh.bind(Mesh.java:391)
at com.badlogic.gdx.graphics.Mesh.bind(Mesh.java:382)
at com.badlogic.gdx.graphics.Mesh.render(Mesh.java:490)
at com.badlogic.gdx.graphics.Mesh.render(Mesh.java:460)
at com.badlogic.gdx.graphics.g2d.SpriteBatch.flush(SpriteBatch.java:977)
at com.badlogic.gdx.graphics.g2d.SpriteBatch.setProjectionMatrix(SpriteBatch.java:1049)
at hu.lacas.newalienlwp.Renderer.resizeBatch(Renderer.kt:844)
at hu.lacas.newalienlwp.Renderer.access$resizeBatch(Renderer.kt:44)
at hu.lacas.newalienlwp.Renderer$resize$1.run(Renderer.kt:828)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6692)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
The source code
#override fun resize(width: Int, height: Int) {
camera.viewportHeight = Gdx.graphics.height.toFloat()
camera.viewportWidth = Gdx.graphics.width.toFloat()
mOrientation = if (camera.viewportHeight < camera.viewportWidth) LiveWallpaper.ORIENTATION_LANDSCAPE else LiveWallpaper.ORIENTATION_PORTRAIT
camera.fieldOfView = (if (mOrientation != LiveWallpaper.ORIENTATION_LANDSCAPE) 27 else 20).toFloat()
camera.update()
handler.postDelayed({
resizeBatch()
}, 900)
}
private fun resizeBatch() {
val viewportWidth = Gdx.graphics.width
val viewportHeight = Gdx.graphics.height
if (camera2D == null) camera2D = OrthographicCamera()
camera2D?.setToOrtho(false, viewportWidth.toFloat(), viewportHeight.toFloat())
camera2D?.update()
spriteBatch!!.projectionMatrix = camera2D?.combined
Objects.textureRegionScanlineFullScreen.setRegion(0, 0, Gdx.graphics.width, Gdx.graphics.height)
}
it looks like the problem is here:
--> spriteBatch!!.projectionMatrix = camera2D?.combined
This exception is just comes up sometimes... So not really understand what is going on. I created that handler with 900ms because when this is not there the exception is shown more.. Whats is going on?
Libgdx not loaded the matrix yet?
Related
In my application I write some codes and this codes I used string.
I want use UTF-8 languages (Farsi), But after run application show me error and force close application.
But when use English language not show me any error and run successfully!!
My codes :
this.q.put("dry land swim", Integer.valueOf(R.array.dry_land_swim));
TypedArray obtainTypedArray = getResources().obtainTypedArray(((Integer) this.q.get(stringArray[i])).intValue());
int length = obtainTypedArray.length();
int[] iArr2 = new int[length];
WorkoutData workoutData = new WorkoutData();
for (int i2 = 0; i2 < length; i2++) {
iArr2[i2] = obtainTypedArray.getResourceId(i2, -1);
}
workoutData.setExcName(stringArray[i]);
Log.e("ShowError", "" + (this.r.get(stringArray[i])).intValue());
workoutData.setExcDescResId(((Integer) this.r.get(stringArray[i])).intValue());
When change this line text (from En to Fa) :
this.q.put("تست", Integer.valueOf(R.array.dry_land_swim));
Show me error for this lines :
TypedArray obtainTypedArray = getResources().obtainTypedArray(((Integer) this.q.get(stringArray[i])).intValue());
workoutData.setExcDescResId(((Integer) this.r.get(stringArray[i])).intValue());
Error message :
java.lang.RuntimeException: Unable to start receiver com.crazytrends.healthmanager.WalkandStep.receivers.HardwareStepCountReceiver: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=com.crazytrends.healthmanager/.WalkandStep.services.HardwareStepCounterService }: app is in background uid UidRecord{528e8bd u0a841 RCVR idle change:idle|uncached procs:1 seq(0,0,0)}
at android.app.ActivityThread.handleReceiver(ActivityThread.java:4452)
at android.app.ActivityThread.access$1600(ActivityThread.java:301)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2159)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8512)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
Caused by: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=com.crazytrends.healthmanager/.WalkandStep.services.HardwareStepCounterService }: app is in background uid UidRecord{528e8bd u0a841 RCVR idle change:idle|uncached procs:1 seq(0,0,0)}
at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1795)
at android.app.ContextImpl.startService(ContextImpl.java:1740)
at android.content.ContextWrapper.startService(ContextWrapper.java:738)
at android.content.ContextWrapper.startService(ContextWrapper.java:738)
at com.crazytrends.healthmanager.WalkandStep.receivers.HardwareStepCountReceiver.onReceive(HardwareStepCountReceiver.java:22)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:4443)
How can I Fix it?
I have a question regarding h2o.stackedEnsemble in R. When I try to create an ensemble from GLM models (or any other models and GLM) I get the following error:
DistributedException from localhost/127.0.0.1:54321: 'null', caused by java.lang.NullPointerException
DistributedException from localhost/127.0.0.1:54321: 'null', caused by java.lang.NullPointerException
at water.MRTask.getResult(MRTask.java:478)
at water.MRTask.getResult(MRTask.java:486)
at water.MRTask.doAll(MRTask.java:390)
at water.MRTask.doAll(MRTask.java:396)
at hex.StackedEnsembleModel.predictScoreImpl(StackedEnsembleModel.java:123)
at hex.StackedEnsembleModel.doScoreMetricsOneFrame(StackedEnsembleModel.java:194)
at hex.StackedEnsembleModel.doScoreOrCopyMetrics(StackedEnsembleModel.java:206)
at hex.ensemble.StackedEnsemble$StackedEnsembleDriver.computeMetaLearner(StackedEnsemble.java:302)
at hex.ensemble.StackedEnsemble$StackedEnsembleDriver.computeImpl(StackedEnsemble.java:231)
at hex.ModelBuilder$Driver.compute2(ModelBuilder.java:206)
at water.H2O$H2OCountedCompleter.compute(H2O.java:1263)
at jsr166y.CountedCompleter.exec(CountedCompleter.java:468)
at jsr166y.ForkJoinTask.doExec(ForkJoinTask.java:263)
at jsr166y.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:974)
at jsr166y.ForkJoinPool.runWorker(ForkJoinPool.java:1477)
at jsr166y.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104)
Caused by: java.lang.NullPointerException
Error: DistributedException from localhost/127.0.0.1:54321: 'null', caused by java.lang.NullPointerException
The error does not occur when I stack any other models, only appears with the GLM. Of course I use the same folds for cross-validation.
Some sample code for training the model and the ensemble:
glm_grid <- h2o.grid(algorithm = "glm",
family = 'binomial',
grid_id = "glm_grid",
x = predictors,
y = response,
seed = 1,
fold_column = "fold_assignment",
training_frame = train_h2o,
keep_cross_validation_predictions = TRUE,
hyper_params = list(alpha = seq(0, 1, 0.05)),
lambda_search = TRUE,
search_criteria = search_criteria,
balance_classes = TRUE,
early_stopping = TRUE)
glm <- h2o.getGrid("glm_grid",
sort_by="auc",
decreasing=TRUE)
ensemble <- h2o.stackedEnsemble(x = predictors,
y = response,
training_frame = train_h2o,
model_id = "ens_1",
base_models = glm#model_ids[1:5])
This is a bug, and you can track the progress of the fix here (this should be fixed in the next release, but it might be fixed sooner and available on the nightly releases).
I was going to suggest training the GLMs in a loop or apply function (instead of using h2o.grid()) as a temporary work-around, but unfortunately, the same error happens.
I have a problem with OpenCV4Android.
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example.camtime/com.fognature.develop.smp.CameraActivity}:
CvException [org.opencv.core.CvException: cv::Exception:
/hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/imgproc/src/color.cpp:3739:
error: (-215) scn == 3 || scn == 4 in function void
cv::cvtColor(cv::InputArray, cv::OutputArray, int, int)
]
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2320)
at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2380)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1285)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5289)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: CvException [org.opencv.core.CvException: cv::Exception:
/hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/imgproc/src/color.cpp:3739:
error: (-215) scn == 3 || scn == 4 in function void
cv::cvtColor(cv::InputArray, cv::OutputArray, int, int)
]
at org.opencv.imgproc.Imgproc.cvtColor_1(Native Method)
at org.opencv.imgproc.Imgproc.cvtColor(Imgproc.java:4598)
at
com.fognature.develop.smp.CameraActivity.onCreate(CameraActivity.java:108)
at android.app.Activity.performCreate(Activity.java:6018)
at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2273)
... 10 more
On this code part:
Mat sec;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
sec = new Mat();
setContentView(R.layout.activity_camera);
File photo = new File(Environment.getExternalStorageState()
+File.separator+"SMP"+File.separator+getIntent().getStringExtra("c_name")+File.separator+getIntent().getStringExtra("last_photo"));
sec = Highgui.imread(photo.getAbsolutePath());
Imgproc.cvtColor(sec, sec, Imgproc.COLOR_RGBA2GRAY);
}
It always crash on Imgproc.cvtColor(sec, sec, Imgproc.COLOR_RGBA2GRAY);
The error states that :
error: (-215) scn == 3 || scn == 4 in function void
cv::cvtColor(cv::InputArray, cv::OutputArray, int, int) ]
which generally means that:
When you are trying to convert RGBA2GRAY, then the input Mat sec in this case has Only 1 channel. You can confirm this by logging the sec.channels() just after reading it.
It is also possible that, input Mat was empty or corrupted, to confirm you may check sec.width, sec.height, sec.depth, etc attributes to assure that it was loaded properly.
I need your help here.
I'm trying to implement simple blending of two images using OpenCV's seamlessClone() function. I'm getting an exception which says:
error: (-215) CV_MAT_TYPE(mtype) == m.type()
Here is the source code for it:
public class SeamlessClone extends AppCompatActivity {
public static final String TAG = "Seamless Clone demo";
static {
if (!OpenCVLoader.initDebug()) {
// Handle initialization error
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_seamless_clone);
Bitmap destinationBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.lightning);
Log.d(TAG, "bitmap: " + destinationBitmap.getWidth() + "x" + destinationBitmap.getHeight());
Mat destination = new Mat(destinationBitmap.getHeight(),
destinationBitmap.getWidth(), CvType.CV_8UC4);
Utils.bitmapToMat(destinationBitmap, destination);
Bitmap sourceBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.airplane);
Log.d(TAG, "bitmap: " + sourceBitmap.getWidth() + "x" + sourceBitmap.getHeight());
Mat source = new Mat(sourceBitmap.getHeight(),
sourceBitmap.getWidth(), CvType.CV_8UC4);
Utils.bitmapToMat(sourceBitmap, source);
Mat mask = new Mat(source.rows(),source.cols(),source.depth(),Scalar.all(255));
Point point = new Point(destination.cols()/2,destination.rows()/2);
Mat result = new Mat(destinationBitmap.getHeight(),
destinationBitmap.getWidth(), CvType.CV_8UC4);
Photo.seamlessClone(source, destination, mask, point, result, Photo.NORMAL_CLONE);
Utils.matToBitmap(result, destinationBitmap);
ImageView imageView = (ImageView) findViewById(R.id.clone_result);
imageView.setImageBitmap(destinationBitmap);
}
}
And following is the error log from the logcat:
E/OpenCV/StaticHelper: OpenCV error: Cannot load info library for OpenCV
E/cv::error(): OpenCV Error: Assertion failed (CV_MAT_TYPE(mtype) == m.type()) in void cv::_OutputArray::create(int, const int*, int, int, bool, int) const, file /Volumes/Linux/builds/master_pack-android/opencv/modules/core/src/matrix.cpp, line 2297
E/org.opencv.photo: photo::seamlessClone_10() caught cv::Exception: /Volumes/Linux/builds/master_pack-android/opencv/modules/core/src/matrix.cpp:2297: error: (-215) CV_MAT_TYPE(mtype) == m.type() in function void cv::_OutputArray::create(int, const int*, int, int, bool, int) const
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.hemisphere.opencvexample, PID: 1905
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.hemisphere.opencvexample/com.example.hemisphere.opencvexample.SeamlessClone}:
CvException [org.opencv.core.CvException: cv::Exception: /Volumes/Linux/builds/master_pack-android/opencv/modules/core/src/matrix.cpp:2297: error: (-215) CV_MAT_TYPE(mtype) == m.type() in function void cv::_OutputArray::create(int, const int*, int, int, bool, int) const
]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2339)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2413)
at android.app.ActivityThread.access$800(ActivityThread.java:155)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5343)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
Caused by: CvException [org.opencv.core.CvException: cv::Exception: /Volumes/Linux/builds/master_pack-android/opencv/modules/core/src/matrix.cpp:2297: error: (-215) CV_MAT_TYPE(mtype) == m.type() in function void cv::_OutputArray::create(int, const int*, int, int, bool, int) const
]
at org.opencv.photo.Photo.seamlessClone_0(Native Method)
at org.opencv.photo.Photo.seamlessClone(Photo.java:581)
at com.example.hemisphere.opencvexample.SeamlessClone.onCreate(SeamlessClone.java:72)
at android.app.Activity.performCreate(Activity.java:6010)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1129)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292)
... 10 more
Am I doing something wrong in the code?
Thanks in Advance!
I had the same error using OpenCV with Objective-C++.
I was opening my source, destination and mask images as PNG. You need to get ride of the Alpha setting.
To do so, convert your images with OpenCV cvtColor function (CV_RGBA2RGB code) before trying to perform the clone function.
Maybe this is your problem too?
Please try to run in with 3 channels (CvType.CV_8UC3) instead of 4, hope fully it will works.
I've really tried my best, but I just can't find a fix for this Problem.
I wrote a Soundboard for Android devices, where every sound as well as its button images is loaded dynamically.
Here is the crucial paragraph in my code:
private void loadButtonColors(){
int rescount = AppConfig.BUTTONBACKGROUNDSRES(getApplicationContext()).size();
SharedPreferences prefs = getSharedPreferences("buttoncolors", 0);
String colors = null;
colors = prefs.getString("colors", null);
List<String> tempList = new ArrayList<String>();
if(colors != null){
tempList.addAll(Arrays.asList(TextUtils.split(colors, "~")));
}
if(colors == null || tempList.size() != MainActivity.SOUNDBUTTONS.size()){
for(#SuppressWarnings("unused") SoundButton s : MainActivity.SOUNDBUTTONS){
int randomint = new Random().nextInt(rescount);
Integer randominteger = Integer.valueOf(randomint);
String randomstring = String.valueOf(randominteger);
tempList.add(randomstring);
}
prefs.edit().putString("colors", TextUtils.join("~", tempList)).commit();
}
MainActivity.BUTTONCOLORS = (ArrayList<String>) tempList;
}
Later the button's images will be displayed with the images out of the following Arrays where the error seems to arise.
public static ArrayList<Drawable> BUTTONBACKGROUNDSRES(Context context){
ArrayList<Drawable> tempList = new ArrayList<Drawable>();
tempList.add(context.getResources().getDrawable(R.color.button_lblue));
tempList.add(context.getResources().getDrawable(R.color.button_lime));
tempList.add(context.getResources().getDrawable(R.color.button_orange));
tempList.add(context.getResources().getDrawable(R.color.button_pink));
tempList.add(context.getResources().getDrawable(R.color.button_red));
tempList.add(context.getResources().getDrawable(R.color.button_yellow));
return tempList;
};
The resulting error looks like this:
java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:587)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:422)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:840)
at android.content.res.Resources.loadDrawable(Resources.java:2150)
at android.content.res.Resources.getDrawable(Resources.java:715)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:176)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:937)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:877)
at android.content.res.Resources.loadDrawable(Resources.java:2132)
at android.content.res.Resources.getDrawable(Resources.java:715)
at com.centivo.inscope21soundboard.AppConfig.BUTTONBACKGROUNDSRES(AppConfig.java:45)
at com.centivo.inscope21soundboard.LauncherActivity.loadButtonColors(LauncherActivity.java:128)
at com.centivo.inscope21soundboard.LauncherActivity.access$1(LauncherActivity.java:127)
at com.centivo.inscope21soundboard.LauncherActivity$1.run(LauncherActivity.java:43)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5105)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
at dalvik.system.NativeStart.main(Native Method)
If you wanna check out the App visit the Playstore
EDIT: The size of every button image is about 70kb.
If you are running out of memory, store the tempList in BUTTONBACKGROUNDSRES in a member or static variable. It looks like every time you call BUTTONBACKGROUNDSRES, you are going to load a new set of Drawables. If these are always the same, there is no sense in loading them frequently from scratch and then leaving the tempList to be garbage collected. Just create the list once, then refer it.