Skip to main content
gamedev.net
🔒 Locked 🎮 Unity

Odd problem

Started by MilchoPenchev 11 replies 2.6k views
Original Post
MilchoPenchev
MilchoPenchev
I'm working on this project in VS2008. Until recently I was working on a winXP x86, latptop (my main pc had crashed).

A couple of days ago I got myself a new laptop with Win7 x64, and installed VS2008 on it. (I only have the 32 bit version so i installed that).

Now, when I compile the program, all goes well up to the point where the program shows up with the console... and .. stops. There's no crash, no 'program has stopped responding' nothing. It just sits there with a blank console, consuming no CPU (as far as I can tell in observing it for 2 minutes), allocating no more memory, sitting at 9mb of RAM used.

I don't have any code that might cause this, but even worse, it never seems to enter the code! This is what I reduced the main.cpp to (before it just included the commented out stuff), and it behaves exactly as described above:



//#include "Game.h"
//#include "stdlib.h"
#include <iostream>
int main(int argc, char* argv[])
{
std::cout << "MAIN IS ON!\n";
// Create a Game object
// Game *pGame = new Game();
// // start the Game
// int error = pGame->Start();
// if ( error != 0)
// {
// std::cout << "Game could not start...\n";
// system("pause");
// }
//return error;
}



I add a breakpoint to the cout, it never reaches it (which should've been obvious because the console remains blank).

The exact same thing happens with a build from my XP machine when i copy it over to my Win7 machine. So you might be thinking, project configs are wrong or something right?

Well, I copied the exact same build from my xp machine to a friend's Win7 that's also 64 bit, and it ran! Just fine! No problems what so ever!

I've also send this out to a few people to test it... it works on a Vista x86 machine, another Win7 x64 machine, but it doesn't work on one other Win7 machine.

I am at a loss here. There's gotta be something wrong with my pc... or my settings... I really don't know!

This is the last few lines from the output from the program starting. After that last line, it stops, no more output, nothing.

'Terrain Generator.exe': Loaded 'C:\Windows\SysWOW64\atiadlxy.dll'
'Terrain Generator.exe': Loaded 'C:\Windows\SysWOW64\wtsapi32.dll'
'Terrain Generator.exe': Loaded 'C:\Windows\SysWOW64\psapi.dll'
'Terrain Generator.exe': Loaded 'C:\Windows\SysWOW64\wintrust.dll'
'Terrain Generator.exe': Loaded 'C:\Windows\SysWOW64\crypt32.dll'
'Terrain Generator.exe': Loaded 'C:\Windows\SysWOW64\msasn1.dll']

I also use 11 dlls that sit in the program's folder (glew, zlib, ftgl, etc.) - but they all get loaded before this point is reached, so it doesn't hang on one of them.

If anyone can offer some advice on what could be causing this, I'd greatly appreciate it.

Thanks in advance.
popsoftheyear
popsoftheyear
When you run a debug build, then go to "Debug->Break All", look at your stack trace. That should provide a little help...
MilchoPenchev
MilchoPenchev
Just ran it. No source code can be displayed (as expected i guess),

The top of the call stack looks like this:

> ntdll.dll!77a2f861()
[Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]
ntdll.dll!77a2f861()
KernelBase.dll!76fc0816()
kernel32.dll!75941138()


I'm not sure if that means that it's effin up on ntdll.dll or on KernelBase.dll... actually considering I have no idea what either of them actually provide...

I'm going to go read on those, but if anyone has a clue =P

Edit: This would seem very related: http://connect.micro...an-x64-computer .. at least I feel like I'm on the right track now, thanks achild

Edit2: Aaand their workaround does nothing. Just noticed that in the call stack, I've got ntdll.dll listed, not ntdll32.dll, which is different than their described problem. Now what?


popsoftheyear
popsoftheyear
It's possible but I doubt it.
If you right click on the dlls without symbols, you get the option to download the symbols from MS symbol server. Once you've done this, look at your entire stack trace for a dll you do recognize. Specifically, one of the 11 dlls you said you are loading yourself. It's almost certain the culprit is one of those.
rip-off
rip-off
You could also use another tool like Process Monitor to help debug this. Do you have any global variables in your code? Their constructors run before main(), and a bug in such a constructor could cause something like this.
MilchoPenchev
MilchoPenchev

It's possible but I doubt it.
If you right click on the dlls without symbols, you get the option to download the symbols from MS symbol server. Once you've done this, look at your entire stack trace for a dll you do recognize. Specifically, one of the 11 dlls you said you are loading yourself. It's almost certain the culprit is one of those.

I have seen the 11 dlls loaded beforehand though. As I mentioned, they all get loaded before it gets to this point. I just double checked and all of them are there.
Also, I saw no option to download from MS server, though an option gives info that wntdll.pdb was not found.

Edit2: I set up the compiler to get symbols from http://msdl.microsoft.com/download/symbols. I waited until all the symbols were loaded, and then stopped it. This is the callstack's top:


> ntdll.dll!_ZwWaitForSingleObject@12() + 0x15 bytes
ntdll.dll!_ZwWaitForSingleObject@12() + 0x15 bytes
kernel32.dll!_WaitForSingleObjectExImplementation@12() + 0x43 bytes
kernel32.dll!_WaitForSingleObject@8() + 0x12 bytes
aticfx32.dll!7447fe09()
[Frames below may be incorrect and/or missing, no symbols loaded for aticfx32.dll]
aticfx32.dll!7447a4b3()


Only two dlls that I identify appear below, one is opengl32.dll, and the other is sfml-window-d.dll. From what I gather, the ZwWaitForSingleObject waits for a thread. It would seem related in that these implementations might be multi-threaded... but why does it seem to run fine on some pcs, while hanging on others? There must be something different



You could also use another tool like Process Monitor to help debug this. Do you have any global variables in your code? Their constructors run before main(), and a bug in such a constructor could cause something like this.

I do have some global vars. I don't know how any of them can cause a freezeup. None of them are included in main.cpp, as I've commented out the include, so none of them should affect the 'short' version.

Edit: Oh what the .... ! I just ran release version, with the truncated main.cpp, and it ran fine! I quickly uncommented the rest, and... back to the same problem. This now points to something caused by the code.. but the exact same code won't run in debug. Basically: In debug, no version of main.cpp runs. In release the 'short' version that only spits a single line runs, but the full doesnt. I also stopped it mid-run in release mode, only to see that it says no symbols were loaded for kernel32.dll......
rip-off
rip-off

I do have some global vars. I don't know how any of them can cause a freezeup.
[/quote]
It depends. It is a good idea to minimise the amount of complex code that runs before main, and a better idea to eliminate it entirely.


None of them are included in main.cpp, as I've commented out the include, so none of them should affect the 'short' version.
[/quote]
#include doesn't matter here. It only affects global declaration visibility in other translation units - not global definitions in the final executable.


Edit: Oh what the .... ! I just ran release version, with the truncated main.cpp, and it ran fine! I quickly uncommented the rest, and... back to the same problem. This now points to something caused by the code.. but the exact same code won't run in debug. Basically: In debug, no version of main.cpp runs. In release the 'short' version that only spits a single line runs, but the full doesnt. I also stopped it mid-run in release mode, only to see that it says no symbols were loaded for kernel32.dll......
[/quote]
Compilers are allowed remove unused global variables - even if this means that constructors with side effects won't run. I suspect that in Release mode, the optimiser is doing this to one or more of your global variables.
MilchoPenchev
MilchoPenchev

<snip>
Compilers are allowed remove unused global variables - even if this means that constructors with side effects won't run. I suspect that in Release mode, the optimiser is doing this to one or more of your global variables.


This would make sense, and I will go through and clean up my global vars. I have a few very badly declared static classes that I've been meaning to make into singletons anyway.


However, this doesn't explain why it runs on some pcs and not on others.

I did some investigation, and I *think* it won't run on Win7 home, but will run on win7 professional (and I'm guessing business since my old desktop had that and ran the, abeit older, version of the program)

Regardless, if I manage to fix it for Win7 home, and it still works on pro, it'll be a good solution. Though still perplexing.

rip-off
rip-off
I had forgotten about the different behaviour on different computers, sorry. I'd recommend something like the Process Monitor tool from Microsoft (it is free), which might give you clues as to why it is failing/succeeding on different machines.
Adam_42
Adam_42
Here's one more thing you could do to help track down the issue: When it's stopped in the debugger look at the threads window, and check the call stack for each thread. Because it's stopped on a WaitForSingleObject there's probably more than one thread involved here.

My guess would be that it's getting deadlocked on the Windows DLL loader lock.
MilchoPenchev
MilchoPenchev

Here's one more thing you could do to help track down the issue: When it's stopped in the debugger look at the threads window, and check the call stack for each thread. Because it's stopped on a WaitForSingleObject there's probably more than one thread involved here.

My guess would be that it's getting deadlocked on the Windows DLL loader lock.


That would appear to be the case:

I have 2 threads listed, main and a worker thread:


0 6400 Main Thread Main Thread _ZwWaitForSingleObject@12 Normal 0
0 6792 Worker Thread Win32 Thread _NtDelayExecution@8 Normal 0


I have no idea where this thread is spawned, nor how to trace that.


It also, again, makes me wonder why this is an issue on my pc, and not on others. And I also found out it was freezing on a friend's Win7 Professional, so my earlier theory is out the window.

Well, at least i may be on the right track (though I said that yesterday, and it didn't help =P)

Edit: I downloaded process monitor, and ran the .exe outside of VS. All the DLLs load fine, and right after they load another thread is created, after which all the events in the process are "process profiling".

The top of the stack at that point (from process monitor) looks like this:


14 KernelBase.dll CreateRemoteThreadEx + 0x161 0x771735bf C:\Windows\SysWOW64\KernelBase.dll
15 kernel32.dll CreateThread + 0x20 0x76a61ec8 C:\Windows\SysWOW64\kernel32.dll
16 aticfx32.dll AmdQueryPowerXpressDeviceInfo + 0x242fe 0x6ab4651e C:\Windows\SysWOW64\aticfx32.dll
17 aticfx32.dll AmdQueryPowerXpressDeviceInfo + 0x81b7 0x6ab2a3d7 C:\Windows\SysWOW64\aticfx32.dll
18 aticfx32.dll AmdQueryPowerXpressDeviceInfo + 0x7f04 0x6ab2a124 C:\Windows\SysWOW64\aticfx32.dll
19 aticfx32.dll AmdQueryPowerXpressDeviceInfo + 0x172d3 0x6ab394f3 C:\Windows\SysWOW64\aticfx32.dll
20 aticfx32.dll OpenAdapter + 0xf9bc 0x6ab1f29c C:\Windows\SysWOW64\aticfx32.dll
21 atigktxx.dll XopOpenLinkedAdapter + 0xa44 0x5ebd4fe4 C:\Windows\SysWOW64\atigktxx.dll
22 atigktxx.dll SetThunkProxyBypassMode + 0x33f 0x5ebd1689 C:\Windows\SysWOW64\atigktxx.dll


On related note... this seems related to what happens to me, readin up now: http://www.gamefroms....com/?tag=/SFML

EDIT2: Well, sh*t, copying the atigktxx.dll provided in a link from that site fixes it, at least when I run it outside of VS. It also talks about staticlally linking SFML, I'm going to give that a shot too. Seems there's a problem with SFML and ATI drivers - not sure what exactly it is, but it's one annoying bugger.

Thanks to everyone for your help, and your effort in figuring out this baffling problem. =)

vreality
vreality
On 9/7/2011 at 1:59 PM, MilchoPenchev said:


//#include "Game.h"
//#include "stdlib.h"
#include <iostream>
int main(int argc, char* argv[])
{
    std::cout << "MAIN IS ON!\n";
    // Create a Game object
//  Game *pGame = new Game();
//  // start the Game
//  int error = pGame->Start();
//  if ( error != 0)
//  {
//      std::cout << "Game could not start...\n";
//      system("pause");
//  }
//  return error;
}


Ok, now that you've resolved the issue, I think it's ok for me to be a jerk and point out that your main() (when un-commented-out) has a resource leak. ;^)

MilchoPenchev
MilchoPenchev

Ok, now that you've resolved the issue, I think it's ok for me to be a jerk and point out that your main() (when un-commented-out) has a resource leak. ;^)


Yes, I've realized that some time ago as well, never really fixed it, always finding myself working on other things. Partly because there is nothing outside of the Game. And windows is nice enough to clean up resources after me.

Besides I'd have to make a whole commit just for this, cause some of my commits end up having side effects and are sometimes rolled back. I'm talking mercurial-commits.

But yes, you are a jerk ;)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.