Welcome,
Guest
. Please
login
or
register
. Did you miss your
activation email?
French forum
Home
Help
Search
Login
Register
SFML community forums
»
Bindings - other languages
»
DotNet
»
Thread bug ?
Print
Pages: [
1
]
Author
Topic: Thread bug ? (Read 3466 times)
0 Members and 1 Guest are viewing this topic.
Yuraj
Newbie
Posts: 8
C#
Thread bug ?
«
on:
May 01, 2013, 02:54:52 pm »
Hello,
there is probably bug in SFML (or only .net binding?), it can't draw things which were loaded in thread before (like text, textures etc.). I debugged this and It reach app.Draw(text); (it's loaded fully) but It can't draw it on screen.
using
SFML.Graphics
;
using
SFML.Window
;
using
System
;
using
System.Threading
;
namespace
SFMLThreads
{
class
Program
{
static
void
Main
(
string
[
]
args
)
{
RenderWindow app
=
new
RenderWindow
(
new
VideoMode
(
800
,
600
)
,
"SFML Threads Test"
)
;
app
.
SetFramerateLimit
(
60
)
;
app
.
Closed
+=
(
s,e
)
=>
app
.
Close
(
)
;
//Create and start thread
Text text
=
null
;
new
Thread
(
(
)
=>
{
text
=
new
Text
(
"test"
,
new
Font
(
"C:
\\
Windows
\\
Fonts
\\
Verdana.ttf"
)
,
25
)
;
}
)
.
Start
(
)
;
while
(
app
.
IsOpen
(
)
)
{
app
.
DispatchEvents
(
)
;
app
.
Clear
(
)
;
if
(
text
!=
null
)
{
app
.
Draw
(
text
)
;
}
app
.
Display
(
)
;
}
}
}
}
Logged
Laurent
Administrator
Hero Member
Posts: 32498
Re: Thread bug ?
«
Reply #1 on:
May 01, 2013, 02:57:24 pm »
Please read
http://www.sfml-dev.org/tutorials/2.0/graphics-draw.php
('Drawing from threads' section).
Logged
Laurent Gomila - SFML developer
Yuraj
Newbie
Posts: 8
C#
Re: Thread bug ?
«
Reply #2 on:
May 01, 2013, 03:00:25 pm »
Ehm, thanks
I thought It was only C++ (threads) related tutorial.
Logged
Yuraj
Newbie
Posts: 8
C#
Re: Thread bug ?
«
Reply #3 on:
May 01, 2013, 03:16:26 pm »
By the way, is it better to add all Draw logic into thread?
Logged
Laurent
Administrator
Hero Member
Posts: 32498
Re: Thread bug ?
«
Reply #4 on:
May 01, 2013, 03:20:36 pm »
There's no absolute "best solution". It depends on what you do. But use threads only if you need to, don't forget that they have overhead and add complexity to your code.
Logged
Laurent Gomila - SFML developer
Print
Pages: [
1
]
SFML community forums
»
Bindings - other languages
»
DotNet
»
Thread bug ?
anything