Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. A problem with loops

A problem with loops

Scheduled Pinned Locked Moved C / C++ / MFC
databasehelpquestion
30 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V VonHagNDaz

    DavidCrow wrote:

    They do exactly what they were instructed to do

    You have to use the good ole fashion "tool blame" to keep a small amount of sanity. Yes, it is being allocated the proper space. A coworker has suggested that it might be a memory error where something is writing to that chunk and skewing the number?

    I win because I have the most fun in life...

    D Offline
    D Offline
    David Crow
    wrote on last edited by
    #21

    VonHagNDaz wrote:

    A coworker has suggested that it might be a memory error where something is writing to that chunk and skewing the number?

    That's what I've been tring to get at for several posts now, but without having any actual numbers, could not be for sure.


    "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

    "Judge not by the eye but by the heart." - Native American Proverb

    V 1 Reply Last reply
    0
    • D David Crow

      VonHagNDaz wrote:

      A coworker has suggested that it might be a memory error where something is writing to that chunk and skewing the number?

      That's what I've been tring to get at for several posts now, but without having any actual numbers, could not be for sure.


      "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

      "Judge not by the eye but by the heart." - Native American Proverb

      V Offline
      V Offline
      VonHagNDaz
      wrote on last edited by
      #22

      is there some slick way to see whats going on? ive tried watching that address with the memory view part of the debugger, but it doesnt show where anything is writing to that address.

      I win because I have the most fun in life...

      D 1 Reply Last reply
      0
      • V VonHagNDaz

        is there some slick way to see whats going on? ive tried watching that address with the memory view part of the debugger, but it doesnt show where anything is writing to that address.

        I win because I have the most fun in life...

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #23

        Set a breakpoint on any of the statements within the for loop. Add Channel to the watch window. Go through the for loop using F5. Watch Channel at each iteration. Hopefully you'll see it change to -1.


        "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

        "Judge not by the eye but by the heart." - Native American Proverb

        V 1 Reply Last reply
        0
        • D David Crow

          Set a breakpoint on any of the statements within the for loop. Add Channel to the watch window. Go through the for loop using F5. Watch Channel at each iteration. Hopefully you'll see it change to -1.


          "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

          "Judge not by the eye but by the heart." - Native American Proverb

          V Offline
          V Offline
          VonHagNDaz
          wrote on last edited by
          #24

          I appreciate the help, and im glad you havent just gotten fed up with me, but this loop is called per channel per scanline, so its simply not possible to watch Channel on every iteration. Since this error is not repeatable in the same spot every time, im fairly sure that im just screwed. Thank you for all the suggestions.

          I win because I have the most fun in life...

          D 1 Reply Last reply
          0
          • V VonHagNDaz

            I appreciate the help, and im glad you havent just gotten fed up with me, but this loop is called per channel per scanline, so its simply not possible to watch Channel on every iteration. Since this error is not repeatable in the same spot every time, im fairly sure that im just screwed. Thank you for all the suggestions.

            I win because I have the most fun in life...

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #25

            Have you considered:

            for (int Channel = 0; Channel < NumberOfChannels; Channel++)
            {
            if (-1 == Channel)
            ; // set breakpoint on this line

            Dat = (unsigned char\*)m\_Dither.Dat\[Channel\];
            Out = (unsigned char\*)lpDithered->Data\[Channel\]; 
            ChannelData = &(lpDthrCtrl->Data\[Channel\]);
            ...
            

            }


            "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

            "Judge not by the eye but by the heart." - Native American Proverb

            V 1 Reply Last reply
            0
            • D David Crow

              Have you considered:

              for (int Channel = 0; Channel < NumberOfChannels; Channel++)
              {
              if (-1 == Channel)
              ; // set breakpoint on this line

              Dat = (unsigned char\*)m\_Dither.Dat\[Channel\];
              Out = (unsigned char\*)lpDithered->Data\[Channel\]; 
              ChannelData = &(lpDthrCtrl->Data\[Channel\]);
              ...
              

              }


              "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

              "Judge not by the eye but by the heart." - Native American Proverb

              V Offline
              V Offline
              VonHagNDaz
              wrote on last edited by
              #26

              all right! i finally got it! let me explain a little bit more about this problem. im working with my company's legacy code, and im not allowed to change it because "it works." what im supposed to be doing is writing an interface to this class. so i tracked the problem down, and it was a call to CoTaskMemAlloc(1024)... why the did they hard code this, and why cant i change it? so basically what i had to do was cut out the call to that function and manually reset all the memory calls to the proper sizes from the interface. i imagine this wasnt a problem when they were processing small images, but now they're using huge digital photo quality images, im tempted to tell my boss whats up, but then ill probably hear an ear full for working around their class that "just works." thanks for the help man.

              I win because I have the most fun in life...

              D 1 Reply Last reply
              0
              • V VonHagNDaz

                all right! i finally got it! let me explain a little bit more about this problem. im working with my company's legacy code, and im not allowed to change it because "it works." what im supposed to be doing is writing an interface to this class. so i tracked the problem down, and it was a call to CoTaskMemAlloc(1024)... why the did they hard code this, and why cant i change it? so basically what i had to do was cut out the call to that function and manually reset all the memory calls to the proper sizes from the interface. i imagine this wasnt a problem when they were processing small images, but now they're using huge digital photo quality images, im tempted to tell my boss whats up, but then ill probably hear an ear full for working around their class that "just works." thanks for the help man.

                I win because I have the most fun in life...

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #27

                So exactly how did allocating 1024 bytes, rather than some larger number, mess up what you were doing?


                "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                "Judge not by the eye but by the heart." - Native American Proverb

                V 1 Reply Last reply
                0
                • D David Crow

                  So exactly how did allocating 1024 bytes, rather than some larger number, mess up what you were doing?


                  "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                  "Judge not by the eye but by the heart." - Native American Proverb

                  V Offline
                  V Offline
                  VonHagNDaz
                  wrote on last edited by
                  #28

                  it knew it was supposed to be accessing that memory, but it wasnt allocated properly, so it was overwriting into memory set aside for Channel and LengthInBytes. We (my cube mate, and i) stuck a whole bunch of _Asserts everywhere, and Channel never equaled -1, but as soon as the it set Out = (unsigned char*)lpDithered->Data[Channel]; Channel and LengthInBytes lost their value.

                  I win because I have the most fun in life...

                  1 Reply Last reply
                  0
                  • T toxcct

                    VonHagNDaz wrote:

                    if (Channel = -1).

                    :wtf::omg: !!! man, it should be this :

                    if (Channel **==** -1)

                    by using = instead of ==, you're assigning it !


                    [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                    D Offline
                    D Offline
                    DLChambers
                    wrote on last edited by
                    #29

                    Actually, it should be written thus:

                    if (-1 == Channel)

                    so if you mistakenly use = instead of == the compiler will puke. If you get in the habit of putting the constant on the left side of the equation it'll save you many headaches.

                    T 1 Reply Last reply
                    0
                    • D DLChambers

                      Actually, it should be written thus:

                      if (-1 == Channel)

                      so if you mistakenly use = instead of == the compiler will puke. If you get in the habit of putting the constant on the left side of the equation it'll save you many headaches.

                      T Offline
                      T Offline
                      toxcct
                      wrote on last edited by
                      #30

                      yeah, i know this, but I don't like it ! lol but for beginners, (for which the chance to fall in the trap is approaching the 100%), they should take this habbit...


                      [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups