LoadBMP terrible crash problem

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

LoadBMP terrible crash problem

Post by Asimov » June 5th, 2012, 3:59 pm

Hi Chilli,

I have been working though your LoadBMP tutorial. Anyway I got to the bit where I put the sprite on screen and that works great. So I think to myself hmm I am going to try and put my BMP on screen too.

So first of all I add this line. Now your sprite had the name surface and so for another picture I tried to name mine:
D3DCOLOR background[800 * 600];
That however didn't work, and then I renamed it
D3DCOLOR surface[800 * 600];

In the Game.cpp I have:
LoadBmp("Scanner.bmp",surface);

Then I run it with:
gfx.DrawSurface(0,0,800,600,surface);

However I get an access violation straight away and it crashes.

Any idea why.

My question is this also. Why do we need to type in 800 * 600 as it loads that information from the file anyway. So sure we could put in the variable name BitmapInfoHeader.width and BitmapInfoHeader.hieght or something. Or not put it in as all as when it is called it would already know the width and hieght of a file?

Ok second question. What is the difference between an int and an unsigned int?

Asimov
Attachments
access.jpg
(51.54 KiB) Downloaded 184 times
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: LoadBMP terrible crash problem

Post by LuX » June 5th, 2012, 4:48 pm

Might be the same problem I had? The one where the load bmp is not complete and will be fixed in lesson 21.
ʕ •ᴥ•ʔ

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: LoadBMP terrible crash problem

Post by Asimov » June 5th, 2012, 5:25 pm

Hi Lux,

Had a sneaky peak at 21 and put the line right which was wrong, and it still crashs.

int nPaddingBytesPerRow = (4 -((infoHeader.width * 3) % 4)) % 4;

@Chilli.

So I am sending my file to see if I have made any stupid mistakes.

Oh I thought I would paste all this error stuff too:
'Chili DirectX Framework.exe': Loaded 'D:\My Documents\C++\Missile Command\04_Missile Command - LoadBmp\Release\Chili DirectX Framework.exe', Symbols loaded.
'Chili DirectX Framework.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file
'Chili DirectX Framework.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file
'Chili DirectX Framework.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file
'Chili DirectX Framework.exe': Loaded 'C:\Windows\SysWOW64\d3d9.dll', Cannot find or open the PDB file
'Chili DirectX Framework.exe': Loaded 'C:\Windows\SysWOW64\msvcrt.dll', Cannot find or open the PDB file
'Chili DirectX Framework.exe': Loaded 'C:\Windows\SysWOW64\sechost.dll', Cannot find or open the PDB file
'Chili DirectX Framework.exe': Loaded 'C:\Windows\SysWOW64\rpcrt4.dll', Cannot find or open the PDB file
'Chili DirectX Framework.exe': Loaded 'C:\Windows\SysWOW64\sspicli.dll', Cannot find or open the PDB file
'Chili DirectX Framework.exe': Loaded 'C:\Windows\SysWOW64\cryptbase.dll', Cannot find or open the PDB file
'Chili DirectX Framework.exe': Loaded 'C:\Windows\SysWOW64\user32.dll', Cannot find or open the PDB file
'Chili DirectX Framework.exe': Loaded 'C:\Windows\SysWOW64\gdi32.dll', Cannot find or open the PDB file
'Chili DirectX Framework.exe': Loaded 'C:\Windows\SysWOW64\lpk.dll', Cannot find or open the PDB file
'Chili DirectX Framework.exe': Loaded 'C:\Windows\SysWOW64\usp10.dll', Cannot find or open the PDB file
'Chili DirectX Framework.exe': Loaded 'C:\Windows\SysWOW64\advapi32.dll', Cannot find or open the PDB file
'Chili DirectX Framework.exe': Loaded 'C:\Windows\SysWOW64\version.dll', Cannot find or open the PDB file
'Chili DirectX Framework.exe': Loaded 'C:\Windows\SysWOW64\d3d8thk.dll', Cannot find or open the PDB file
'Chili DirectX Framework.exe': Loaded 'C:\Windows\SysWOW64\dwmapi.dll', Cannot find or open the PDB file
'Chili DirectX Framework.exe': Loaded 'C:\Windows\SysWOW64\dsound.dll', Cannot find or open the PDB file
'Chili DirectX Framework.exe': Loaded 'C:\Windows\SysWOW64\ole32.dll', Cannot find or open the PDB file
'Chili DirectX Framework.exe': Loaded 'C:\Windows\SysWOW64\winmm.dll', Cannot find or open the PDB file
'Chili DirectX Framework.exe': Loaded 'C:\Windows\SysWOW64\powrprof.dll', Cannot find or open the PDB file
'Chili DirectX Framework.exe': Loaded 'C:\Windows\SysWOW64\setupapi.dll', Cannot find or open the PDB file
'Chili DirectX Framework.exe': Loaded 'C:\Windows\SysWOW64\cfgmgr32.dll', Cannot find or open the PDB file
'Chili DirectX Framework.exe': Loaded 'C:\Windows\SysWOW64\oleaut32.dll', Cannot find or open the PDB file
'Chili DirectX Framework.exe': Loaded 'C:\Windows\SysWOW64\devobj.dll', Cannot find or open the PDB file
'Chili DirectX Framework.exe': Loaded 'C:\Windows\SysWOW64\imm32.dll', Cannot find or open the PDB file
'Chili DirectX Framework.exe': Loaded 'C:\Windows\SysWOW64\msctf.dll', Cannot find or open the PDB file
'Chili DirectX Framework.exe': Loaded 'C:\Windows\SysWOW64\nvinit.dll', Cannot find or open the PDB file
First-chance exception at 0x012dcef7 in Chili DirectX Framework.exe: 0xC00000FD: Stack overflow.
Unhandled exception at 0x012dcef7 in Chili DirectX Framework.exe: 0xC00000FD: Stack overflow.
First-chance exception at 0x012dcef7 in Chili DirectX Framework.exe: 0xC0000005: Access violation reading location 0x00270000.
Unhandled exception at 0x012dcef7 in Chili DirectX Framework.exe: 0xC0000005: Access violation reading location 0x00270000.
The program '[4940] Chili DirectX Framework.exe: Native' has exited with code -1073741819 (0xc0000005).


Asimov
Attachments
04_Missile Command - LoadBmp.zip
(971.09 KiB) Downloaded 168 times
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: LoadBMP terrible crash problem

Post by LuX » June 5th, 2012, 5:57 pm

Couldn't find anything at a quick glance, but stack overflow might point to an endless loop? Probably not.
ʕ •ᴥ•ʔ

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: LoadBMP terrible crash problem

Post by Asimov » June 5th, 2012, 6:44 pm

Hi Lux,

Well some of the errors above are probably due to my dodgy wav file, but that isn't what is stopping it.

Well there is a stack and I presume there is too much going in the stack which makes it overflow. So perhaps the stack needs to be increased in some way.

For the life of me I can't work it out.

I have since found out that the normal stack for visual c++ 2010 is set to 1mbyte. My picture is just over that. So I think the stack does need to be increased to load my picture. I am googling how to increase the stack now. However I might be on the wrong track.

Did you like the backdrop I designed in photoshop btw?

Asimov
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: LoadBMP terrible crash problem

Post by Asimov » June 5th, 2012, 9:43 pm

Hi Chilli,

I know you like us to try and work out our own problems and I have been trying. Go back a couple of posts and you can download my program. It also has the bmp in the file too.

Anyway if you have read the previous mails every time I try and load in my picture I get a stack overflow. I can load in your little man without problems.

I thought that maybe my picture was taking up too much of the stack, so after finding out that visual C++ stack is only 1mb I increased the stack to 2mb.

My program then run without crashing, but my picture is still not being shown but all that rubbish at the bottom.

I think there is some kind of memory leak causing the stack overflow and something else is going wrong with my picture loading.

What do you think?

Asimov
Attachments
Stack.jpg
(115.73 KiB) Downloaded 173 times
backgrounimage.jpg
(32.73 KiB) Downloaded 173 times
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: LoadBMP terrible crash problem

Post by Asimov » June 5th, 2012, 9:58 pm

Hi Chilli,

I have finally solved my problem.
I was a bit quick with my last post.

After increasing my stack size to 2000000, I forgot to uncomment this line
//LoadBmp("Scanner.bmp",surface);

Now it is uncommented my program loads my bmp fine.
Next I want to get it to load from a resource file. There must be a way.

Anyway it took me from last night to today to work it out, but I finally solved it on my own. woo hoo.

Perhaps you should add a comment in your next video that if the picture fails to load and give a stack overflow to increase the stack size in visual studio. The default stack size is only 1mb.

Asimov
Attachments
stacksizedsolved.jpg
(100.03 KiB) Downloaded 173 times
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: LoadBMP terrible crash problem

Post by LuX » June 5th, 2012, 10:09 pm

Oooh sweet you got it working!
ʕ •ᴥ•ʔ

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: LoadBMP terrible crash problem

Post by chili » June 6th, 2012, 4:06 am

Nice work on figuring out that a stack overflow was the cause of your troubles and increasing the stack size to compensate. All declared variables go on the stack, so if you try to declare too many large arrays you will get an overflow.

The proper way to solve that problem is to allocate large arrays etc. in the heap rather than in the stack (this is what I've referred to before as "dynamic memory allocation"). We will do this in Lesson 22.
Chili

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: LoadBMP terrible crash problem

Post by Asimov » June 6th, 2012, 4:21 pm

Hi Chilli,

Can't wait for lesson 22 woo hoo.

Asimov
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

Post Reply