mirror of
				https://github.com/ArthurSonzogni/FTXUI.git
				synced 2025-11-04 05:28:15 +08:00 
			
		
		
		
	Fix PostEvent() segfault (#403)
Fix segfault when PostEvent() called on inactive screen. Co-authored-by: ArthurSonzogni <sonzogniarthur@gmail.com>
This commit is contained in:
		@@ -295,10 +295,14 @@ ScreenInteractive ScreenInteractive::FitComponent() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ScreenInteractive::Post(Task task) {
 | 
			
		||||
  if (!quit_) {
 | 
			
		||||
    task_sender_->Send(std::move(task));
 | 
			
		||||
  }
 | 
			
		||||
  // Task/Events sent toward inactive screen or screen waiting to become
 | 
			
		||||
  // inactive are dropped.
 | 
			
		||||
  if (!task_sender_)
 | 
			
		||||
    return;
 | 
			
		||||
 | 
			
		||||
  task_sender_->Send(std::move(task));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ScreenInteractive::PostEvent(Event event) {
 | 
			
		||||
  Post(event);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -47,6 +47,20 @@ TEST(ScreenInteractive, Signal_SIGFPE) {
 | 
			
		||||
  TestSignal(SIGFPE);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Regression test for:
 | 
			
		||||
// https://github.com/ArthurSonzogni/FTXUI/issues/402
 | 
			
		||||
TEST(ScreenInteractive, PostEventToNonActive) {
 | 
			
		||||
  auto screen = ScreenInteractive::FitComponent();
 | 
			
		||||
  screen.Post(Event::Custom);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Regression test for:
 | 
			
		||||
// https://github.com/ArthurSonzogni/FTXUI/issues/402
 | 
			
		||||
TEST(ScreenInteractive, PostTaskToNonActive) {
 | 
			
		||||
  auto screen = ScreenInteractive::FitComponent();
 | 
			
		||||
  screen.Post([] {});
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
}  // namespace ftxui
 | 
			
		||||
 | 
			
		||||
// Copyright 2021 Arthur Sonzogni. All rights reserved.
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user