"Curiouser and curiouser.", said Alice. "WTF?!", said Joe.




The following SDK program works fine on my Win2k PC.
I start trying it out on a WinXP machine:
Things are looking bad now: it will only run in debug build. In release
build it just exits (no crash, just doesn't start properly).
I track it down to the part marked with "THE REALLY IMPORTANT BIT IS
HERE" (see psuedo code, below). (I couldn't find the point of failure,
because my attempt at logging each point just caused everything to work
again (hmmm...)).

WITHOUT that code block, the program just exists prematurely.
WITH that code block, the program runs fine (note that the block is
AFTER the message pump).
If I move the code block in front of the message pump, it still works.
IF I remove the volatile keyword, the program stops working again.
If I remove huge chunks of other code (not shown), it makes no
difference.

Is it a thread issue with directX being initialised in a separate thread
from WinMain?
If I don't create the thread, I get the same behaviour as described above.
I'm using the multithreaded libs.
I could leave in the volatile loop, but I don't like not knowing why.
If I build with optimisations turned off, I get the same behaviour.
In fact, just tested it with for(x= 0; x < 1; x++){}; removed (leaving only
the volatile declaration - unreferrenced variable), and with optimisations
turned off, it had the same effect (program worked). With optimisation on,
it looks like it's been optimised away (program stops working).

So, what the frig is going on? Any ideas?

pseudo code:
WinMain(){

CreateEvent to check for previous existance.

Read and Write a couple of DWORDS to the registry

Register a Window Class

hwndApp= CreateWindow

_beginthreadex (myThreadProc)

check current user's locale.

Add a tray icon

// normal message loop stuff
MSG msg;

ZeroMemory(msg)

while(msg != WM_QUIT){
PeekMessage()
TranslageMessage()
DispatchMessage()
}

// THE REALLY IMPORTANT BIT IS HERE.
{
volatile int x;
for(x= 0; x < 1; x++){};
}

}

myThreadProc(){
set up directx.
etc.
}


.



Relevant Pages