Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
[C++] Stupid bug... [SOLVED]

 
Post new topic   Reply to topic Printable version
 View previous topic  C++ : Inheritance,Template and Threads... Post :: Post New wine client - Continuum fix anyone?  View next topic  
Author Message
Samapico
No, these DO NOT look like penises, ok?


Joined: May 08 2003
Posts: 1252
Offline

PostPosted: Sat Oct 24, 2009 4:10 pm    Post subject: [C++] Stupid bug... [SOLVED] Reply to topic Reply with quote

We're making this program for school, it has to simulate a TCP/IP protocol using UDP. Basically a couple of networking layers, each has its own thread, two queues for requests (from layer above) and indications (from layer under).
We're having this very weird bug, the queue works fine, but at some point, I get memory access violation error... It appears that the queue object in the layer is... moved?! When I put a watch on 'this' while in the queue, it's like 0x00000008 or something like that, which is nowhere near a good pointer.
I used the linkedlist from mervbot core, but I also had the issue with some STL queue I tried.

I can't figure out the problem... I'm hoping some of you guys could help me out new_let_it_all_out.gif
The source has a bunch of files and stuff, but I'm sure you'll find a way through it all... The server project works fine, but the client one gives the exception after sending a request to a layer.

Have fun :/ and thank you in advance


<attachment removed>
_________________
(Insert a bunch of dead links here)


Last edited by Samapico on Mon Oct 26, 2009 4:56 pm, edited 2 times in total
Back to top
View users profile Send private message Add User to Ignore List
Doc Flabby
Server Help Squatter


Joined: Feb 26 2006
Posts: 636
Offline

PostPosted: Sun Oct 25, 2009 8:36 am    Post subject: Reply to topic Reply with quote

For some reason queue.cpp is a 0 byte file in that rar you uploaded icon_sad.gif
_________________
Rediscover online gaming. Get Subspace | STF The future...prehaps
Back to top
View users profile Send private message Add User to Ignore List
Samapico
No, these DO NOT look like penises, ok?


Joined: May 08 2003
Posts: 1252
Offline

PostPosted: Sun Oct 25, 2009 1:22 pm    Post subject: Reply to topic Reply with quote

hmm, it's not even part of the project, the _queue type I used is in types.h/cpp, but I think when I uploaded it it's actually using a _linkedlist , also in types.h/cpp

Attached proper arborescence of both projects in case you're not using visual studio; a couple of files in the .rar are not used




Project arborescence

server.png - 11.21 KB
File downloaded or viewed 139 time(s)

Project arborescence

client.png - 11.04 KB
File downloaded or viewed 134 time(s)
Back to top
View users profile Send private message Add User to Ignore List
Samapico
No, these DO NOT look like penises, ok?


Joined: May 08 2003
Posts: 1252
Offline

PostPosted: Sun Oct 25, 2009 5:33 pm    Post subject: Reply to topic Reply with quote

i was able to go one more step forward, somehow...

I was able to send a message from the client to the server, the server network layer received it, but then I get the same crash...

