Caught in the trap again
-
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 thepartialImage
s? I added calls toDispose
. Set it explicitely tonull
. CalledGC.Collect
. CalledGC.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 anArgumentException
. And then I remembered: with those managed wrappers of the unmanaged graphics API, any kind of error is translated into anOutOfMemoryException
, regardless of the actual cause. Why do I always have to learn that the hard way instead of remembering it immediately? I fear theOutOfMemoryException
might somewhen become theInnerException
of aLostMyMindException
... -
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 thepartialImage
s? I added calls toDispose
. Set it explicitely tonull
. CalledGC.Collect
. CalledGC.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 anArgumentException
. And then I remembered: with those managed wrappers of the unmanaged graphics API, any kind of error is translated into anOutOfMemoryException
, regardless of the actual cause. Why do I always have to learn that the hard way instead of remembering it immediately? I fear theOutOfMemoryException
might somewhen become theInnerException
of aLostMyMindException
...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.
-
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.
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
-
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
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 -
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
? :-DBernhard Hiller wrote:
And how can I be prevented from throwing a
LostMyMindException
? :-DObviously, 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
-
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
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.
-
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 thepartialImage
s? I added calls toDispose
. Set it explicitely tonull
. CalledGC.Collect
. CalledGC.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 anArgumentException
. And then I remembered: with those managed wrappers of the unmanaged graphics API, any kind of error is translated into anOutOfMemoryException
, regardless of the actual cause. Why do I always have to learn that the hard way instead of remembering it immediately? I fear theOutOfMemoryException
might somewhen become theInnerException
of aLostMyMindException
...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???
-
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 thepartialImage
s? I added calls toDispose
. Set it explicitely tonull
. CalledGC.Collect
. CalledGC.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 anArgumentException
. And then I remembered: with those managed wrappers of the unmanaged graphics API, any kind of error is translated into anOutOfMemoryException
, regardless of the actual cause. Why do I always have to learn that the hard way instead of remembering it immediately? I fear theOutOfMemoryException
might somewhen become theInnerException
of aLostMyMindException
...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:
-
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 thepartialImage
s? I added calls toDispose
. Set it explicitely tonull
. CalledGC.Collect
. CalledGC.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 anArgumentException
. And then I remembered: with those managed wrappers of the unmanaged graphics API, any kind of error is translated into anOutOfMemoryException
, regardless of the actual cause. Why do I always have to learn that the hard way instead of remembering it immediately? I fear theOutOfMemoryException
might somewhen become theInnerException
of aLostMyMindException
...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