Mystery.... 
Author Message
 Mystery....

    I'm writing a simple 2D rendering engine for a game. The framework is
done but there's something wrong, that I can't figure out. The engine is
actually a derivative of a CWnd and handles paint, timer and mouse events.
In the game you can open some windows so there can be some instances of the
engine. The problem is that when first started it runs perfectly - during an
animation with 200 objects the CPU usage is 5%-10%. But when the window
which is the owner of the engine is closed and opened several times, after
the 3rd or 4th try the CPU usage during the same animation goes up to 100%.
The code in both cases is the same and I can't understand how that is
possible. I think some resources probably get exhausted, but what kind of
resources can cause that effect? The count of the GDI handles and the memory
used by the engine stay the same during all tries. Another thing is that
when the CPU goes to 100%, the kernel CPU time is up to 100% too, which I
guess means that it slows down during API calls, but I must say again, that
this is the absolutely SAME code each try. And the most suspicios thing is
that when I drag another window over the window with the engine a little
bit, just to hide 10% of it, the CPU goes to 5%-10% again.
    I'll appreciate any opinions that could lead to the reason for this.
Thanks in advance.


Sat, 25 Jun 2005 16:20:15 GMT  
 Mystery....
Hi Alexander,

Just a thought, but have you tried to break in the de{*filter*} while your app
is thrashing? Just hit F12 in the IDE, open up a call stack window and cycle
through each of your threads (using the menu's Debug>Threads to give each
thread a chance to get focus in the de{*filter*}). Then you can step through
each thread for a few calls and hopefully see some sort of endless loop or
something. It almost sounds as if you have a WM_PAINT handler that is not
calling BeginPaint / EndPaint properly (or not properly using its CPaintDC,
which calls those for you). In cases like that, Windows will just keep
sending WM_PAINT over and over again.

Regards,
Mike


Quote:
>     I'm writing a simple 2D rendering engine for a game. The framework is
> done but there's something wrong, that I can't figure out. The engine is
> actually a derivative of a CWnd and handles paint, timer and mouse events.
> In the game you can open some windows so there can be some instances of
the
> engine. The problem is that when first started it runs perfectly - during
an
> animation with 200 objects the CPU usage is 5%-10%. But when the window
> which is the owner of the engine is closed and opened several times, after
> the 3rd or 4th try the CPU usage during the same animation goes up to
100%.
> The code in both cases is the same and I can't understand how that is
> possible. I think some resources probably get exhausted, but what kind of
> resources can cause that effect? The count of the GDI handles and the
memory
> used by the engine stay the same during all tries. Another thing is that
> when the CPU goes to 100%, the kernel CPU time is up to 100% too, which I
> guess means that it slows down during API calls, but I must say again,
that
> this is the absolutely SAME code each try. And the most suspicios thing is
> that when I drag another window over the window with the engine a little
> bit, just to hide 10% of it, the CPU goes to 5%-10% again.
>     I'll appreciate any opinions that could lead to the reason for this.
> Thanks in advance.



Sat, 25 Jun 2005 23:32:46 GMT  
 Mystery....
Hi Michael,
    I already have tried to break while having high CPU, but the application
has at about 9 threads and most of them are stopped in their message loops
during the break. Another thing is that it usually stops in assembly code
and I don't know it so well so I can't understand exactly what's going on.
    I checked the CPaintDC object that I use and it's used properly (I mean
it's created only if the update region is not empty). But I find it strange
to have a problem like this, because it would happen always or at least more
often over the same situation and the same source.
    I don't use any static or global objects in the engine, except for one
pooler, but it's singleton -  so there's nothing that gets reused improperly
during creation of multiple instances one after another.
    The good news is that either my computer is not working properly, or my
windows, or the de{*filter*} - I don't know which of them, because when I tested
the same thing under different computer, which runs under XP everything
works just fine. (I'm running under Win 2k)
    Thank you anyway. I really appreciate it.



Quote:
> Hi Alexander,

> Just a thought, but have you tried to break in the de{*filter*} while your app
> is thrashing? Just hit F12 in the IDE, open up a call stack window and
cycle
> through each of your threads (using the menu's Debug>Threads to give each
> thread a chance to get focus in the de{*filter*}). Then you can step through
> each thread for a few calls and hopefully see some sort of endless loop or
> something. It almost sounds as if you have a WM_PAINT handler that is not
> calling BeginPaint / EndPaint properly (or not properly using its
CPaintDC,
> which calls those for you). In cases like that, Windows will just keep
> sending WM_PAINT over and over again.

> Regards,
> Mike



Sun, 26 Jun 2005 01:04:09 GMT  
 Mystery....

Quote:
>     The good news is that either my computer is not working properly, or
my
> windows, or the de{*filter*} - I don't know which of them, because when I
tested
> the same thing under different computer, which runs under XP everything
> works just fine. (I'm running under Win 2k)

I think it is more likely that your code is at fault than your computer.
Just
because it works on one machine doesn't mean your code is correct, it
just means that the problem doesn't show up on that machine.

I'm afraid I don't know what the problem with your code is.

--
This posting is provided "AS IS" with no warranties, and confers no rights.


Quote:
> Hi Michael,
>     I already have tried to break while having high CPU, but the
application
> has at about 9 threads and most of them are stopped in their message loops
> during the break. Another thing is that it usually stops in assembly code
> and I don't know it so well so I can't understand exactly what's going on.
>     I checked the CPaintDC object that I use and it's used properly (I
mean
> it's created only if the update region is not empty). But I find it
strange
> to have a problem like this, because it would happen always or at least
more
> often over the same situation and the same source.
>     I don't use any static or global objects in the engine, except for one
> pooler, but it's singleton -  so there's nothing that gets reused
improperly
> during creation of multiple instances one after another.
>     The good news is that either my computer is not working properly, or
my
> windows, or the de{*filter*} - I don't know which of them, because when I
tested
> the same thing under different computer, which runs under XP everything
> works just fine. (I'm running under Win 2k)
>     Thank you anyway. I really appreciate it.



> > Hi Alexander,

> > Just a thought, but have you tried to break in the de{*filter*} while your
app
> > is thrashing? Just hit F12 in the IDE, open up a call stack window and
> cycle
> > through each of your threads (using the menu's Debug>Threads to give
each
> > thread a chance to get focus in the de{*filter*}). Then you can step through
> > each thread for a few calls and hopefully see some sort of endless loop
or
> > something. It almost sounds as if you have a WM_PAINT handler that is
not
> > calling BeginPaint / EndPaint properly (or not properly using its
> CPaintDC,
> > which calls those for you). In cases like that, Windows will just keep
> > sending WM_PAINT over and over again.

> > Regards,
> > Mike



Sun, 26 Jun 2005 04:54:49 GMT  
 Mystery....
Hi Alexander,

Could it possibly have anything to do with the graphics card drivers? Do you
have the latest?

--
Kim Gr?sman, Visual C++ MVP
http://www.*-*-*.com/


Quote:
> Hi Michael,
>     I already have tried to break while having high CPU, but the
application
> has at about 9 threads and most of them are stopped in their message loops
> during the break. Another thing is that it usually stops in assembly code
> and I don't know it so well so I can't understand exactly what's going on.
>     I checked the CPaintDC object that I use and it's used properly (I
mean
> it's created only if the update region is not empty). But I find it
strange
> to have a problem like this, because it would happen always or at least
more
> often over the same situation and the same source.
>     I don't use any static or global objects in the engine, except for one
> pooler, but it's singleton -  so there's nothing that gets reused
improperly
> during creation of multiple instances one after another.
>     The good news is that either my computer is not working properly, or
my
> windows, or the de{*filter*} - I don't know which of them, because when I
tested
> the same thing under different computer, which runs under XP everything
> works just fine. (I'm running under Win 2k)
>     Thank you anyway. I really appreciate it.



Sun, 26 Jun 2005 19:19:25 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Timer Offset Mystery under .NET

2. Application.Exit() mystery

3. build this string mystery

4. McMalloc: Mystery of the memory

5. Obfuscated C And Other Mysteries

6. MISTAKE mystery code

7. Mystery Windows DLL

8. Local initialization mysteries

9. Stack Overflow Exception Mystery..

10. A minor mystery solved

11. Mystery function

12. Mystery error

 

 
Powered by phpBB® Forum Software