android render issue causing delays? - android

I'm developing an Android game and I've got the garbage collection to
the point where it GC's only about once every 5 minutes or so, which I
think is acceptable, for now.
The problem is that, every once in a while, I'll see this message in
the logs:
08-29 09:58:46.410 W/copybit ( 1912): stretch_copybit::run_render fail
08-29 09:59:09.000 E/libs3c2drender( 1912): int
S3c2DRender::DoG2D(unsigned int, s3c_img*, s3c_rect*, unsigned int,
s3c_img*, s3c_rect*, int, int)::S3C_G2D_ROTATOR_18176 fail
And when this message comes up, my game seems to pause for about
100-200 milliseconds..
I'm currently using a Canvas to draw with, although if my memory is
accurate, I've seen this same error message using Open GL as well.
Here's my code to draw the image object:
cachedMatrix.reset();
cachedMatrix.postTranslate(-halfImageWidth, -halfImageHeight);
cachedMatrix.postScale(localScaleX, localScaleY);
cachedMatrix.postTranslate(localOffset.x, localOffset.y);
float degrees = (radiansToDegrees(-rotation) + 360f) % 360f;
cachedMatrix.postRotate(degrees);
cachedMatrix.postTranslate(screenPos.x, screenPos.y);
canvas.drawBitmap(image, cachedMatrix, null);
Frankly, I am at a loss as to how to get around this. This is happening on my Samsung Moment phone.
Has anyone else encountered this issue ? And found a workaround or
insights into why this is happening ?

Related

ConsumerIrManager.transmit broken in Lollipop?

I upgraded my Samsung Galaxy S4 from latest KitKat to Lollipop (5.0.1) yesterday and my IR remote control app that I have used for months stopped working.
Since I was using a late copy of KitKat ConsumerIrManager, the transmit( ) function was sending the number of pulses using the code below. It worked very nicely.
private void irSend(int freqHz, int[] pulseTrainInMicroS) {
int [] pulseCounts = new int [pulseTrainInMicroS.length];
for (int i=0; i<pulseTrainInMicroS.length; i++) {
long iValue = pulseTrainInMicroS[i] * freqHz / 1000000;
pulseCounts[i] = (int) iValue;
}
m_IRService.transmit(freqHz, pulseCounts);
}
when it stopped working yesterday, I began looking closely at it.
I noticed that the transmitted waveform is not having any relationship with the requested pulse train. even the code below doesn't work correctly! there is
private void TestSend() {
int [] pulseCounts = {100, 100, 100};
m_IRService.transmit(38000, pulseCounts);
}
the resulting waveforms had many problems and so are entirely useless.
the waveforms were entirely wrong
the frequency was wrong and the pulse spacing was not regular
they were not repeatable
looking at the demodulated waveform:
if my 100, 100, 100 were correctly rendered, I should have seen two pulses 2.6ms (before 4.4.3(?) 100 us) long. instead I received (see attached) "[demodulated] not repeatable 1.BMP" and "[demodulated] not repeatable 2.BMP". note that the waveform isn't 2 pulses...in fact, it's not even repeatable.
as for the captures below, the signal goes low when the IR is detected.
we should have seen two pulses going low for 2.6 ms and 2.6 ms between them (see green line below).
I had also tried shorter pulses using 50, 50, 50 and have observed that the first pulse isn't correct either (see below).
looking at the modulated waveform:
the frequency was not correct; instead, it was about 18kHz and irregular.
I'm quite experienced with this and have formal education in electronics.
It seems to me there's a bug in ConsumerIrManager.transmit( )...
curiously, the "WatchOn" application that comes with the phone still works.
thank you for any insights you can give.
Test equipment:
Tektronix TDS-2014B, 100 MHz, used in peak-detect mode.
As #IvanTellez says, a change was made in Android in respect to this functionality. Strangely, when I had it outputting simple IR signals (for troubleshooting purposes), the function behaves as shown above (erratically, wrong carrier frequency, etc). When I eventually returned to normal types of IR signals, it worked correctly.

What does this logcat line mean

I am seeing this logcat line when I run my app.
/dalvikvm(20160): 20160(com.test) stat: (e) 315 4699KB / (c) 0 0KB / (a) 1 5355KB / (h) 2836KB 6884KB 4047KB
My application runs ok, dont see any issue, but this red line in logcat worries me. stat(e) looks like some kind of error statistics. I am just guessing. I did some googling, but could not find anything
There is nothing to worry about, it just simple Dalvik VM waste. Anyway as a usual developer you couldn't make any affect on it.

Accurate POSIX thread timing using NDK

