LoadImage troubles?
BlitzMax Forums/BlitzMax Programming/LoadImage troubles?
| ||
I have an issue with loading images. Some will load correctly, others will not. If I have an image eg. test.image, that may load correctly, but if I copy that image to test2.image, that may not load correctly and will deliver an exception when I attempt to draw the image.tempimage:TImage = safeLoadImage("test.png") tempimage2:TImage = LoadImage("test2.png") Test2.png is a copy of test.png. Any ideas why this might be happening? It also happens with a safeloadimage() which is a quick and dirty error checking wrapper for loadimage. |
| ||
More info please! describe the whole process of making a copy of test.png? |
| ||
The md5 checksum is the same. It appears to be my wrapped function that is failing on the image with a number in the title. Function safeloadimage:TImage(a$) tempimage:TImage = LoadImage(a$) Print "trying image " + a$ DrawImage tempimage, 0,0 Return tempimage End Function Last edited 2012 |
| ||
I'd suspect you're not using Strict or SuperStrict as the first line in you code, this will highlight any potential incorrect variable assingments ( ie tempimage ) |
| ||
Using 'Local tempimage:TImage' may fix your current issue, or highlight another cause. Last edited 2012 |
| ||
There have been times I've seen where if a variable is a local it may get freed by the garbage collector when it shouldn't, and my only fix for it was to make something a Global ... so at least make it a local first and try it, then if not try it as a global. |
| ||
Is there any canonical way to make sure we have correctly loaded an image? Loadimage() has been one of my greatest sticking points with Blitzmax for some reason and I'm trying to wrap it in a safety tester that doesn't involve an actual draw attempt (though that might not be the worst outcome.) |
| ||
Is there any canonical way to make sure we have correctly loaded an image? You should be able to use something like :- Local Image:TImage = LoadImage(ImageFile$) 'Check if image loaded ok If Image Print "Image Loaded" Else Print "Image didn't Load" EndIf |
| ||
just do: [monkeycode] Function safeloadimage:TImage(a$) tempimage:TImage = LoadImage(a$) If tempimage = null Print "Unable to Load Image "+a$ EndIf Return tempimage End Function [/monkeycode] [edit] ups too slow. Last edited 2012 |
| ||
+1, fast delivery, would ask question of again. A +++ |