Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (degenerate_762, AndrewAMD, Ayumi), 1,321 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
DirectX n00b having CPU usage problem. #224864
09/01/08 17:41
09/01/08 17:41
Joined: Mar 2007
Posts: 677
0x00000USA
M
MrCode Offline OP
User
MrCode  Offline OP
User
M

Joined: Mar 2007
Posts: 677
0x00000USA
Hi all.

I've been experimenting with DirectX and Win32 quite recently (haven't even started getting into rendering 3D with it yet), and already I have a problem. I can't seem to figure out why, but every time I start my program (it just displays the standard blue background on a 640x480 window), my CPU usage skyrockets to 100%. And, when I close the window, the process doesn't end. I'm guessing the CPU usage thing is a common problem, as I've seen other DirectX programs that do the same thing (not 3DGS, of course, wink).

EDIT: In case anyone is interested, I'm working from this DirectX Tutorial: DirectXTutorial.com

Last edited by MrCode; 09/01/08 18:33. Reason: Added tutorial link

Code:
void main()
{
    cout << "I am MrCode,";
    cout << "hear me roar!";
    system("PAUSE");
}
Re: DirectX n00b having CPU usage problem. [Re: MrCode] #225516
09/04/08 22:27
09/04/08 22:27
Joined: Mar 2007
Posts: 677
0x00000USA
M
MrCode Offline OP
User
MrCode  Offline OP
User
M

Joined: Mar 2007
Posts: 677
0x00000USA
Sorry for the bump, but I really do need help with this. I can't figure it out on my own (the tutorial mentions nothing about 100% CPU usage).

Re: DirectX n00b having CPU usage problem. [Re: MrCode] #225645
09/05/08 14:43
09/05/08 14:43
Joined: Jul 2004
Posts: 1,924
Finland
Ambassador Offline
Serious User
Ambassador  Offline
Serious User

Joined: Jul 2004
Posts: 1,924
Finland
It aint anything dangerous, I think all apps that have a while loop with no sleep func in it use the cpu at 100%. If you add a sleep of, say 1 millisecond, the cpu usage should drop. Not sure though...

something like this on windows:

while(TRUE)
{
blah blah... your code 'n stuff
Sleep(1.0);
}

Re: DirectX n00b having CPU usage problem. [Re: Ambassador] #225674
09/05/08 18:06
09/05/08 18:06
Joined: Dec 2000
Posts: 4,608
mk_1 Offline

Expert
mk_1  Offline

Expert

Joined: Dec 2000
Posts: 4,608
Concerning your app doesn't stop: closing the dx window doesn't mean closing the app. You need a message listener and wait for a closing message (see win32 msg handling)


Follow me on twitter
Re: DirectX n00b having CPU usage problem. [Re: mk_1] #226056
09/07/08 17:05
09/07/08 17:05
Joined: Mar 2007
Posts: 677
0x00000USA
M
MrCode Offline OP
User
MrCode  Offline OP
User
M

Joined: Mar 2007
Posts: 677
0x00000USA
Ok, the CPU usage thing seems to have been mostly solved (I added a Sleep(1) and my CPU usage has been halved). As for the handling the close message, I have this code:

Code:
LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)
{
	switch(msg)
	{
		case WM_CLOSE:
			DestroyWindow(hwnd);
		case WM_DESTROY:
			PostQuitMessage(0);
			break;
		default:
			break;
	}
	return DefWindowProc(hwnd,msg,wparam,lparam);
}


I know basic Win32 (I'm up to doing GDI stuff), I'm just new to DirectX. I don't know why my messages aren't being handled correctly. Usually when I'm writing a normal Win32 program, I don't really even need the WM_CLOSE/DestroyWindow() handler. I can just use WM_DESTROY.

EDIT: ok, CPU usage thing must have been a strange coincidence, because it's still at 100%. Well, Sleep(10) makes it lower, but I'm afraid that might make the rendering FPS (for when I start doing more with 3D) drop quite a bit.

Last edited by MrCode; 09/07/08 17:16. Reason: CPU usage still problem, and more wait time could be not good

Code:
void main()
{
    cout << "I am MrCode,";
    cout << "hear me roar!";
    system("PAUSE");
}
Re: DirectX n00b having CPU usage problem. [Re: MrCode] #226124
09/08/08 05:15
09/08/08 05:15
Joined: Mar 2007
Posts: 677
0x00000USA
M
MrCode Offline OP
User
MrCode  Offline OP
User
M

Joined: Mar 2007
Posts: 677
0x00000USA
Ok, I've got the program-not-closing thing solved (I was just missing an if statement in my message loop). And apparently when my CPU usage still went up even after adding Sleep(1), that was the coincidence. Sorry if I seemed a little too presumptuous about that. I should be fine now. Thx for the suggestions, guys.


Code:
void main()
{
    cout << "I am MrCode,";
    cout << "hear me roar!";
    system("PAUSE");
}

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1