On Sun, 2008-07-06 at 03:38 +0100, iain wrote:
> On Sat, 2008-07-05 at 20:36 +0200, Andre Schmidt wrote:
> 
> > am i doing something very stupid in that code ?
> > or is it maybe a bug ?
> > (or does the code work under your system?)
> 
> Without having run it you may need to wrap the clutter_actor_move_by
> command in clutter_thread_enter() and clutter_thread_leave() calls as
> its being called from a thread that isn't the main thread. And add
> clutter_threads_init() at the start of main.

thank you very much! exactly what i was missing
(i attached a working code for future reference)

> 
> If a clutter function is called from a thread other than the main one
> then they need to be wrapped with _enter and _leave.

i had the feeling that i needed something...
thank you for letting me know!

.andre

> 
> iain
> 
#include <clutter/clutter.h>
#include <stdlib.h>
#include <lo/lo.h>

ClutterActor *rect;

int move_actor()
{
  printf("trying to move\n");
  clutter_threads_enter();
  clutter_actor_move_by(rect,20,20);
  clutter_threads_leave();
  return 0;
}

int main(int argc, char *argv[])
{
  lo_server_thread st = lo_server_thread_new("7771", NULL);
  lo_server_thread_add_method(st, NULL, NULL, move_actor, NULL);
  lo_server_thread_start(st);
  
  ClutterColor stage_color = { 0x00, 0x00, 0x00, 0xff };
  ClutterColor actor_color = { 0xff, 0xff, 0xff, 0x99 };

  g_thread_init(NULL);
  clutter_threads_init();
  clutter_init (&argc, &argv);

  /* Get the stage and set its size and color: */
  ClutterActor *stage = clutter_stage_get_default ();
  clutter_actor_set_size (stage, 200, 200);
  clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);

  /* Add a rectangle to the stage: */
  rect = clutter_rectangle_new_with_color (&actor_color);
  clutter_actor_set_size (rect, 100, 100);
  clutter_actor_set_position (rect, 0, 0);
  clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect);
  clutter_actor_show (rect);


  /* Show the stage: */
  clutter_actor_show (stage);

  move_actor();

  /* Start the main loop, so we can respond to events: */
  clutter_main ();

  return EXIT_SUCCESS;

}

Reply via email to