Пример #1
0
void on_close_stub() {
  STUB_GET_VIEW();
  if (wnd == NULL)
    return;

  //call callback
  wnd->on_close();

  //remove view from system
  view_sync.enter();
  RemoveParams params(glutGetWindow(), false);
  remove_view_in_thread(&params);
  view_sync.signal_close();
  view_sync.leave();
}
Пример #2
0
/// Removes a new view. Function has to be called just from the inside of view thread with a locked sync_view.
int remove_view_in_thread(void* remove_params_ptr)
{
  debug_assert(!need_safe_call(), "E remove_view_in_thread called from other thread.");
  RemoveParams& params = *(RemoveParams*)remove_params_ptr;
  std::map<int, View*>::iterator found_view = view_instances.find(params.view_id);
  //debug_assert(found_view != view_instances.end(), "E removing of a view that is not registered");
  if (found_view == view_instances.end()) {
    debug_log("W removing of a view that is not registered\n");
    return -1;
  }

  //destroy window if requested (it will not be requested when remove is called as a reaction to on_close)
  if (params.destroy_glut_window)
  {
    //remove window from GLUT
    glutSetWindow(params.view_id);
    glutSetWindowData(NULL); //prevent stubs from being executed if there is still some message waiting for the window

    //call on-close event
    found_view->second->on_close();

    //finish removal of window from GLUT
    glutDestroyWindow(params.view_id);
  }

  //remove from structures
  view_instances.erase(found_view);

  //thread cleanup
  if (view_instances.size() == 0)
  {
    view_thread->should_quit = true;
    view_thread = NULL;

    //signal all events
    view_sync.signal_close();
    view_sync.signal_keypress();
    view_sync.signal_drawing_finished();
  }

  return 0;
}