R
Roger Crawfis
Hopefully this is the right newsgroup. I figured you guys would be the best
experts on this.
I am learning C# and .NET and went a little crazy with the events. Now I am
not sure how to isolate this problem. Here is my architecture, I have:
1. an OpenGLPanel class derived from UserControl that handles the repainting
using OpenGL. A render event is published for subscribers to paint into the
window.
2. a Manipulator class that handles mouse and keyboard events to cause
rotations, scales, etc. using events.
3. a Camera class that rotates, zooms, etc. based on any subscriptions to a
Manipulator and posts view update events.
Okay, simple scenario, I have a form with two OpenGLPanels, visible. Each
has a camera and listens for the camera events. The camera listen for the
manipulator events. The manipulator listen's for the form's mouse and
keyboard events (a complete cycle!!!!!). The main form has a method to draw
an object and subscribes to the OpenGLPanel's render event.
Things work great in a serial world. I even could attach a manipulator to
both cameras, etc. Pretty cool!! I was just started to really like this new
environment. I decided to switch from just firing the event to doing an
asynchronous call (as a first step to remoting the camera). I would really
like a OneWay approach for the camera, but both of these destroy the OpenGL
context or something. Right now, I am only processing the camera updates to
the OpenGLPanel's asynchronously, but would suspect that all of the mouse
events are also handles asynchronously. The render events will always be
sequential, but I would also like to have the manipulator events happen
OneWay to the cameras.
The problem with the render made sense to me at first, if I set the active
rendering context and then the thread got bumped, etc. I added
[Synchronization] in front of the OpenGLPanel class. It and the Form1 class
are the only ones that make OpenGL calls. I get one of the Panels not
redrawing. The calls are all happening, but I think something in the state
got messed up. The other panel starts off blank and then when I force a
particular event (set of events) it shows up and works properly. Changing
the subscription order seems to reverse which panel works and which one does
not. Pretty much every method is atomic and nothing is left in a bad state
(if I programmed it correctly). I decided to add [Synchronization] before
all of my classes, but nothing helps. BTW, I never create any threads, just
those (two) from a default Windows form. I am running on a single CPU
machine.
Okay, now for the question(s):
1) Is this a correct way to protect a shared system resource?
2) Is there a better way?
3) Any guesses on what might be going on before I attempt to boil the code
down to a simpler test case (or assugn it as a midterm question )?
4) I can see the High priority thread preempting the other thread, such that
mouse calls are continually triggered before any updates to the display can
finish. I would expect, that after I release the mouse and wait idle for
awhile the display would redraw.
Some other questions on multi-tasking:
4) My counter indicates I am still getting 70-90 frames-per-second, but
visually, it is more like 1-2 fps.
5) Are the events queued, or do I always just get the most recent event? If
they are queued, is there an easy way to only get the latest. I want to
display with the latest camera, not march thru all of the events.
6) How does a Windows form split up its tasks into threads? I know you want
the user interface thread to be at a high priority, is everything in the
form then issued at a low priority? This would include control updates and
displays, so ...
This is all educational code for my own amusement, so I happy to give the
entire project to anyone interested in looking into this further.
Roger Crawfis
Associate Professor
Computer Science and Engineering Dept.
The Ohio State University
experts on this.
I am learning C# and .NET and went a little crazy with the events. Now I am
not sure how to isolate this problem. Here is my architecture, I have:
1. an OpenGLPanel class derived from UserControl that handles the repainting
using OpenGL. A render event is published for subscribers to paint into the
window.
2. a Manipulator class that handles mouse and keyboard events to cause
rotations, scales, etc. using events.
3. a Camera class that rotates, zooms, etc. based on any subscriptions to a
Manipulator and posts view update events.
Okay, simple scenario, I have a form with two OpenGLPanels, visible. Each
has a camera and listens for the camera events. The camera listen for the
manipulator events. The manipulator listen's for the form's mouse and
keyboard events (a complete cycle!!!!!). The main form has a method to draw
an object and subscribes to the OpenGLPanel's render event.
Things work great in a serial world. I even could attach a manipulator to
both cameras, etc. Pretty cool!! I was just started to really like this new
environment. I decided to switch from just firing the event to doing an
asynchronous call (as a first step to remoting the camera). I would really
like a OneWay approach for the camera, but both of these destroy the OpenGL
context or something. Right now, I am only processing the camera updates to
the OpenGLPanel's asynchronously, but would suspect that all of the mouse
events are also handles asynchronously. The render events will always be
sequential, but I would also like to have the manipulator events happen
OneWay to the cameras.
The problem with the render made sense to me at first, if I set the active
rendering context and then the thread got bumped, etc. I added
[Synchronization] in front of the OpenGLPanel class. It and the Form1 class
are the only ones that make OpenGL calls. I get one of the Panels not
redrawing. The calls are all happening, but I think something in the state
got messed up. The other panel starts off blank and then when I force a
particular event (set of events) it shows up and works properly. Changing
the subscription order seems to reverse which panel works and which one does
not. Pretty much every method is atomic and nothing is left in a bad state
(if I programmed it correctly). I decided to add [Synchronization] before
all of my classes, but nothing helps. BTW, I never create any threads, just
those (two) from a default Windows form. I am running on a single CPU
machine.
Okay, now for the question(s):
1) Is this a correct way to protect a shared system resource?
2) Is there a better way?
3) Any guesses on what might be going on before I attempt to boil the code
down to a simpler test case (or assugn it as a midterm question )?
4) I can see the High priority thread preempting the other thread, such that
mouse calls are continually triggered before any updates to the display can
finish. I would expect, that after I release the mouse and wait idle for
awhile the display would redraw.
Some other questions on multi-tasking:
4) My counter indicates I am still getting 70-90 frames-per-second, but
visually, it is more like 1-2 fps.
5) Are the events queued, or do I always just get the most recent event? If
they are queued, is there an easy way to only get the latest. I want to
display with the latest camera, not march thru all of the events.
6) How does a Windows form split up its tasks into threads? I know you want
the user interface thread to be at a high priority, is everything in the
form then issued at a low priority? This would include control updates and
displays, so ...
This is all educational code for my own amusement, so I happy to give the
entire project to anyone interested in looking into this further.
Roger Crawfis
Associate Professor
Computer Science and Engineering Dept.
The Ohio State University