remove pointer and using update() should fix random crash (thanks Uknown)

This commit is contained in:
Ade Novan authored and Gde Made Novan Priambhada committed 2017-07-02 01:28:38 +08:00
1 parent 1241d53a8a
commit 6121dce9e1
6 files changed
+32 -35

No files matched your search

-1
View File
@@ -425,7 +425,6 @@ public:
int iWlanAdhocChannel;
bool bWlanPowerSave;
bool bEnableNetworkChat;
int iNewChat;
int iPSPModel;
int iFirmwareVersion;
+13 -20
View File
@@ -56,10 +56,12 @@ SceNetAdhocPdpStat * pdp[255];
SceNetAdhocPtpStat * ptp[255];
uint32_t localip;
std::vector<std::string> chatLog;
ChatMenu * ch;
std::string name = "";
std::string incoming = "";
std::string message = "";
bool chatScreenVisible = false;
bool updateChatScreen = false;
int newChat = 0;
int isLocalMAC(const SceNetEtherAddr * addr) {
SceNetEtherAddr saddr;
@@ -986,14 +988,6 @@ void freeFriendsRecursive(SceNetAdhocctlPeerInfo * node) {
free(node);
}
//@params chatmenu pass NULL on destroy, and pass ChatMenu On Create (EmuScreen.cpp)
void setChatPointer(ChatMenu * chatmenu) {
if (chatmenu != NULL) {
delete ch;
}
ch = chatmenu; //setChatPointer
}
void sendChat(std::string chatString) {
SceNetAdhocctlChatPacketC2S chat;
I18NCategory *n = GetI18NCategory("Networking");
@@ -1011,20 +1005,19 @@ void sendChat(std::string chatString) {
NOTICE_LOG(SCENET, "Send Chat %s to Adhoc Server", chat.message);
name = g_Config.sNickName.c_str();
chatLog.push_back(name.substr(0, 8) + ": " + chat.message);
if (ch) {
ch->UpdateChat();
if (chatScreenVisible) {
updateChatScreen = true;
}
}
}
else {
chatLog.push_back(n->T("You're in Offline Mode, go to lobby or online hall"));
if (ch) {
ch->UpdateChat();
if (chatScreenVisible) {
updateChatScreen = true;
}
}
}
std::vector<std::string> getChatLog() {
// this log used by chat screen
if (chatLog.size() > 50) {
@@ -1133,12 +1126,12 @@ int friendFinder(){
incoming.append((char *)packet->base.message);
chatLog.push_back(incoming);
//im new to pointer btw :( doesn't know its safe or not this should update the chat screen when data coming
if (ch) {
ch->UpdateChat();
if (chatScreenVisible) {
updateChatScreen = true;
}
else {
if (g_Config.iNewChat < 50) {
g_Config.iNewChat += 1;
if (newChat < 50) {
newChat += 1;
}
}
// Move RX Buffer
@@ -1169,8 +1162,8 @@ int friendFinder(){
//joined.append((char *)packet->ip);
chatLog.push_back(incoming);
//im new to pointer btw :( doesn't know its safe or not this should update the chat screen when data coming
if (ch) {
ch->UpdateChat();
if (chatScreenVisible) {
updateChatScreen = true;
}
// Update HUD User Count
#ifdef LOCALHOST_AS_PEER
+3 -2
View File
@@ -33,7 +33,6 @@
#include "Core/HLE/sceKernel.h"
#include "Core/HLE/sceKernelMutex.h"
#include "Core/HLE/sceUtility.h"
#include "UI/ChatScreen.h"
class PointerWrap;
@@ -847,9 +846,11 @@ void addFriend(SceNetAdhocctlConnectPacketS2C * packet);
* Send chat or get that
* @param std::string ChatString
*/
void setChatPointer(ChatMenu * chatmenu);
void sendChat(std::string chatString);
std::vector<std::string> getChatLog();
extern bool chatScreenVisible;
extern bool updateChatScreen;
extern int newChat;
/*
* Find a Peer/Friend by MAC address
+11 -4
View File
@@ -69,7 +69,8 @@ void ChatMenu::CreateViews() {
CreatePopupContents(box_);
root_->SetDefaultFocusView(box_);
UpdateChat();
g_Config.iNewChat = 0;
chatScreenVisible = true;
newChat = 0;
}
void ChatMenu::dialogFinished(const Screen *dialog, DialogResult result) {
@@ -142,6 +143,7 @@ void ChatMenu::UpdateChat() {
}
}
toBottom_ = true;
updateChatScreen = false;
}
}
@@ -157,6 +159,13 @@ bool ChatMenu::touch(const TouchInput &touch) {
return UIDialogScreen::touch(touch);
}
void ChatMenu::update(InputState &input) {
PopupScreen::update(input);
if (updateChatScreen) {
UpdateChat();
}
}
void ChatMenu::postRender() {
if (scroll_ && toBottom_) {
scroll_->ScrollToBottom();
@@ -165,7 +174,5 @@ void ChatMenu::postRender() {
}
ChatMenu::~ChatMenu() {
setChatPointer(NULL);
scroll_ = NULL;
chatVert_ = NULL;
chatScreenVisible = false;
}
+2 -1
View File
@@ -10,8 +10,9 @@ public:
void CreateViews() override;
void dialogFinished(const Screen *dialog, DialogResult result) override;
bool touch(const TouchInput &touch) override;
void update(InputState &input) override;
void postRender() override;
virtual void UpdateChat();
void UpdateChat();
private:
UI::EventReturn OnSubmit(UI::EventParams &e);
UI::TextEdit *chatEdit_;
+3 -7
View File
@@ -373,9 +373,7 @@ void EmuScreen::sendMessage(const char *message, const char *value) {
}
} else if (!strcmp(message, "chat screen")) {
releaseButtons();
ChatMenu * ch = new ChatMenu();
setChatPointer(ch);
screenManager()->push(ch);
screenManager()->push(new ChatMenu());
}
}
@@ -785,7 +783,7 @@ void EmuScreen::CreateViews() {
}
if (g_Config.bEnableNetworkChat) {
//root_->Add(new Button(sc->T("Chat"), new AnchorLayoutParams(50, NONE, NONE, 50, true)))->OnClick.Handle(this, &EmuScreen::OnChat);
root_->Add(new ChoiceWithValueDisplay(&g_Config.iNewChat, sc->T("Chat"), new AnchorLayoutParams(130,WRAP_CONTENT,80, NONE, NONE, 50, true)))->OnClick.Handle(this, &EmuScreen::OnChat);
root_->Add(new ChoiceWithValueDisplay(&newChat, sc->T("Chat"), new AnchorLayoutParams(130,WRAP_CONTENT,80, NONE, NONE, 50, true)))->OnClick.Handle(this, &EmuScreen::OnChat);
}
saveStatePreview_ = new AsyncImageFileView("", IS_FIXED, nullptr, new AnchorLayoutParams(bounds.centerX(), 100, NONE, NONE, true));
saveStatePreview_->SetFixedSize(160, 90);
@@ -807,9 +805,7 @@ UI::EventReturn EmuScreen::OnDevTools(UI::EventParams &params) {
UI::EventReturn EmuScreen::OnChat(UI::EventParams &params) {
releaseButtons();
ChatMenu * ch = new ChatMenu(); // memory leak or not?
setChatPointer(ch);
screenManager()->push(ch);
screenManager()->push(new ChatMenu());
return UI::EVENT_DONE;
}