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. Other Discussions
  3. The Weird and The Wonderful
  4. Caught in the trap again

Caught in the trap again

Scheduled Pinned Locked Moved The Weird and The Wonderful
graphicstestingbeta-testingjsonhelp
9 Posts 7 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.
  • B Offline
    B Offline
    Bernhard Hiller
    wrote on last edited by
    #1

    A code fragment from a class used for testing purposes. The function cuts a snippet out of an image, sends it to some data transformation (the transformed data contain no reference to a bitmap), and notifies a different class that new data are available.

            Point position = \_Motor.GetData().Position;
            Rectangle rectangle = new Rectangle(position, Properties.ImageSize.Size);
            Bitmap partialImage = \_Bitmap.Clone(rectangle, \_Bitmap.PixelFormat);
            InfraredImage = \_Converter.InfraredImageFromBitmap(partialImage);
            OnImageReceived();
    

    The function is called every few milliseconds. After a few milliseconds, Bad Things (TM) happened:

    An unhandled exception of type 'System.OutOfMemoryException' occurred in System.Drawing.dll

    - at the _Bitmap.Clone call. How could that happen? Do I have to get rid of the partialImages? I added calls to Dispose. Set it explicitely to null. Called GC.Collect. Called GC.WaitForPendingFinalizers. Nothing helped. Then I saw "rectangle = {X = 1630 Y = 0 Width = 80 Height = 100}". Uhm, _Bitmap is 1707 x 1280 pixels, isn't it? And 1630+80=1710: that's 3 pixels beyond the right border of the image. Actually an ArgumentException. And then I remembered: with those managed wrappers of the unmanaged graphics API, any kind of error is translated into an OutOfMemoryException, regardless of the actual cause. Why do I always have to learn that the hard way instead of remembering it immediately? I fear the OutOfMemoryException might somewhen become the InnerException of a LostMyMindException ...

    R B N M 4 Replies Last reply
    0
    • B Bernhard Hiller

      A code fragment from a class used for testing purposes. The function cuts a snippet out of an image, sends it to some data transformation (the transformed data contain no reference to a bitmap), and notifies a different class that new data are available.

              Point position = \_Motor.GetData().Position;
              Rectangle rectangle = new Rectangle(position, Properties.ImageSize.Size);
              Bitmap partialImage = \_Bitmap.Clone(rectangle, \_Bitmap.PixelFormat);
              InfraredImage = \_Converter.InfraredImageFromBitmap(partialImage);
              OnImageReceived();
      

      The function is called every few milliseconds. After a few milliseconds, Bad Things (TM) happened:

      An unhandled exception of type 'System.OutOfMemoryException' occurred in System.Drawing.dll

      - at the _Bitmap.Clone call. How could that happen? Do I have to get rid of the partialImages? I added calls to Dispose. Set it explicitely to null. Called GC.Collect. Called GC.WaitForPendingFinalizers. Nothing helped. Then I saw "rectangle = {X = 1630 Y = 0 Width = 80 Height = 100}". Uhm, _Bitmap is 1707 x 1280 pixels, isn't it? And 1630+80=1710: that's 3 pixels beyond the right border of the image. Actually an ArgumentException. And then I remembered: with those managed wrappers of the unmanaged graphics API, any kind of error is translated into an OutOfMemoryException, regardless of the actual cause. Why do I always have to learn that the hard way instead of remembering it immediately? I fear the OutOfMemoryException might somewhen become the InnerException of a LostMyMindException ...

      R Offline
      R Offline
      Rob Grainger
      wrote on last edited by
      #2

      Not really the correct forum for this - I'd post it as a question if I were you.

      "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

      Richard DeemingR 1 Reply Last reply
      0
      • R Rob Grainger

        Not really the correct forum for this - I'd post it as a question if I were you.

        "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

        Richard DeemingR Offline
        Richard DeemingR Offline
        Richard Deeming
        wrote on last edited by
        #3

        It's hardly a question, given he's already found the solution. This is precisely the correct forum. :doh:


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

        B R 2 Replies Last reply
        0
        • Richard DeemingR Richard Deeming

          It's hardly a question, given he's already found the solution. This is precisely the correct forum. :doh:


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          B Offline
          B Offline
          Bernhard Hiller
          wrote on last edited by
          #4

          Oh, maybe it is:

          Quote:

          Why do I always have to learn that the hard way instead of remembering it immediately?

          And how can I be prevented from throwing a LostMyMindException? :-D

          S 1 Reply Last reply
          0
          • B Bernhard Hiller

            Oh, maybe it is:

            Quote:

            Why do I always have to learn that the hard way instead of remembering it immediately?

            And how can I be prevented from throwing a LostMyMindException? :-D

            S Offline
            S Offline
            Sascha Lefevre
            wrote on last edited by
            #5

            Bernhard Hiller wrote:

            And how can I be prevented from throwing a LostMyMindException? :-D

            Obviously, with a missing mind, you won't throw any exception any more - you would have to implement a sane observer to take care of that!

            If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

            1 Reply Last reply
            0
            • Richard DeemingR Richard Deeming

              It's hardly a question, given he's already found the solution. This is precisely the correct forum. :doh:


              "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

              R Offline
              R Offline
              Rob Grainger
              wrote on last edited by
              #6

              Indeed - note to self, read more carefully before commenting. Apologies Bernard.

              "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

              1 Reply Last reply
              0
              • B Bernhard Hiller

                A code fragment from a class used for testing purposes. The function cuts a snippet out of an image, sends it to some data transformation (the transformed data contain no reference to a bitmap), and notifies a different class that new data are available.

                        Point position = \_Motor.GetData().Position;
                        Rectangle rectangle = new Rectangle(position, Properties.ImageSize.Size);
                        Bitmap partialImage = \_Bitmap.Clone(rectangle, \_Bitmap.PixelFormat);
                        InfraredImage = \_Converter.InfraredImageFromBitmap(partialImage);
                        OnImageReceived();
                

                The function is called every few milliseconds. After a few milliseconds, Bad Things (TM) happened:

                An unhandled exception of type 'System.OutOfMemoryException' occurred in System.Drawing.dll

                - at the _Bitmap.Clone call. How could that happen? Do I have to get rid of the partialImages? I added calls to Dispose. Set it explicitely to null. Called GC.Collect. Called GC.WaitForPendingFinalizers. Nothing helped. Then I saw "rectangle = {X = 1630 Y = 0 Width = 80 Height = 100}". Uhm, _Bitmap is 1707 x 1280 pixels, isn't it? And 1630+80=1710: that's 3 pixels beyond the right border of the image. Actually an ArgumentException. And then I remembered: with those managed wrappers of the unmanaged graphics API, any kind of error is translated into an OutOfMemoryException, regardless of the actual cause. Why do I always have to learn that the hard way instead of remembering it immediately? I fear the OutOfMemoryException might somewhen become the InnerException of a LostMyMindException ...

                B Offline
                B Offline
                Brisingr Aerowing
                wrote on last edited by
                #7

                And what was the developer who came up with this smoking at the time? How on Earth is this a good idea?

                What do you get when you cross a joke with a rhetorical question? The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism. Do questions with multiple question marks annoy you???

                1 Reply Last reply
                0
                • B Bernhard Hiller

                  A code fragment from a class used for testing purposes. The function cuts a snippet out of an image, sends it to some data transformation (the transformed data contain no reference to a bitmap), and notifies a different class that new data are available.

                          Point position = \_Motor.GetData().Position;
                          Rectangle rectangle = new Rectangle(position, Properties.ImageSize.Size);
                          Bitmap partialImage = \_Bitmap.Clone(rectangle, \_Bitmap.PixelFormat);
                          InfraredImage = \_Converter.InfraredImageFromBitmap(partialImage);
                          OnImageReceived();
                  

                  The function is called every few milliseconds. After a few milliseconds, Bad Things (TM) happened:

                  An unhandled exception of type 'System.OutOfMemoryException' occurred in System.Drawing.dll

                  - at the _Bitmap.Clone call. How could that happen? Do I have to get rid of the partialImages? I added calls to Dispose. Set it explicitely to null. Called GC.Collect. Called GC.WaitForPendingFinalizers. Nothing helped. Then I saw "rectangle = {X = 1630 Y = 0 Width = 80 Height = 100}". Uhm, _Bitmap is 1707 x 1280 pixels, isn't it? And 1630+80=1710: that's 3 pixels beyond the right border of the image. Actually an ArgumentException. And then I remembered: with those managed wrappers of the unmanaged graphics API, any kind of error is translated into an OutOfMemoryException, regardless of the actual cause. Why do I always have to learn that the hard way instead of remembering it immediately? I fear the OutOfMemoryException might somewhen become the InnerException of a LostMyMindException ...

                  N Offline
                  N Offline
                  Nicholas Marty
                  wrote on last edited by
                  #8

                  Well you could have resorted to doing it in an unsafe manner because the managed wrappers are really slow. That way you would have successfully screwed with the memory :laugh:

                  1 Reply Last reply
                  0
                  • B Bernhard Hiller

                    A code fragment from a class used for testing purposes. The function cuts a snippet out of an image, sends it to some data transformation (the transformed data contain no reference to a bitmap), and notifies a different class that new data are available.

                            Point position = \_Motor.GetData().Position;
                            Rectangle rectangle = new Rectangle(position, Properties.ImageSize.Size);
                            Bitmap partialImage = \_Bitmap.Clone(rectangle, \_Bitmap.PixelFormat);
                            InfraredImage = \_Converter.InfraredImageFromBitmap(partialImage);
                            OnImageReceived();
                    

                    The function is called every few milliseconds. After a few milliseconds, Bad Things (TM) happened:

                    An unhandled exception of type 'System.OutOfMemoryException' occurred in System.Drawing.dll

                    - at the _Bitmap.Clone call. How could that happen? Do I have to get rid of the partialImages? I added calls to Dispose. Set it explicitely to null. Called GC.Collect. Called GC.WaitForPendingFinalizers. Nothing helped. Then I saw "rectangle = {X = 1630 Y = 0 Width = 80 Height = 100}". Uhm, _Bitmap is 1707 x 1280 pixels, isn't it? And 1630+80=1710: that's 3 pixels beyond the right border of the image. Actually an ArgumentException. And then I remembered: with those managed wrappers of the unmanaged graphics API, any kind of error is translated into an OutOfMemoryException, regardless of the actual cause. Why do I always have to learn that the hard way instead of remembering it immediately? I fear the OutOfMemoryException might somewhen become the InnerException of a LostMyMindException ...

                    M Offline
                    M Offline
                    Marc Clifton
                    wrote on last edited by
                    #9

                    Bernhard Hiller wrote:

                    Bad Things (TM)

                    I think Winnie the Pooh already trademarked that. :) Marc

                    Imperative to Functional Programming Succinctly Contributors Wanted for Higher Order Programming Project! Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny

                    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