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 Offline
    V Offline
    VonHagNDaz
    wrote on last edited by
    #1

    Hey guys, I'm having a problem with a variable within a function. This variable is set to zero at the begging of the block, and used as an index for a few arrays. The ONLY place where it is changed is in the for(...; ...; Channel++) portion of the loop. Somehow this number is being set to -1. The range for this int 0 - 7. Any clues what could be happening?

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

    T 1 Reply Last reply
    0
    • V VonHagNDaz

      Hey guys, I'm having a problem with a variable within a function. This variable is set to zero at the begging of the block, and used as an index for a few arrays. The ONLY place where it is changed is in the for(...; ...; Channel++) portion of the loop. Somehow this number is being set to -1. The range for this int 0 - 7. Any clues what could be happening?

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

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

      any chance to see a relevant piece of code ?


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

      V 1 Reply Last reply
      0
      • T toxcct

        any chance to see a relevant piece of code ?


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

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

        int Channel; for( Channel = 0; Channel < NumberOfChannels; Channel++ ) { Dat = (unsigned char*)m_Dither.Dat[Channel]; Out = (unsigned char*)lpDithered->Data[Channel]; ChannelData = &(lpDthrCtrl->Data[Channel]); //Set Memory to known state so OR'ing of dithered bits works as expected memset(Out,0x00,OutLen); there is a lot more going on under this portion, but this is the only place that Channel is used.

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

        T D 2 Replies Last reply
        0
        • V VonHagNDaz

          int Channel; for( Channel = 0; Channel < NumberOfChannels; Channel++ ) { Dat = (unsigned char*)m_Dither.Dat[Channel]; Out = (unsigned char*)lpDithered->Data[Channel]; ChannelData = &(lpDthrCtrl->Data[Channel]); //Set Memory to known state so OR'ing of dithered bits works as expected memset(Out,0x00,OutLen); there is a lot more going on under this portion, but this is the only place that Channel is used.

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

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

          you say it then equals -1. where have you tested this value. have you tried to set breakpoints and use your debugger to find out exactly where the change occurs ?


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

          V 1 Reply Last reply
          0
          • T toxcct

            you say it then equals -1. where have you tested this value. have you tried to set breakpoints and use your debugger to find out exactly where the change occurs ?


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

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

            Im using VS2005, and i test the value using break points and checking the locals portion of the debugger. i do a conditional break at the beginning of the block if (Channel = -1). I also break at the the two function calls within this block. None of these functions take Channel as an argument. I also break at the end of the block to check Channel. Now it is impossible to check the value at each break all the time, because this function is called roughly a million times(deals with individual pixels split into various ink channels for images ~150+ Mb).

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

            T 1 Reply Last reply
            0
            • V VonHagNDaz

              Im using VS2005, and i test the value using break points and checking the locals portion of the debugger. i do a conditional break at the beginning of the block if (Channel = -1). I also break at the the two function calls within this block. None of these functions take Channel as an argument. I also break at the end of the block to check Channel. Now it is impossible to check the value at each break all the time, because this function is called roughly a million times(deals with individual pixels split into various ink channels for images ~150+ Mb).

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

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

              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]

              V D D 3 Replies Last reply
              0
              • V VonHagNDaz

                int Channel; for( Channel = 0; Channel < NumberOfChannels; Channel++ ) { Dat = (unsigned char*)m_Dither.Dat[Channel]; Out = (unsigned char*)lpDithered->Data[Channel]; ChannelData = &(lpDthrCtrl->Data[Channel]); //Set Memory to known state so OR'ing of dithered bits works as expected memset(Out,0x00,OutLen); there is a lot more going on under this portion, but this is the only place that Channel is used.

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

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

                VonHagNDaz wrote:

                for( Channel = 0; Channel < NumberOfChannels; Channel++ )

                What is NumberOfChannels? What is its value? Would it be possible to comment out everything in the for loop?

                VonHagNDaz wrote:

                memset(Out,0x00,OutLen);

                What is Out? What is the value of OutLen?


                "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
                • 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]

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

                  typo, but thats the statement for the conditional breakpoint, its not in the code. I just found out about those today, i like em

                  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
                    David Crow
                    wrote on last edited by
                    #9

                    toxcct wrote:

                    man, it should be this : if (Channel == -1) by using = instead of ==, you're assigning it !

                    Does the debugger differentiate between == (compare) and = (assign)?


                    "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:

                      for( Channel = 0; Channel < NumberOfChannels; Channel++ )

                      What is NumberOfChannels? What is its value? Would it be possible to comment out everything in the for loop?

                      VonHagNDaz wrote:

                      memset(Out,0x00,OutLen);

                      What is Out? What is the value of OutLen?


                      "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
                      #10

                      number of channels represents the differnt ink cartridges inside of the E*s*n printers we are modifying. 1 - 8 for dual CMYK printing. I cant comment these out because they access the arrays(one for each channel) which the pixel information for each ink channel is stored. Out is the pixel data for that channel, and OutLen is the length of the data that is expected. say 16 pixel wide image, four ink channels, you would end up with four arrays each containing the color data for that specific channel for each pixel.

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

                      D 1 Reply Last reply
                      0
                      • D David Crow

                        toxcct wrote:

                        man, it should be this : if (Channel == -1) by using = instead of ==, you're assigning it !

                        Does the debugger differentiate between == (compare) and = (assign)?


                        "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
                        #11

                        since this is a conditional break, no assignments are made. this is a feature within the vs2005 debugger. im not sure of all the ins and outs because i just found out about it today

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

                        D 1 Reply Last reply
                        0
                        • V VonHagNDaz

                          number of channels represents the differnt ink cartridges inside of the E*s*n printers we are modifying. 1 - 8 for dual CMYK printing. I cant comment these out because they access the arrays(one for each channel) which the pixel information for each ink channel is stored. Out is the pixel data for that channel, and OutLen is the length of the data that is expected. say 16 pixel wide image, four ink channels, you would end up with four arrays each containing the color data for that specific channel for each pixel.

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

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

                          VonHagNDaz wrote:

                          number of channels represents the differnt ink cartridges inside of the E*s*n printers we are modifying. 1 - 8 for dual CMYK printing...Out is the pixel data for that channel, and OutLen is the length of the data that is expected. say 16 pixel wide image, four ink channels, you would end up with four arrays each containing the color data for that specific channel for each pixel.

                          That's all well and good, but it did nothing to answer my questions. When I asked about NumberOfChannels, is it an int, short, char, etc? What value does it have (not what it should have) at the start of the for loop?


                          "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
                          • V VonHagNDaz

                            since this is a conditional break, no assignments are made. this is a feature within the vs2005 debugger. im not sure of all the ins and outs because i just found out about it today

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

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

                            VonHagNDaz wrote:

                            this is a feature within the vs2005 debugger.

                            I suspected such, hence my question to toxcct for clarification.


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

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

                            1 Reply Last reply
                            0
                            • D David Crow

                              VonHagNDaz wrote:

                              number of channels represents the differnt ink cartridges inside of the E*s*n printers we are modifying. 1 - 8 for dual CMYK printing...Out is the pixel data for that channel, and OutLen is the length of the data that is expected. say 16 pixel wide image, four ink channels, you would end up with four arrays each containing the color data for that specific channel for each pixel.

                              That's all well and good, but it did nothing to answer my questions. When I asked about NumberOfChannels, is it an int, short, char, etc? What value does it have (not what it should have) at the start of the for loop?


                              "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
                              #14

                              sorry about that, Channel is an int and is set to zero at the start of the loop, out is an unsigned char*, and Outlen is and unsigned int.

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

                              D 1 Reply Last reply
                              0
                              • V VonHagNDaz

                                sorry about that, Channel is an int and is set to zero at the start of the loop, out is an unsigned char*, and Outlen is and unsigned int.

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

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

                                VonHagNDaz wrote:

                                Channel is an int and is set to zero at the start of the loop,

                                That's obvious from your code snippet. I was asking about NumberOfChannels.

                                VonHagNDaz wrote:

                                ...out is an unsigned char*...

                                But what is its size? If it has not been initialized, memset() should fail if OutLen is anything other than 0 or 1.

                                VonHagNDaz wrote:

                                Outlen is and unsigned int.

                                But what is its value at the time of memset()?


                                "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:

                                  Channel is an int and is set to zero at the start of the loop,

                                  That's obvious from your code snippet. I was asking about NumberOfChannels.

                                  VonHagNDaz wrote:

                                  ...out is an unsigned char*...

                                  But what is its size? If it has not been initialized, memset() should fail if OutLen is anything other than 0 or 1.

                                  VonHagNDaz wrote:

                                  Outlen is and unsigned int.

                                  But what is its value at the time of memset()?


                                  "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
                                  #16

                                  man, im sorry i keep making you ask me twice, i dont know where my head is at this morning. NumberOfChannels is an int. both NumberOfChannels and Outlen are set outside by the calling class, and not altered with in this class.

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

                                  D 1 Reply Last reply
                                  0
                                  • V VonHagNDaz

                                    man, im sorry i keep making you ask me twice, i dont know where my head is at this morning. NumberOfChannels is an int. both NumberOfChannels and Outlen are set outside by the calling class, and not altered with in this class.

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

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

                                    VonHagNDaz wrote:

                                    NumberOfChannels is an int.

                                    Ok, but you still have not indicated their respective values prior to being used. Can you not just set a breakpoint on the for and memset() statements and look at their values in the watch window?


                                    "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:

                                      NumberOfChannels is an int.

                                      Ok, but you still have not indicated their respective values prior to being used. Can you not just set a breakpoint on the for and memset() statements and look at their values in the watch window?


                                      "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
                                      #18

                                      there values are NumberOfChannels 4 and OutLen 2692. its just randomly that Channel = -1. Sometimes everything works out and Channel never goes to -1, and it never goes to -1 at the same iteration through the loop. It crashes either randomly, or not at all.

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

                                      D 1 Reply Last reply
                                      0
                                      • V VonHagNDaz

                                        there values are NumberOfChannels 4 and OutLen 2692. its just randomly that Channel = -1. Sometimes everything works out and Channel never goes to -1, and it never goes to -1 at the same iteration through the loop. It crashes either randomly, or not at all.

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

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

                                        VonHagNDaz wrote:

                                        ...and OutLen 2692.

                                        So does Out have enough room for 2692 characters?

                                        VonHagNDaz wrote:

                                        its just randomly that Channel = -1.

                                        Computers never do anything at random. They do exactly what they were instructed to do.


                                        "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:

                                          ...and OutLen 2692.

                                          So does Out have enough room for 2692 characters?

                                          VonHagNDaz wrote:

                                          its just randomly that Channel = -1.

                                          Computers never do anything at random. They do exactly what they were instructed to do.


                                          "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
                                          #20

                                          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 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