Welcome, Guest. Please login or register. Did you miss your activation email?

Poll

Is my problem stupid

Yes
2 (66.7%)
No
1 (33.3%)

Total Members Voted: 3

Voting closed: October 12, 2010, 06:35:42 am

Author Topic: Having trouble with DLLs, threads AND RenderWindows  (Read 3744 times)

0 Members and 1 Guest are viewing this topic.

Stew_822

  • Newbie
  • *
  • Posts: 16
    • View Profile
    • http://circean-studios.co.cc
    • Email
Having trouble with DLLs, threads AND RenderWindows
« on: October 12, 2010, 06:35:42 am »
Hi guys, nice to meet you all! Man, that's an awesome range of emoticions over there -<<
 :shock:
hehe.

Anyway, I'm making a program that loads DLLs and for each DLL it creates a thread for it, and the thread executes one function that the DLL contains. Yeah, crappy explanation I know.

Anyway, when I pass a RenderWindow to the DLL and try to draw on it, it fails. Funny thing is I can move the RenderWindow using SetPosition. Well actually it isn't funny, because it makes less sense.

I tried moving the Clear() and Display() code to the DLL but nothing is working.

Anyway, if anyone has any idea as to why this is happening I'd love to hear them. I'll send an icecream to anyone who helps :)

Thanks for taking your time to read this and have a nice day!!!

--Stewart
It's better to keep your mouth shut and give the impression that you're stupid than to open it and remove all doubt.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Having trouble with DLLs, threads AND RenderWindows
« Reply #1 on: October 12, 2010, 08:06:00 am »
You have to deactivate the window's context in the main thread (window.SetActive(false)) before it can be used for drawing operations in the other thread.
Laurent Gomila - SFML developer

Stew_822

  • Newbie
  • *
  • Posts: 16
    • View Profile
    • http://circean-studios.co.cc
    • Email
:(
« Reply #2 on: October 12, 2010, 10:17:01 am »
So if I did that, I could only ever have one thread drawing on the window at a time?
 :cry:
This is not good.
 
Thankyou for the quick response :).

-- Stewart
It's better to keep your mouth shut and give the impression that you're stupid than to open it and remove all doubt.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Having trouble with DLLs, threads AND RenderWindows
« Reply #3 on: October 12, 2010, 10:20:24 am »
Why would you need multiple threads drawing to the same window?
Laurent Gomila - SFML developer

Stew_822

  • Newbie
  • *
  • Posts: 16
    • View Profile
    • http://circean-studios.co.cc
    • Email
Having trouble with DLLs, threads AND RenderWindows
« Reply #4 on: October 12, 2010, 10:24:39 am »
I'll take that as a no?

I need them to draw on the same window because... well... it's kinda hard to explain.

I'm creating a program that will contain heaps of other little programs, and I was going to load them from DLLs and each one would have it's own thread, for simplicity. The DLLs would obviously need to draw on the window, otherwise how could the user interact with them?

Is there any way around this, or do I need to re-design my code?

Thanks again for helping me :)
It's better to keep your mouth shut and give the impression that you're stupid than to open it and remove all doubt.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Having trouble with DLLs, threads AND RenderWindows
« Reply #5 on: October 12, 2010, 10:37:31 am »
It is technically possible, but there's no way to do this directly with SFML.

However I think the best solution is to redesign your application, using one thread per "plugin" (or whatever they are) is often not necessary, and bad things may happen when rendering is involved.

If you to discuss about the design of your application, you can tell us more about it :)
Laurent Gomila - SFML developer

Stew_822

  • Newbie
  • *
  • Posts: 16
    • View Profile
    • http://circean-studios.co.cc
    • Email
Aww shucks
« Reply #6 on: October 12, 2010, 10:49:52 am »
Aww shucks
I thought that'd be the case :(

Hmm... Okay, I'll tell you more about it :). I'm going to have this "core" program I'm coding that loads so-called modules and will make a tab for each module. When the tab is clicked on, the module will show whatever it wants in that tab, and the modules will be able to display things anywhere else, as well.

The modules are mostly going to be utilities that I'm probably going to code (hopefully some other people will code some too!) that do useful things. They will be programs that are hardly useful, like one might be for text-storing (ever had a snippet of code that you need to store for a second?), and instead of having 50 different programs that do useless things, you can just have one.

I'm calling it Companion, because it's going to sit unnoticed on the side of the screen, not visible. When you move your mouse to the corner, it'll appear with all these useful things to do (hey, a todo list. Not a bad idea!)

I was recommended by a friend to use threads and DLLs and I choose SFML myself (I love it :)). I suppose I could do things differently (I suppose I don't really have a choice).

What if I created a couple of functions in the DLL, say start, step and end? Each function could then be called when the appropriate thing happens. And all the variables that the DLL uses could just be global? Would that work, do you think? (I'm rather new to C++, and haven't spent much time with DLLs either).

-- Stewart
It's better to keep your mouth shut and give the impression that you're stupid than to open it and remove all doubt.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Having trouble with DLLs, threads AND RenderWindows
« Reply #7 on: October 12, 2010, 11:20:16 am »
Quote
I was recommended by a friend to use threads and DLLs and I choose SFML myself

- DLLs: ok for modularity
- threads: probably not necessary, start without them and add them only if you have to
- SFML: definitely not a good choice

Your app looks like a regular desktop app rather than a real-time multimedia thing, so why don't you use a library such as Qt? Or I am missing something? What's the relation between the utilities that you describe and 2D rendering?

Quote
What if I created a couple of functions in the DLL, say start, step and end? Each function could then be called when the appropriate thing happens

Definitely. A typical approach for graphics entities would be create/update/draw/destroy.

Quote
And all the variables that the DLL uses could just be global?

If each plugin is supposed to provide a single object, it can be global inside the DLL and returned with an exported function like GetXxx(), or created/destroyed on demand with exported functions like CreateXxx()/DestroyXxx().

Anyway, you'd better read more about plugins, there are a few things that you have to know to work efficiently with them ;)
Laurent Gomila - SFML developer

Stew_822

  • Newbie
  • *
  • Posts: 16
    • View Profile
    • http://circean-studios.co.cc
    • Email
Having trouble with DLLs, threads AND RenderWindows
« Reply #8 on: October 12, 2010, 11:40:56 am »
Quote
Your app looks like a regular desktop app rather than a real-time multimedia thing, so why don't you use a library such as Qt? Or I am missing something? What's the relation between the utilities that you describe and 2D rendering?

hehe, well, err..  ummm.... well... Nothing, I suppose, I just thought since I knew a little SFML I just thought I'd use it  :oops:

Yeah, ok, I'll try a library. Thanks so much for your help, and at least I got the DLL part right :)

-- Stewart
 8)
It's better to keep your mouth shut and give the impression that you're stupid than to open it and remove all doubt.

 

anything