[.net] Running DirectX in a seperate thread in VB.net

Started by
23 comments, last by Ixusv4 16 years, 3 months ago
Quote:Original post by Machaira
Quote:Original post by gharen2
Yeah yeah yeah.

I didn't want to complicate things further by going into that. I figure, once he gets it working with Application.DoEvents, he can look at optimizing it. Implement first, optimize second, they always say :)


Yeah, but implement the best way you know how. :)


So..the Do events doesn't do what everybody thinks.. So if anybody has an idea to help me with my problem...

Advertisement
Without seeing the project it's hard to offer a suggestion. The Tick event on the timer fires even when another form has focus. I threw together a sample project to test this. There might be something in your render code that's causing the problem. Without seeing anything that's the best I can do. :(

Former Microsoft XNA and Xbox MVP | Check out my blog for random ramblings on game development

I too can't help you without seeing code.

Quote:Original post by Ixusv4
So..the Do events doesn't do what everybody thinks.. So if anybody has an idea to help me with my problem...


And not to belabor the issue, but don't worry about the question of the validity of DoEvents for now. It does do what it's supposed to, the issue is just that it doesn't do it as efficiently as it could. But in terms of behavior, it has no bearing on your problem. Hence why I didn't want to bring it up :)

So, how about some code?
Quote:Original post by Ixusv4
The DOEvents was already implanted in my renderloop. If it wasn't there any interaction with other controls on any form in the same program would be impossible.

The problem arises when the user interacts with the scrollbar/object or any object or when one moves any form around..

The problem is in the fact dat VB.net is not multi-tasking. And usually one makes a directX program Fullscreen...Buth I want to make my own 3D Editor :(


Yes, your problem makes sense. When you fire the DoEvents() function, all user mouse clicks, key strokes, etc now have time to execute. Obviously the scrolling of your form/picturebox are taking longer than anticipated. This could be bad code or just the amount of work that needs to be done.

Multithreading may not solve your problem, as others stated please post your scrollbar event code and render loop. they're may be an easier way to fix the problem.
I made an example. It's made very fast..so forgive me any errors.
It give's a good idea what I'm making...Yet a little simplified...

U can download it here




Here's a quickly hacked update to it that kinda fixes some issues. You can at least hold and drag the thumb on the scrollbar without breaking the rendering.

Former Microsoft XNA and Xbox MVP | Check out my blog for random ramblings on game development

Well..indeed...it resolves some issues...
Buth..there are now some other issues..
First of all...the responsiness of the program is not quite like what u would expect of a windows program...second of is that the thing that does fire the actual render is not in the class anymore..
The first thing can probably be fixed by fixing the second thing. Given that what you did was thrown together a rethinking of the design could probably solve both problems simultaneously. [wink]

Former Microsoft XNA and Xbox MVP | Check out my blog for random ramblings on game development

Ok..I'm open for any suggestion :D
But bringing the Winproc to the class resolves in a minor problem..
First the Overrides doesn't work in a class...
So it would me something like this...


Protected Overloads Sub WndProc(ByRef m As Message)

If m.Msg = 15 Then

frmMain.Engine.Render()

SendNotifyMessage(Me, 15, IntPtr.Zero, IntPtr.Zero)
Else
MyBase.WndProc(m)
End If

End Sub

Only how do we get an integer pointer of a class?
And what does the 15 mean?
First off, use spacing! Your code was impossible to read. Extra lines and proper formatting go a LONG way :)

This works perfect for me. You'll notice moving the scrollbars or moving the form DOESN'T halt rendering. Update your CTRL form Button1_Click to the below code:


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

If Button1.Text = "Start Renderloop" Then
Button1.Text = "Stop Renderloop"

Dim thrStart As New Threading.Thread(AddressOf frmMain.Engine.Start)
thrStart.Start()

Else
Button1.Text = "Start Renderloop"
frmMain.Engine.Stop()
End If

End Sub

This topic is closed to new replies.

Advertisement