I'm writing a simple NDK OpenSL ES audio app that records the users touches on a virtual piano keyboard and then plays them back forever over a set loop. After much experimenting and reading, I've settled on using a separate POSIX loop to achieve this. As you can see in the code it subtracts any processing time taken from the sleep time in order to make the interval of each loop as close to the desired sleep interval as possible (in this case it's 5000000 nanoseconds.
void init_timing_loop() {
pthread_t fade_in;
pthread_create(&fade_in, NULL, timing_loop, (void*)NULL);
}
void* timing_loop(void* args) {
while (1) {
clock_gettime(CLOCK_MONOTONIC, &timing.start_time_s);
tic_counter(); // simple logic gates that cycle the current tic
play_all_parts(); // for-loops through all parts and plays any notes (From an OpenSL buffer) that fall on the current tic
clock_gettime(CLOCK_MONOTONIC, &timing.finish_time_s);
timing.diff_time_s.tv_nsec = (5000000 - (timing.finish_time_s.tv_nsec - timing.start_time_s.tv_nsec));
nanosleep(&timing.diff_time_s, NULL);
}
return NULL;
}
The problem is that even using this the results are better, but quite inconsistent. sometimes notes will delay for perhaps even 50ms at a time, which makes for very wonky playback.
Is there a better way of approaching this? To debug I ran the following code:
gettimeofday(&timing.curr_time, &timing.tzp);
__android_log_print(ANDROID_LOG_DEBUG, "timing_loop", "gettimeofday: %d %d",
timing.curr_time.tv_sec, timing.curr_time.tv_usec);
Which gives a fairly consistent readout - that doesn't reflect the playback inaccuracies whatsoever. Are there other forces at work with Android preventing accurate timing? Or is OpenSL ES a potential issue? All the buffer data is loaded into memory - could there be bottlenecks there?
Happy to post more OpenSL code if needed... but at this stage I'm trying figure out if this thread loop is accurate or if there's a better way to do it.
You should consider seconds when using clock_gettime as well, you may get greater timing.start_time_s.tv_nsec than timing.finish_time_s.tv_nsec. tv_nsec starts from zero when tv_sec is increased.
timing.diff_time_s.tv_nsec =
(5000000 - (timing.finish_time_s.tv_nsec - timing.start_time_s.tv_nsec));
try something like
#define NS_IN_SEC 1000000000
(timing.finish_time_s.tv_sec * NS_IN_SEC + timing.finish_time_s.tv_nsec) -
(timing.start_time_s.tv_nsec * NS_IN_SEC + timing.start_time_s.tv_nsec)

Android Canvas OpenGL Renderer is out of memory

I develop android library for drawing chart at view, using canvas.
However, the following errors occur frequently.
LogCat:
D/NvOsDebugPrintf(11526): NvRmChannelSubmit: NvError_IoctlFailed with error code 12
D/NvOsDebugPrintf(11526): NvRmChannelSubmit failed (err = 196623, SyncPointValue = 94008102)
(87 times repeat)
D/OpenGLRenderer(11526): GL error from OpenGLRenderer: 0x505
E/OpenGLRenderer(11526): OpenGLRenderer is out of memory!
Solution is not found although I am groping for various causes and solution.
So, please tell me about what can become a cause which such an error generates?
And how can solve this problem.
I beg your kindness. Finally my sincere apologies for my poor English.

Android Live Wallpaper: waitForCondition(ReallocateCondition)

I've been developing a live wallpaper using GLWallpaperService, and have gotten good results overall. It runs rock-solid in the emulator and looks good. I've dealt with OpenGL many times before so have a solid command of how to do things... unfortunately I'm having a hell of a time getting this to actually be stable on the actual hardware.
The basic symption occurs when you slide the physical keyboard on a Motorola Droid in and out a few times. This causes the wallpaper to get destroyed/recreated several times in quick succession -- which would be fine, as I have my assets clearing in onDestroy and reloading in onSurfaceChanged. The problem is after a few iterations of this, (four or five, maybe) the calls to onSurfaceChanged completely stop, and i get an endless string of this printed to the log:
04-02 00:53:18.088: WARN/SharedBufferStack(1032): waitForCondition(ReallocateCondition) timed out (identity=337, status=0). CPU may be pegged. trying again.
Is there something I should be implementing here aside from the Android-typical onSurfaceCreated/onSurfaceChanged/onSurfaceDestroyed triumvirate? Browsing through the WallpaperService and WallpaperRenderer classes doesn't pop up anything obvious to me.
I had a similar problem. The error was that I needed to call to "unlockCanvasAndPost":
Canvas c = null;
**try {**
c = holder.lockCanvas(null);
synchronized (holder) {
instance.doDraw(c);
}
**} finally {
// do this in a finally so that if an exception is thrown
// during the above, we don't leave the Surface in an
// inconsistent state
if (c != null) {
holder.unlockCanvasAndPost(c);
}
}**

Categories

Resources