Re: Seg fault when accessing bitmap pixels

369 views
Skip to first unread message

alan

unread,
Nov 15, 2010, 4:37:42 AM11/15/10
to android-ndk
Are you sure you are using the correct value for pos?

On Nov 15, 1:37 am, Charles Beligian <chabelig...@gmail.com> wrote:
> In Java, I'm creating a bitmap as follows:
>
> bmp = Bitmap.createBitmap(256, 256, Bitmap.Config.ARGB_8888);
>
> After passing it into a JNI call and calling AndroidBitmap_getInfo(),
> I want to do some pixel work with the last parameter. So:
>
> void*              pixels;
> int                ret;
>
> if ((ret = AndroidBitmap_lockPixels(env, bitmap, &pixels)) < 0) {
>         LOGE("AndroidBitmap_lockPixels() failed ! error=%d", ret);
>
> }
>
> jbyte*  dat = (jbyte*) pixels;
>
>  for ( ... ) {
> dat[pos] = // .. do some work}
>
> However, I'm getting memory addressing errors when trying to access an
> arbitrary position in dat. How can I go store all the bitmap pixel
> data into a pointer like this?

Igor R

unread,
Nov 15, 2010, 4:42:22 AM11/15/10
to andro...@googlegroups.com
> if ((ret = AndroidBitmap_lockPixels(env, bitmap, &pixels)) < 0) {
>        LOGE("AndroidBitmap_lockPixels() failed ! error=%d", ret);
> }

If AndroidBitmap_lockPixels failed, the function shouldn't continue.
Perhaps it really failed, and you just didn't pay attention to the
log.

mic _

unread,
Nov 15, 2010, 11:25:50 AM11/15/10
to andro...@googlegroups.com
If your bitmap is 256 kB, then why are you trying to access data at offset 266240? Or am I misunderstanding your printouts?

How are you limiting the value of pos? The code snippet you posted (" for ( ... ) {  dat[pos] = // .. do some work  }") wasn't very clear.

/Michael

On Mon, Nov 15, 2010 at 5:09 PM, Charles Beligian <chabe...@gmail.com> wrote:
alan: insofar as I can tell. Here are the last few pos values that I
am modifying right before the crash (obtained through log printing):

Array: 260119 260118 260117
Array: 261143 261142 261141
Array: 262146 262145 262144
Array: 263170 263169 263168
Array: 264194 264193 264192
Array: 265218 265217 265216
Array: 266242 266241 266240 (the apparently faulty address)
(*crash* )
signal 11 (SIGSEGV), fault addr 42a4d00a
r0 00000020  r1 00000000  r2 00000000  r3 42a4d008
r4 00000004  r5 0000aa50  r6 00041000  r7 80836dfd
r8 00000000  r9 00000000  10 000000a0  fp 00000000
ip 0000000f  sp bea67820  lr 80840ea5  pc 80901296  cpsr 00000030

Not sure if that's helpful. It's all hex to me. I did find some math
online that suggested the pixel memory size is equivalent to stride *
height of the image--for me that's 262144. Maybe there are some buffer
pixels involved as well, or maybe it's all gibberish, but it's a
number awfully close to where I am crashing.

Igor: good catch. I added a return; statement within the loop. The
code however continues to function (i.e. lockPixels doesn't fail).
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.


Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
Message has been deleted
0 new messages