Tom Ramcigam (magicmarmot) wrote,
Tom Ramcigam
magicmarmot

  • Mood:
  • Music:

Geeking out


So I just spent about ten hours finding a bug.

This segment did not work properly:
///////////////////////////////////
for (int i=0; i
[Error: Irreparable invalid markup ('<height;>') in entry. Owner must fix manually. Raw contents below.]

<lj-cut text="VC++ code behind the cut">
So I just spent about ten hours finding a bug.

This segment did not work properly:
///////////////////////////////////
for (int i=0; i<height; i+=2)
{
memcpy(oddPtr, evenPtr, stride);
evenPtr += (stride * 2);
oddPtr += (stride * 2);
}
///////////////////////////////////

I finally replaced it with this:
///////////////////////////////////
for (int i=0; i<height; i+=2)
{
memcpy((oddPtr + ((parent->m_fieldOrder + i)*stride)),
(evenPtr + ((parent->m_fieldOrder + i)*stride)),
stride);
}
//////////////////////////////////
which worked.

This bit of code is contained in an image-processing routine, which handles a number of images. The bug was that in the first instance, the first image in the sequence rendered properly, while the rest of the images were untouched.

In hunting down the bug, at one point I changed the top section of code to copy the entire frame. I used offsets as in the second example, and it copied the entire frame every time.

evenPtr and oddPtr are both char*. m_fieldOrder is either 0 or 1, and is just designed to swap the field order of the interlacing, it is not mechanical for the bug.

To add to the funkiness: this code runs in a separate thread.

Question: why does the second bit of code work, but not the first?
</lj-cut>
Subscribe
  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 1 comment