Sign in to follow this  
WuTz

My Engine isn't working in Release-mode

Recommended Posts

WuTz    100
Hi! Every time, I want to start my Engine in the Release mode (instead of debug), it crashes! Does anyone had a similar problem?

Share this post


Link to post
Share on other sites
popsoftheyear    2194
I think it's happened to everyone at some point or another.

Here are a couple common things to check for (though this is not a complete list)
- Uninitialized variables. In debug variables initialize to 0, typically, and at least on Microsoft compilers I think memory on the heap initializes to 0xCD repeatedly (or was that unused heap memory?). This means your variable which is normally valid, has any possible value in it. This goes for enums as well!
- ASSERT statements. If asserts do more than check a condition, ie they actually DO something like "ASSERT((result = Func()) == NULL);", it will NOT be executed in release builds. Both "result" will not be assigned, and "Func()" will not be called.

I'd say start there.

Share this post


Link to post
Share on other sites
Daivuk    413
Ya, we had that one often.

Look into your constructors. You have uninitialized variables. In debug it will often initialize them to garbage, and bool to true. But in Release, I think depending on your compiler configs, will automatically initialize them to zero, and bools to false. Don't rely on this anyway, always initialize them.

You probably just forgot a variable or two :). That was our case, every time!

Share this post


Link to post
Share on other sites
WuTz    100
Well, ok... What was it? What do I have to look for? :(

EDIT: Wow! so many answers, and I was still typing ;) Gotta read them first...

Share this post


Link to post
Share on other sites
Evil Steve    2017
Quote:
Original post by WuTz
Well, ok... What was it? What do I have to look for? :(
That depends what "Crash" means. If it's an access violation, what address? What line of code causes it? Are you sure all pointers are valid on that line?
If it won't even start up, it's probably manifest related
If it's a bluescreen, it's probably driver or hardware related.

Quote:
Original post by Daivuk
But in Release, I think depending on your compiler configs, will automatically initialize them to zero, and bools to false.
The compiler won't initialise them to anything - their value depends on whatever happened to be in memory before it and is essentially random.

Share this post


Link to post
Share on other sites
rip-off    10979
In Debug mode, certain things are done for you to make it easier to detect bugs. However, these have the flip side of behaving in a deterministic manner, which means that your code can end up depending on behaviour that the debug runtimes give you. An example is when you allocate or free memory, the runtime will fill it with special patterns which make it easier to discover uninitialised or release memory being used.

You also need to understand that you can attach a debugger in release mode. You can modify the default Release configuration which might make it easier to make sense of what is happening, as otherwise it will be very confusing.

Share this post


Link to post
Share on other sites
Toolmaker    967
I've had it happen too! I think you need to inspect your computer for forks and see if your code has any bugs in them. Because it's most likely that those cause the crash to happen.

Share this post


Link to post
Share on other sites
sox    488
Without posting more details it might be hard to find help. What language are you using? What output (if any) do you get?

Taking a stab in the dark: If you're coding in C or C++, the first thing you'll want to check for is uninitialized variables. The compiler usually sets all new variables to a default value like 0 in debug mode, but in release the same variables could be anything. An uninitialized bool could be equal to 23. Uninitialized pointers would incorrectly pass null checks. Dogs and cats living together, etc.

If all else fails, drop in a printf at every other line, see which is the last one that outputs. The crash will be after that line.

edit: Wow, in the time it took me to type that, five other people beat me to it with good answers. LOL

Share this post


Link to post
Share on other sites
WuTz    100
Ok. It crashes in mvcrt.dll or msvcrt.dll, something like that. I only see Assembler code, but I will take a look, what happens before that crash. And I found some uninitialized variables. Maybe it works, when I init them all. Thanks for that fast help! :)

Share this post


Link to post
Share on other sites
Evil Steve    2017
Quote:
Original post by WuTz
Ok. It crashes in mvcrt.dll or msvcrt.dll, something like that. I only see Assembler code, but I will take a look, what happens before that crash. And I found some uninitialized variables. Maybe it works, when I init them all. Thanks for that fast help! :)
If you turn on debug information for your release build you should be able to get a full call stack. Failing that, you can add some OutputDebugString() calls to see where it gets to before it crashes, and then work out what's wrong from there.

Share this post


Link to post
Share on other sites
WuTz    100
Ok. I've found the location where it crashes:


case WM_SIZE:
GetClientRect(hDlg,&MainWnd);
ViewportHW=NULL;
ViewportHW=GetDlgItem(hDlg,IDC_Viewport);
GetClientRect(ViewportHW,&ViewportWnd);
if(MainWnd.right-50>5 && MainWnd.bottom-50>5 && ViewportHW)
{
SetWindowPos(ViewportHW,NULL,40,40,MainWnd.right-50,MainWnd.bottom-50,0); ///<------------------ HERE!
}
TheScene.UpdateWindowSize();
if(wParam==SIZE_MAXIMIZED)



with that output:

(Sorry, I had to translate it from German)

One exception (first Chance) at 0x00000000 in WTech DX10.exe: 0xC0000005: Access violation.
One exception (first Chance) at 0x7787cdc9 in WTech DX10.exe: 0xC0000005: Access violation when reading at position 0x00000010.
Unhanded exception 0x7787cdc9 in WTech DX10.exe: 0xC000041D: Unhanded exception while user-recall.


I already checked the Variables in that piece of code. "ViewportHW" is strange.
The debugger says "No symbols found for ViewportHW" or so. But it IS initialized! Very strange..

Share this post


Link to post
Share on other sites
Evil Steve    2017
One exception (first Chance) at 0x7787cdc9 in WTech DX10.exe: 0xC0000005: Access violation when reading at position 0x00000010.

That means you have a null pointer, and you're accessing something 16 bytes from the start of the object. The line you mention doesn't have any pointers in it, so that can't be the line causing the crash. If you add an OutputDebugString() before and after that line, do you see the first but not the second?

What's more likely is that on the next line, TheScene.UpdateWindowSize();, TheScene is a null reference (Or is it a global?), or causes a null pointer access.

Share this post


Link to post
Share on other sites
WuTz    100
I tried the DebugOutput. This is what I get:


Before SetWindowPos()
Eine Ausnahme (erste Chance) bei 0x00000000 in WTech DX10.exe: 0xC0000005: Access violation.
Eine Ausnahme (erste Chance) bei 0x7787cdc9 in WTech DX10.exe: 0xC0000005: Zugriffsverletzung beim Lesen an Position 0x00000010.
Unbehandelte Ausnahme bei 0x7787cdc9 in WTech DX10.exe: 0xC000041D: Unbehandelte Ausnahme während eines Benutzerrückrufs.
Das Programm "[3916] WTech DX10.exe: Systemeigen" wurde mit Code 0 (0x0) beendet.


with this code:


if(MainWnd.right-50>5 && MainWnd.bottom-50>5 && ViewportHW)
{
OutputDebugString(L"Before SetWindowPos()\n");
SetWindowPos(ViewportHW,NULL,40,40,MainWnd.right-50,MainWnd.bottom-50,0);
OutputDebugString(L"After SetWindowPos()\n");
}
OutputDebugString(L"Before UpdateWindowSize()\n");
TheScene.UpdateWindowSize();
OutputDebugString(L"After UpdateWindowSize()\n");

Share this post


Link to post
Share on other sites
WuTz    100
They are local variables of the function:


