Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No Gui Application without endless loop, application crash at (*it)->slot_disconnect(this); #33

Closed
itas109 opened this issue Aug 16, 2020 · 2 comments
Labels

Comments

@itas109
Copy link
Owner

itas109 commented Aug 16, 2020

Describe the bug
No Gui Application without endless loop, application crash at (*it)->slot_disconnect(this);

void disconnect_all()
{
	lock_block<mt_policy> lock(this);
	const_iterator it = m_senders.begin();
	const_iterator itEnd = m_senders.end();

	while(it != itEnd)
	{
		(*it)->slot_disconnect(this);// crash c0000005
		++it;
	}

	m_senders.erase(m_senders.begin(), m_senders.end());
}

test code:

#include <iostream>

#include "SerialPort.h"

using namespace itas109;
using namespace std;

class mySlot : public has_slots<>
{
public:
	mySlot(CSerialPort & sp){ m_sp = sp; };

	void OnSendMessage()
	{
		recLen = m_sp.readAllData(str);
		if (recLen > 0)
		{
			str[recLen] = '\0';
			std::cout << "receive data : " << str << ", receive size : " << recLen << std::endl;
		}
	};

private:
	mySlot(){};

private:
	CSerialPort m_sp;

	char str[1024];
	int recLen;
};

int main()
{
	CSerialPort sp;
	mySlot receive(sp);

       // while(true);
	return 0;
}

Desktop (please complete the following information):

  • OS:Win7 Ultimate 64bit
  • Compiler: VS2013 update 5/MinGW 810
  • Version: [e.g. 4.0.3.200429
@itas109 itas109 added the bug label Aug 16, 2020
@itas109
Copy link
Owner Author

itas109 commented Dec 13, 2020

mySlot(CSerialPort & sp){ m_sp = sp; };

change to (not crash)

mySlot(CSerialPort & sp){ //m_sp = sp; };

@itas109
Copy link
Owner Author

itas109 commented Dec 13, 2020

this code works

#include <iostream>

#include "CSerialPort/SerialPort.h"

using namespace itas109;
using namespace std;

class mySlot : public has_slots<>
{
public:
    mySlot(CSerialPort * sp)
    {
        p_sp = sp;
    };

    void OnSendMessage()
    {
        recLen = p_sp->readAllData(str);
        if (recLen > 0)
        {
            str[recLen] = '\0';
            std::cout << "receive data : " << str << ", receive size : " << recLen << std::endl;
        }
    };

private:
    mySlot(){};

private:
    CSerialPort * p_sp;

    char str[1024];
    int recLen;
};

int main()
{
    CSerialPort sp;
    mySlot receive(&sp);

    // while(true);
    return 0;
}

@itas109 itas109 closed this as completed in 336ab48 Jan 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant