I was inspired to find a long-hidden mistake-mindset

Source: Internet
Author: User

In the past two days, I have designed a change program for my graduation project. Instead of changing the program for him, I suggest you change it for yourself, because the program is self-written from start to end (except the jrtplib, opencv library and socket class written by others), the program is to implement remote video viewing and playback control, it is the simplest way to send commands from the client to view the video on the video server, and use RTP video transmission to send control information using an encapsulated socket class downloaded from the codeproject. In the end, it is not difficult. In fact, it is to combine these several components. The whole program is also extracted from the graduation project program.

My program runs normally and occasionally crashes. At that time, I also found the cause, but unfortunately I did not find it, because it didn't crash every time, but occasionally, so I don't have to worry about it anymore (I'm about to graduate now, so I don't have to worry about it anymore. I'll leave it to my teachers and sisters to solve it !). Now I want to bring my undergraduate graduation project. To be honest, if it is not something that I like programming or that I want to talk about in class, even a VC project won't be created! So I don't expect him to do it on his own. It's just now that we have something to do, so let's just give it a whole piece of cake ).

There is a lot of nonsense, and there is still no theme!

In short, I simplified my programs and deleted all irrelevant ones. Four channels were also changed to one channel, and the interface was changed. There was only one simple dialog box left, in short, it is a bit cool, and the corresponding code has been modified. Simple video transmission is okay, but when debugging control information, it is okay to send messages from the client to the server, the WSA_INVALID_PARAMETER error always occurs when sending a Response Message from the server! No problem was found after debugging for one afternoon ~~~. By accident, it is purely accidental, and suddenly realizes that a function is called when a crash occurs, that is, data is sent using socket in the dialog box interface class, among them, one of the function parameters is socket reference, that is, with &, and then return to find...

Finally, I found the problem: in a transmission class written by myself, there are also several parallel functions for processing received messages, all of which use socket reference to transmit parameters, and all of which are in the cpp file, that is, it was written in order at that time. One of them is to send the socket obtained by myself to the dialog box through sendmessage. The result is the problem here. There are two parameters of sendmessage, A parameter used to pass the socket is used (wparam) & socket. At that time, you should want to directly pass the value, since several nearby functions are passed by reference, that is, there are a lot of & and the parameter names are also the same, there is an illusion in mind, when receiving messages in the dialog box, the parsing is not based on the socket pointer, but directly converted to the socket, as a result, the original socket pointer is used as a socket and used in the interface function to send information. Therefore, an error occurs every time a function is called.

Now it seems that the error is actually very simple, but it has been hidden for a long time. I wrote the program about a year ago. At that time, I didn't use the socket that passed the past, so it was okay to run most of the time, so I did not go into details and found the error. I was surprised to find out when I changed the program for someone else. I think that if I didn't use the sendmessage function, a few nearby functions would use references, and the parameter names would also be the same, there may be no errors at the time.

Multiple identical things appear in a row, forming a kind of trap that is first visual and then converted into thinking. In the end, as long as the situation is repeated, it will fall.

It is worth thinking!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.