Problem with CBitmap (MFC prog)
-
I have a problem with CBitmaps. I want to copy one bitmap into another, which wouldn’t be a problem if I didn’t use multithreading. My situation is this: I made a program which calculates the Mandelbrot fractal. I have a bitmap in which the picture is saved and which is used to make it display in the window. The function calculating the fractal creates a temporary bitmap and after it has finished, I want to copy the temporary image to the main image which is used to display but I receive either an assertion error or the bitmap becomes blank (white). The problem only occurs when I run the function in a separate thread but if I don’t use multithreading, all works fine… I tried a lot of things (for example using the BitBlt-function or working with pointers to the bitmaps) but none really helps. The weird thing is, that even if I get the assertion error, the program displays the bitmap correctly (only on some comps!). I gave it to a friend to test it (he has the same OS as me, Win2000 Professional) but it didn’t show the image (only a white window). It also seems to work correctly under WinXP. I’m running out of ideas, so please give me some suggestions what to do
-
I have a problem with CBitmaps. I want to copy one bitmap into another, which wouldn’t be a problem if I didn’t use multithreading. My situation is this: I made a program which calculates the Mandelbrot fractal. I have a bitmap in which the picture is saved and which is used to make it display in the window. The function calculating the fractal creates a temporary bitmap and after it has finished, I want to copy the temporary image to the main image which is used to display but I receive either an assertion error or the bitmap becomes blank (white). The problem only occurs when I run the function in a separate thread but if I don’t use multithreading, all works fine… I tried a lot of things (for example using the BitBlt-function or working with pointers to the bitmaps) but none really helps. The weird thing is, that even if I get the assertion error, the program displays the bitmap correctly (only on some comps!). I gave it to a friend to test it (he has the same OS as me, Win2000 Professional) but it didn’t show the image (only a white window). It also seems to work correctly under WinXP. I’m running out of ideas, so please give me some suggestions what to do
-
I have a problem with CBitmaps. I want to copy one bitmap into another, which wouldn’t be a problem if I didn’t use multithreading. My situation is this: I made a program which calculates the Mandelbrot fractal. I have a bitmap in which the picture is saved and which is used to make it display in the window. The function calculating the fractal creates a temporary bitmap and after it has finished, I want to copy the temporary image to the main image which is used to display but I receive either an assertion error or the bitmap becomes blank (white). The problem only occurs when I run the function in a separate thread but if I don’t use multithreading, all works fine… I tried a lot of things (for example using the BitBlt-function or working with pointers to the bitmaps) but none really helps. The weird thing is, that even if I get the assertion error, the program displays the bitmap correctly (only on some comps!). I gave it to a friend to test it (he has the same OS as me, Win2000 Professional) but it didn’t show the image (only a white window). It also seems to work correctly under WinXP. I’m running out of ideas, so please give me some suggestions what to do
-
I have a problem with CBitmaps. I want to copy one bitmap into another, which wouldn’t be a problem if I didn’t use multithreading. My situation is this: I made a program which calculates the Mandelbrot fractal. I have a bitmap in which the picture is saved and which is used to make it display in the window. The function calculating the fractal creates a temporary bitmap and after it has finished, I want to copy the temporary image to the main image which is used to display but I receive either an assertion error or the bitmap becomes blank (white). The problem only occurs when I run the function in a separate thread but if I don’t use multithreading, all works fine… I tried a lot of things (for example using the BitBlt-function or working with pointers to the bitmaps) but none really helps. The weird thing is, that even if I get the assertion error, the program displays the bitmap correctly (only on some comps!). I gave it to a friend to test it (he has the same OS as me, Win2000 Professional) but it didn’t show the image (only a white window). It also seems to work correctly under WinXP. I’m running out of ideas, so please give me some suggestions what to do
I presume, you are having problems with multi-threading. 'A thread is supposed to access only those objects which it has created'. If you are trying to copy the new bitmap from the processing thread( not the main thread ) to the Bitmap object created by your main thread, then you have a problem. A workaround would be, to use user-defined windows messages after you are finished with your processing, and thereby notifying your main thread, to copy the newly created bitmap to the original one. Hope this helps!!! "A robust program is resistant to errors -- it either works correctly, or it does not work at all; whereas a fault tolerant program must actually recover from errors."
-
I presume, you are having problems with multi-threading. 'A thread is supposed to access only those objects which it has created'. If you are trying to copy the new bitmap from the processing thread( not the main thread ) to the Bitmap object created by your main thread, then you have a problem. A workaround would be, to use user-defined windows messages after you are finished with your processing, and thereby notifying your main thread, to copy the newly created bitmap to the original one. Hope this helps!!! "A robust program is resistant to errors -- it either works correctly, or it does not work at all; whereas a fault tolerant program must actually recover from errors."
I thought of what you mentioned but I found another way to get the program nearly working as I want. I use the PeekMessage-function in the calculation function. This works properly but if you click in the menu, the calculation will stop until you leave it. But I'm statisfied how it works now. And of course thanks to all who posted suggestions :)