By Furious5k
on Wed, 06/20/2012 - 17:11
Hi,
I have taken the ImageTargets example and am trying to make the DataSet and Trackables it uses be passed in from the Java code. This is having a side effect on initialisation process. The water is a little too deep for me, so any help would be much appreciated.
[CODE]
/** Native function to initialize the application. */
private native void setDataSet(String dataSetPath);
/** Initializes data for tracking */
private void initTrackingData() {
String path = getResources().getString(R.string.dataSetPath);
setDataSet(path);
}[/CODE]
The JNI method simply sets the value of class variable
[CODE]char* dataSetPath = "";[/CODE]
This is the point at which I make the call (first two lines)
[CODE]
case APPSTATUS_LOAD_TRACKER:
//Initialize data required for tracking
initTrackingData();
// Load the tracking data set
//
// This task instance must be created and invoked on the UI
// thread and it can be executed only once!
try
{
mLoadTrackerTask = new LoadTrackerTask();
mLoadTrackerTask.execute();
}[/CODE]
[B]Here's the error I receive:[/B]
[CODE]04-05 20:21:33.987: D/QCAR(2792): ImageTargets::onConfigurationChanged
04-05 20:21:33.987: I/IMAGE_TARGETS(2792): Java_com_westminster_qualcomm_QCARSamples_ImageTargets_ImageTargets_setProjectionMatrix
04-05 20:21:33.987: E/AR(2792): CameraDevice::getCameraCalibration(): Failed to get camera calibration because the camera is not initialized.
[/CODE]
It looks to me like the reason is that, under normal circumstances, "setProjectionMatrix" method is called at the end of all the intialisation at:
[CODE]case APPSTATUS_CAMERA_RUNNING:
// Call the native function to start the camera
startCamera();
[B]setProjectionMatrix();[/B]
break;
default:
throw new RuntimeException("Invalid application state");[/CODE]
but for some reason my changes are making the "onConfigurationChanged()" method to be triggered, which calls the "setProjectionMatrix" earlier than it otherwise would have:
[CODE]public void onConfigurationChanged(Configuration config)
{
DebugLog.LOGD("ImageTargets::onConfigurationChanged");
super.onConfigurationChanged(config);
storeScreenDimensions();
// Set projection matrix:
if (QCAR.isInitialized())
[B]setProjectionMatrix();[/B]
}[/CODE]
Assuming my analysis is correct, I have two problems:
a) I don't understand what triggers onConfigurationChanged(). Is it modification of variables in native code?
b) The if statement safeguard is wrong with the changed code, but I don't know how to test for appropriate state. I can't even see "isInitialized()" in the QCAR.h
I suppose I could test for APPSTATUS_CAMERA_RUNNING, but not certain that is correct.
Re: onChangeConfig issue