LRESULT CALLBACK MainMsgProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{

RECT MainWnd,ViewportWnd;
HWND ViewportHW;
D3DXVECTOR3 HitLoc;
OPENFILENAME ofn;
WCHAR szFile[MAX_PATH];
WCHAR p[MAX_PATH];

switch(uMsg)
{
//...



Here are (or should be) the local variables:
Image and video hosting by TinyPic

The ViewportHW-Var is not there!? ???

Share this post


Link to post
Share on other sites
Daivuk    413
Where do you initialize your ViewportHW ?

EDIT: Nevermind, I was blind: ViewportHW=NULL;
ViewportHW=GetDlgItem(hDlg,IDC_Viewport);

Share this post


Link to post
Share on other sites
WuTz    100
Here:

if(MainWnd.right-50&gt;5 && MainWnd.bottom-50&gt;5 && ViewportHW)
00B6FC73 mov eax,dword ptr [esp+2Ch]
00B6FC77 mov ebp,dword ptr [__imp__SetWindowPos@28 (0B99448h)]
00B6FC7D add eax,0FFFFFFCEh
00B6FC80 cmp eax,5
00B6FC83 jle $LN41+7Eh (0B6FCCAh)
00B6FC85 mov ecx,dword ptr [esp+30h]
00B6FC89 add ecx,0FFFFFFCEh
00B6FC8C cmp ecx,5
00B6FC8F jle $LN41+7Eh (0B6FCCAh)
00B6FC91 test edi,edi
00B6FC93 je $LN41+7Eh (0B6FCCAh)
{
OutputDebugString(L"Before SetWindowPos()\n");
00B6FC95 push offset string L"Before SetWindowPos("... (0B9FD3Ch)
00B6FC9A call dword ptr [__imp__OutputDebugStringW@4 (0B99064h)]
SetWindowPos(ViewportHW,NULL,40,40,MainWnd.right-50,MainWnd.bottom-50,0);
00B6FCA0 mov edx,dword ptr [esp+30h]
00B6FCA4 mov eax,dword ptr [esp+2Ch]
00B6FCA8 push 0
00B6FCAA add edx,0FFFFFFCEh
00B6FCAD push edx
00B6FCAE add eax,0FFFFFFCEh
00B6FCB1 push eax
00B6FCB2 push 28h
00B6FCB4 push 28h
00B6FCB6 push 0
00B6FCB8 push edi
00B6FCB9 call ebp
OutputDebugString(L"After SetWindowPos()\n");
00B6FCBB mov edi,dword ptr [__imp__OutputDebugStringW@4 (0B99064h)] //MSVC++ Marks this line with a green arrow...
00B6FCC1 push offset string L"After SetWindowPos()"... (0B9FD10h)
00B6FCC6 call edi
00B6FCC8 jmp $LN41+84h (0B6FCD0h)
00B6FCCA mov edi,dword ptr [__imp__OutputDebugStringW@4 (0B99064h)]
}
OutputDebugString(L"Before UpdateWindowSize()\n");
00B6FCD0 push offset string L"Before UpdateWindowS"... (0B9FCD8h)
00B6FCD5 call edi
TheScene.UpdateWindowSize();
00B6FCD7 mov ecx,offset TheScene (0BA9BD8h)
00B6FCDC call DX10Scene::UpdateWindowSize (0B71170h)
OutputDebugString(L"After UpdateWindowSize()\n");



I don't understand those assembly stuff. :) Is this the right code?

Share this post


Link to post
Share on other sites
Evil Steve    2017
In this line:
00B6FCBB mov edi,dword ptr [__imp__OutputDebugStringW@4 (0B99064h)] //MSVC++ Marks this line with a green arrow...

What is the (32-bit) value at the memory address 0B99064h? (The address may change when you re-run).

Share this post


Link to post
Share on other sites
Evil Steve    2017
Quote:
Original post by WuTz
When I hold the MouseCursor over this address, a box pops up. It shows:

3969124

Does this helps?
That's probably just the decimal representation of the hexadecimal address. Can you open a new memory window and enter that address?

(Note: I'm clutching at straws a bit here, the only reason that address should be invalid is with some fairly significant memory corruption)

Share this post


Link to post
Share on other sites
Zipster    2365
The green arrow is where the code is going to resume, because you're actually further down the call stack. You're just looking at the address of the OutputDebugString function. I'm guessing that something inside the SetWindowPos function is crashing... are you sure you passed in all valid parameters? Or that something went wrong long ago and this is the first you're seeing of it.

Also, what's your call stack look like at the time of the crash?

Share this post


Link to post
Share on other sites
popsoftheyear    2194
If this doesn't get anywhere, I wouldn't mind seeing the entire MessageProc function. All those variables at the top of your function could be initialized to anything in release mode, so it's possible that you're using one of them somewhere in code you haven't posted yet.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this