mirror of
				https://github.com/kunkundi/crossdesk.git
				synced 2025-10-26 20:25:34 +08:00 
			
		
		
		
	Fix crash when connecting to local desk
This commit is contained in:
		| @@ -185,8 +185,8 @@ int MainWindow::CreateConnectionPeer() { | ||||
|   peer_ = CreatePeer(¶ms_); | ||||
|   if (peer_) { | ||||
|     LOG_INFO("Create peer instance successful"); | ||||
|     std::string user_id = mac_addr_str_; | ||||
|     Init(peer_, user_id.c_str()); | ||||
|     local_id_ = mac_addr_str_; | ||||
|     Init(peer_, local_id_.c_str()); | ||||
|     LOG_INFO("Peer init finish"); | ||||
|   } else { | ||||
|     LOG_INFO("Create peer instance failed"); | ||||
| @@ -464,32 +464,51 @@ int MainWindow::Run() { | ||||
|           ImGui::Separator(); | ||||
|           ImGui::Spacing(); | ||||
|  | ||||
|           if (ImGui::Button(connect_button_label_.c_str())) { | ||||
|           if (ImGui::Button(connect_button_label_.c_str()) || rejoin_) { | ||||
|             int ret = -1; | ||||
|             if ("SignalConnected" == signal_status_str_) { | ||||
|               if (connect_button_label_ == | ||||
|                       localization::connect[localization_language_index_] && | ||||
|                   !connection_established_) { | ||||
|                 ret = JoinConnection(peer_, remote_id_, client_password_); | ||||
|                 if (remote_id_ == local_id_ && !peer_reserved_) { | ||||
|                   peer_reserved_ = CreatePeer(¶ms_); | ||||
|                   if (peer_reserved_) { | ||||
|                     LOG_INFO("Create peer[reserved] instance successful"); | ||||
|                     std::string local_id = "C-" + mac_addr_str_; | ||||
|                     Init(peer_reserved_, local_id.c_str()); | ||||
|                     LOG_INFO("Peer[reserved] init finish"); | ||||
|                   } else { | ||||
|                     LOG_INFO("Create peer[reserved] instance failed"); | ||||
|                   } | ||||
|                 } | ||||
|                 ret = JoinConnection(peer_reserved_ ? peer_reserved_ : peer_, | ||||
|                                      remote_id_, client_password_); | ||||
|                 if (0 == ret) { | ||||
|                   is_client_mode_ = true; | ||||
|                   if (!peer_reserved_) { | ||||
|                     is_client_mode_ = true; | ||||
|                   } | ||||
|                   rejoin_ = false; | ||||
|                 } else { | ||||
|                   rejoin_ = true; | ||||
|                 } | ||||
|  | ||||
|               } else if (connect_button_label_ == | ||||
|                              localization::disconnect | ||||
|                                  [localization_language_index_] && | ||||
|                          connection_established_) { | ||||
|                 ret = LeaveConnection(peer_); | ||||
|                 memset(audio_buffer_, 0, 960); | ||||
|                 ret = LeaveConnection(peer_reserved_ ? peer_reserved_ : peer_); | ||||
|  | ||||
|                 connection_established_ = false; | ||||
|                 received_frame_ = false; | ||||
|                 is_client_mode_ = false; | ||||
|                 if (0 == ret) { | ||||
|                   rejoin_ = false; | ||||
|                   memset(audio_buffer_, 0, 960); | ||||
|                   connection_established_ = false; | ||||
|                   received_frame_ = false; | ||||
|                   is_client_mode_ = false; | ||||
|                 } | ||||
|               } | ||||
|  | ||||
|               if (0 == ret) { | ||||
|                 connect_button_pressed_ = !connect_button_pressed_; | ||||
|  | ||||
|                 connect_button_label_ = | ||||
|                     connect_button_pressed_ | ||||
|                         ? localization::disconnect[localization_language_index_] | ||||
| @@ -823,6 +842,10 @@ int MainWindow::Run() { | ||||
|     DestroyPeer(peer_); | ||||
|   } | ||||
|  | ||||
|   if (peer_reserved_) { | ||||
|     DestroyPeer(peer_reserved_); | ||||
|   } | ||||
|  | ||||
|   SDL_CloseAudioDevice(output_dev_); | ||||
|   SDL_CloseAudioDevice(input_dev_); | ||||
|  | ||||
|   | ||||
| @@ -96,6 +96,7 @@ class MainWindow { | ||||
|   std::string settings_button_label_ = "Setting"; | ||||
|   char input_password_tmp_[7] = ""; | ||||
|   char input_password_[7] = ""; | ||||
|   std::string local_id_ = ""; | ||||
|   char remote_id_[20] = ""; | ||||
|   char client_password_[20] = ""; | ||||
|   bool is_client_mode_ = false; | ||||
| @@ -126,6 +127,7 @@ class MainWindow { | ||||
|   bool received_frame_ = false; | ||||
|   bool is_create_connection_ = false; | ||||
|   bool audio_buffer_fresh_ = false; | ||||
|   bool rejoin_ = false; | ||||
|  | ||||
|   int fps_ = 0; | ||||
|   uint32_t start_time_; | ||||
| @@ -141,6 +143,7 @@ class MainWindow { | ||||
|  | ||||
|  private: | ||||
|   PeerPtr *peer_ = nullptr; | ||||
|   PeerPtr *peer_reserved_ = nullptr; | ||||
|   Params params_; | ||||
|  | ||||
|  private: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user