Worse part is that i have no idea what I did to fix it... I moved some stuff around, but none of these things should change anything >=(

I guess I'll check the diffs through SVN and test a bunch of stuff...
Back to top
View users profile Send private message Add User to Ignore List
Doc Flabby
Server Help Squatter


Joined: Feb 26 2006
Posts: 636
Offline

PostPosted: Sun Oct 25, 2009 8:28 pm    Post subject: Reply to topic Reply with quote

I've found your problem samp.

The linked list you are using isn't threadsafe. I think this might be the problem.

So when two threads enter the "append" method at the same time, they interact in an unpredictable way. If you step into it, and look at the other thread in visual studio you'll see they are both in the same method.

http://img193.imageshack.us/img193/9527/forsamp.jpg

You need to use a threadsafe class or make it thread safe, using mutex's or something similar. If two threads interact like this, the result is unpredictable, which is why sometimes it works and sometimes not.
Back to top
View users profile Send private message Add User to Ignore List
Samapico
No, these DO NOT look like penises, ok?


Joined: May 08 2003
Posts: 1252
Offline

PostPosted: Sun Oct 25, 2009 9:57 pm    Post subject: Reply to topic Reply with quote

But... aren't these 2 different instances of the list???
Back to top
View users profile Send private message Add User to Ignore List
Doc Flabby
Server Help Squatter


Joined: Feb 26 2006
Posts: 636
Offline

PostPosted: Mon Oct 26, 2009 6:45 am    Post subject: Reply to topic Reply with quote

Hmm, if there two different instances they shouldn't interact... I'll take another look at it when i'm more awake, it was just after midnight on a sunday -_-
Back to top
View users profile Send private message Add User to Ignore List
Samapico
No, these DO NOT look like penises, ok?


Joined: May 08 2003
Posts: 1252
Offline

PostPosted: Mon Oct 26, 2009 1:23 pm    Post subject: Reply to topic Reply with quote

I also tried using critical sections while anything is appended or removed from the list, but that didn't work (you can still see these sections commented out)
Back to top
View users profile Send private message Add User to Ignore List
Doc Flabby
Server Help Squatter


Joined: Feb 26 2006
Posts: 636
Offline

PostPosted: Mon Oct 26, 2009 2:55 pm    Post subject: Reply to topic Reply with quote

I had another look and got no closer, i tried the critical section thing too...The thing that makes me think its a threading issue is because if i put a breakpoint on the "Append" Method and step though it slowly, i dont get the error, but if i run it at full speed it crashes.
Back to top
View users profile Send private message Add User to Ignore List
Samapico
No, these DO NOT look like penises, ok?


Joined: May 08 2003
Posts: 1252
Offline

PostPosted: Mon Oct 26, 2009 3:07 pm    Post subject: Reply to topic Reply with quote

it doesnt crash on the first append... break at the 2nd .addrequest in c_main.cpp, and go slow, it should crash
Back to top
View users profile Send private message Add User to Ignore List
Doc Flabby
Server Help Squatter


Joined: Feb 26 2006
Posts: 636
Offline

PostPosted: Mon Oct 26, 2009 3:57 pm    Post subject: Reply to topic Reply with quote

Found it icon_smile.gif You were right it had nothing to do with threading.

Your trying to call a method on a NULL pointer. Line 44 in layer_transport.cpp.

Reason why it was so hard to find is because of this which hides the problem...
Code: Show/Hide

   Layer* Session()   { return layer_above; }
   Layer* Network()   { return layer_below; }


you need to provide the layer_below with a valid pointer ^^

Code: Show/Hide

void Layer_transport::RequestRcvd(Request *req)
{
   HeaderTransport h;
   char* iframe = NULL;


   
   switch (req->type)
   {
   case REQ_SendData:
      h.flags = DATA;
      h.length = req->frame->length;

      req->frame->Prepend(&h, sizeof(h));
      
      if(Network()==NULL) { printf("Null pointer"); } //i added this

      
      Network()->AddRequest(REQ_SendData, req->targetid, new DataBuffer(req->frame), NULL);  //calling a NULL pointer
      //P_DataReq(req->data, req->datalen);
      break;

   case REQ_ConnectRequest:
      break;
   case REQ_Disconnect:
      break;
   default:
      break;
   }
}
Back to top
View users profile Send private message Add User to Ignore List
Samapico
No, these DO NOT look like penises, ok?


Joined: May 08 2003
Posts: 1252
Offline

PostPosted: Mon Oct 26, 2009 4:34 pm    Post subject: Reply to topic Reply with quote

F*************************** &*"/$6Y&*"$?&*

I FORGOT TO USE THE ATTACHLAYERS GODDAMNIT

It makes sense now... THANK YOU

I remember thinking that I should check if I did attach the layers, but I was probably sleeping or something, and I completely forgot...
Back to top
View users profile Send private message Add User to Ignore List
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> Non-Subspace Related Coding All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 699 page(s) served in previous 5 minutes.

phpBB Created this page in 0.526851 seconds : 39 queries executed (80.4%): GZIP compression disabled