TheVoid
Community Member

Posts: 7
|
 |
« on: January 21, 2008, 07:44:51 AM » |
|
Using the TV3D 6.5 c# template, when you maximise the window using the maximise button in the top right hand corner of the form and then close the application using the form's close button, the application throws an exception.
In addition, when I maximise the form I can hear my computer emitting a high pitched sound (I have good hearing) as though it is looping over something intensely.
|
|
|
|
|
Logged
|
|
|
|
Toaster
Community Member

Posts: 377
|
 |
« Reply #1 on: January 21, 2008, 09:11:54 AM » |
|
Yep this is a bug in either the code or the engine. It happens in any program I make if you maximize the window and then close the window it will give you an exception.  -Toaster
|
|
|
|
|
Logged
|
|
|
|
|
ZaPPZion
|
 |
« Reply #2 on: January 21, 2008, 10:36:08 AM » |
|
Ahh, i was wondering why my program sometimes gave that error;) anyway, try{Application.run(frmMain);}catch{} is a way to discard the exception:). I know this doesnt solve the bug, it just stops the error message 
|
|
|
|
|
Logged
|
|
|
|
|
SylvainTV
|
 |
« Reply #3 on: January 21, 2008, 04:12:45 PM » |
|
What does it say in the debug file when you get the error ? That's not normal at all for something as simple as that 
|
|
|
|
|
Logged
|
|
|
|
|
ZaPPZion
|
 |
« Reply #4 on: January 21, 2008, 04:22:38 PM » |
|
there's nothing in the debug file. This is the exception I get:  By the way, I'm using 4 viewports, might be one of the reasons? though this seems like something else.
|
|
|
|
|
Logged
|
|
|
|
TheVoid
Community Member

Posts: 7
|
 |
« Reply #5 on: January 22, 2008, 02:37:52 AM » |
|
I get the error even just with the template and no modifications.
And as I mentioned, I can hear my computer really working hard on something when I maximise. Can't be sure if that's related to the bug but it could be.
As you can see from ZaPPZion's post, the error says that the app has tried to access a disposed object (the form itself).
|
|
|
|
|
Logged
|
|
|
|
|
SylvainTV
|
 |
« Reply #6 on: January 22, 2008, 01:50:02 PM » |
|
About the noise, I think that's the CPU and GPU that are working a lot because of the big maximised rendering size. You should see if it still does it if you enable VSync ?
I will check the crash bug though.
|
|
|
|
|
Logged
|
|
|
|
TheVoid
Community Member

Posts: 7
|
 |
« Reply #7 on: January 23, 2008, 03:11:46 AM » |
|
Ah yes, thanks Sylvain (I was running in 1920 by 1200 at over 2000 fps, no wonder it was freaking out). With vsync in full screen it doesn't make that noise. Thanks alot for sorting that out, and for the great forum support.
Does anyone know if there is an equivalent to vsync (or some sensible way to limit the fps) for windowed mode?
|
|
|
|
|
Logged
|
|
|
|
Toaster
Community Member

Posts: 377
|
 |
« Reply #8 on: January 23, 2008, 06:15:34 AM » |
|
I am not sure if this will work but you can go to your nvidia display panel and change the vsync to on all the time. I am not sure if this works in windowed mode and the ATI control panel should have the same thing.
-Toaster
|
|
|
|
|
Logged
|
|
|
|
pvel
Community Member

Posts: 5
|
 |
« Reply #9 on: January 23, 2008, 01:46:46 PM » |
|
Hello, I ran into the same problem with the maximized form mentioned in this thread. I created a solution that I think is elegant and works well, so I thought I would share it. This is the standard barebones program that shows the FPS in the top left corner, so no unnecessary clutter. This also correctly closes when the user presses the escape key. A last thing that's worth mentioning is that it does not use Application.doEvents(), which probably makes a lot of people feel better ;-) public partial class MainForm : Form { AutoResetEvent state = new AutoResetEvent(false); private TVEngine engine; private TVInputEngine input; private bool continueRunning = true;
[STAThread] public static void Main() { Application.Run(new MainForm()); }
public MainForm() { InitializeComponent(); }
private void MainWindow_Load(object sender, EventArgs e) { engine = new TVEngine(); engine.DisplayFPS(true); engine.Init3DFullscreen(800, 600, 32); //fullscreen mode //engine.Init3DWindowed(pictureBox.Handle); //windowed mode
input = new TVInputEngine(); input.Initialize(true, true);
this.Show(); this.Focus();
ThreadPool.QueueUserWorkItem(new WaitCallback(run), state);
}
private void MainWindow_FormClosing(object sender, FormClosingEventArgs e) { if (continueRunning) { continueRunning = false;
state.WaitOne();
engine.ReleaseAll(); } }
private void run(object stateObject) { bool escapePressed = false;
while (continueRunning) { engine.Clear(false); engine.RenderToScreen();
if (input.IsKeyPressed(MTV3D65.CONST_TV_KEY.TV_KEY_ESCAPE)) { escapePressed = true; continueRunning = false; } }
if(escapePressed) { this.Invoke((MethodInvoker)delegate { this.Close(); }); }
((AutoResetEvent)stateObject).Set(); } }
|
|
|
|
« Last Edit: January 23, 2008, 05:49:50 PM by pvel »
|
Logged
|
|
|
|
pvel
Community Member

Posts: 5
|
 |
« Reply #10 on: January 29, 2008, 04:52:55 PM » |
|
Actually, I realized now that this problem is a lot easier to solve by simply not having the render code in the Form class.. Just create the Form from your central class (I believe most people call that class Core), and use that Form from there.. That way you don't run into the problem of having to use the Close() function from the Form's Load() function (where the render loop is), which isn't allowed. The solution I provided earlier works, but it's probably a lot simpler to just have the Form class not do anything important and just keep it as an external place to render your game :-P
|
|
|
|
|
Logged
|
|
|
|
|
SylvainTV
|
 |
« Reply #11 on: January 31, 2008, 05:10:20 PM » |
|
Better idea indeed !
The form should just be here to init in it. Then use a Module and/or classes to have your game loop.
|
|
|
|
|
Logged
|
|
|
|
|
ZaPPZion
|
 |
« Reply #12 on: January 31, 2008, 05:15:12 PM » |
|
true  this is ofcourse way better, but i think it's easier to do it in the form when creating small apps  but nonetheless, good idea
|
|
|
|
|
Logged
|
|
|
|
|