Crashing upon new Gdiplus::Image()

Hello everybody! Yesterday I had posted about a problem I was having creating Gdiplus::Image's. I have a related issue now, where the call to
Gdiplus::Image::Image(const WCHAR *filename, BOOL useEmbeddedColorManagement)
crashes the program.

Here is the code that calls this function:
m_pImage = new Gdiplus::Image(a_ImagePath);, where m_pImage is a pointer to a Gdiplus::Image and a_ImagePath is a const wchar_t* to a valid path.

When the program is compiled and run, the actual window does not show up, and half of the time I get a popup box saying the program has stopped working, etc. Under more details it points to an XML file which supposedly has more details on the error, which I pasted here: http://pastebin.com/hGXM6g06 .

I have used my IDE's debugger (Code::Blocks), and it segfaults at the constructor call for the Gdiplus::Image constructor. Thank you for your help, let me know if I can provide any more information.
Last edited on
Make sure a_ImagePath is a valid pointer - Windows API Calls many times don't check the validity of the pointers.
If there's a problem, either you're out of ram, you previously did bad allocations with another block of memory, or a_ImagePath is a bad pointer.
Last edited on
Thanks, I'll play around with the path, I'll post on how it went.
There are no memory leaks, and I'm almost positive it is a valid pointer pointing to the correct path, and I'm still crashing. Any ideas?
I really don't know. Standing to the other topic, m_pImage is in another class, right? Can I see how the class is declared in your code?
Like:
1
2
3
4
5
class Test {};

//...
Test * pT = new Test; // <-- This line 
Test t; // <-- or This 


Because, if it's not directly like this, it may be crashing because of a bad 'this' pointer.

About this, try putting a message box both before and after m_pImage = new Gdiplus::Image(a_ImagePath);
like:
1
2
3
MessageBoxW(NULL,L"Error is NOT before Constructor",L"Info",0,0);
m_pImage = new Gdiplus::Image(a_ImagePath);
MessageBoxW(NULL,L"Error is AFTER Constructor",L"Info",0,0);

(Even if I'm partially sure you already did this)
Here is a pastebin of the entire class. m_pImage is a member variable: http://pastebin.com/62xA3h2M

And yes, I've done that, and it fails before the second messagebox. Also, the debugger call stack shows that it fails at that call.
Please try the same code in Visual Studio and see if it works. It could be a problem with libgdiplus.a and MinGW, GDI+ is a C++ API, unlike any other win32 api's, there are different rules.
Usually I'm fully against Visual Studio, but I'll try anything. I'll report back when I've downloaded and compiled.

Thanks again for all of your continued help with this issue!
Last edited on
Try making a little test:

1
2
// In your entrypoint:
Gdiplus::Image * pImage = new Gdiplus::Image(L"imagepath here");


And see if it bugs. If it does, it's a GDI+/Library problem. If it doesn't, you must have got problems with your class's memory allocation, which is really weird as you initialize other variables before the image, and you don't notice any other crash.
Good news! It bugged out with the same problem, therefor it's a GDI+/Library problem! What might I do to solve this? Is there any way to check if the imagepath is valid?
Last edited on
Did you tried with Visual Studio ?

Saying that the bug is inside GDI+ when using a non supported compiler is not a good thing.
Try checking like:
1
2
3
4
5
FILE * pFile = fopen("imagepath here","rb");
if(!pFile)
    MessageBoxW(NULL,L"Invalid Image!",L"Error",MB_ICONERROR);
else
    MessageBoxW(NULL,L"Valid!",L"Info",MB_ICONASTERISK);


Or look into GetFileAttributes: http://msdn.microsoft.com/en-us/library/windows/desktop/aa364944(v=vs.85).aspx
Last edited on
Topic archived. No new replies allowed.