Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Mihail121

JPEG library crashes!!!

This topic is 5586 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! I was trying to do some coding based on the JPEG code avaidable on GameTutorials.I''m doing everything like i shoud(including jpeglib.h,linking with jpeg.lib and etc.) but when i try to load a image my program crashes.I noticed that the problem is this: cinfo.err = jpeg_error_std(&jerr); //AND BELLOW IS THE PROBLEM jpeg_create_decompress(&cinfo); The jpeg_create_decompress function is craching my program.If anyone can help me...please it''s very important. Well that''s all,bye! P.S. Are there any more ways for loading JPEGs istead of the librart??? The PAIN is coming...this summer!!!In cinemas everywhere.

Share this post


Link to post
Share on other sites
Advertisement
The reason your program is crashing is prolly cause it''s writing to a pointer that hasn''t been declared or writing outside of it.

Yes, there is another way You could use OleLoadPicture(), it will take some research (took me some). Along with JPEGS you could also load some others such as BMP and GIF with the same function call in theory. Search the Microsoft SDK site and google.com for using the oleloadpicture function.

If you still desperate, email me at drarem@hotmail. com and I''ll try to help you out.

Here''s my disorganized function, use at your own risk ~

int hBmpCls::InitPIC(HDC HMemDC, LPCTSTR szFile, BOOL mask) {
HBITMAP hOldBmp;
hMemDC = HMemDC;
HANDLE hFile = CreateFile(szFile, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
DWORD dwFileSize = GetFileSize(hFile, NULL);

LPVOID pvData = NULL;
// alloc memory based on file size
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize);

pvData = GlobalLock(hGlobal);

DWORD dwBytesRead = 0;
// read file and store in global memory
BOOL bRead = ReadFile(hFile, pvData, dwFileSize, &dwBytesRead, NULL);

GlobalUnlock(hGlobal);
CloseHandle(hFile);

LPSTREAM pstm = NULL;

HRESULT hr = CreateStreamOnHGlobal(hGlobal, TRUE, &pstm);

// Create IPicture from image file
if (gpPicture)
gpPicture->Release();

// now to do the drudgework....
hr = ::OleLoadPicture(pstm, dwFileSize, FALSE, IID_IPicture, (LPVOID *)&gpPicture);
pstm->Release();
hDC = GetDC(g_hwnd);
hMemDC = CreateCompatibleDC(hDC);
hBmpPic = CreateCompatibleBitmap(hDC, 700, 650); // create bitmap
hOldBmp = (HBITMAP) SelectObject(hMemDC, hBmpPic);

long hmWidth;
long hmHeight;
gpPicture->get_Width(&hmWidth);
gpPicture->get_Height(&hmHeight);
// convert himetric to pixels
int nWidth = MulDiv(hmWidth, GetDeviceCaps(hMemDC, LOGPIXELSX), HIMETRIC_INCH);
int nHeight = MulDiv(hmHeight, GetDeviceCaps(hMemDC, LOGPIXELSY), HIMETRIC_INCH);
RECT rc;
rc.right=256;
rc.bottom=256;
rc.left=0;
rc.top=0;
// display picture using IPicture::Render
gpPicture->Render(hMemDC, 0, 0, nWidth, nHeight, 0, hmHeight, hmWidth, -hmHeight, &rc);
// SelectObject(hMemDC, hOldBmp);

// InvalidateRect(g_hwnd, NULL, TRUE);
}[/CODE]


I fseek, therefore I fam.

Share this post


Link to post
Share on other sites
Heh. I got this probleb about a week ago, I was in panic for 3-4 days. My program crashed in jpeg_create_decompress(&cinfo); line, heh. Did you see an assembly line when program crashes? I don''t know assembler very well, but something I undersood. So I found the solution, more I found many ways

1. Make your
"struct jpeg_decompress_struct cinfo;"
global, define it outside your LoadJPEG(...) function.

2. Find "code generation" tab in project settings and set "Runtime library" to "Multi-threaded DLL (/MD)"

3. The best solution find out better jpeg loading code (i selected this way). http://www.smalleranimals.com/jpegfile.htm for example

Share this post


Link to post
Share on other sites
How will i be able to ever repay you???Please tell me if there is something i can do for you.By the way tell me if you''re looking for something to do right now cause i can help you.

Bye!

The PAIN is coming...this summer!!!In cinemas everywhere.

Share this post


Link to post
Share on other sites
How will i be able to ever repay you???Please tell me if there is something i can do for you.By the way tell me if you''re looking for something to do right now cause i can help you.

Bye!

The PAIN is coming...this summer!!!In cinemas everywhere.

Share this post


Link to post
Share on other sites
Well the things are getting stranger and stranger!!!The function works in my main file(no prototype) but when i try to get the things in a class the things get really buggy!!!I''ve tried your advices but the things aren''t working.Please help!!!

The PAIN is coming...this summer!!!In cinemas everywhere.

Share this post


Link to post
Share on other sites
Well actually the things worked after 2 weeks of non-working!I found the reason i will tell it to you.DO NOT let the boolean to be defined as int.Define is at unsigned char and that''s all.I want to 10x all of you for the advices.The OleLoadPicture worked quite well but the image data retrieving functions work slower than the JPEG library.Anyway - bye!

The PAIN is coming...this summer!!!In cinemas everywhere.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!