Discussion:
[ENet-discuss] ENetPeer->data and enet_host_service
Jacob F.
2011-04-27 19:20:37 UTC
Permalink
I really need some help. This bug has stalled me for 2 days and I am
getting no where at all.
What happens is when I change a peer's void* I can no longer call
enet_host_service() without making a segmentation fault.

I have pushed the bugged code to my repository so you can look at it.

https://github.com/Queatz/Simple-C---Game-Engine/blob/master/engine/network.cpp

As you can see, at line 147 I assign something to the peer data if someone
connects. Now, just above that on line 138 you see the call to
enet_host_service where the segmentation fault happens. It
happens consistently on the next call (which is of a none event type) after
a client connects, causing that peer data to get set. With that line (147)
commented I get no segmentation fault at all.

If someone could see something I am missing I would be very grateful.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cubik.org/pipermail/enet-discuss/attachments/20110427/4f542154/attachment.html>
Jay Sprenkle
2011-04-27 19:36:50 UTC
Permalink
Perhaps you should clear e.evt.peer->data in the case of an error?
There's no way any caller could determine if the value there is valid/an
error occurred.
Post by Jacob F.
I really need some help. This bug has stalled me for 2 days and I am
getting no where at all.
What happens is when I change a peer's void* I can no longer call
enet_host_service() without making a segmentation fault.
I have pushed the bugged code to my repository so you can look at it.
https://github.com/Queatz/Simple-C---Game-Engine/blob/master/engine/network.cpp
As you can see, at line 147 I assign something to the peer data if someone
connects. Now, just above that on line 138 you see the call to
enet_host_service where the segmentation fault happens. It
happens consistently on the next call (which is of a none event type) after
a client connects, causing that peer data to get set. With that line (147)
commented I get no segmentation fault at all.
If someone could see something I am missing I would be very grateful.
_______________________________________________
ENet-discuss mailing list
ENet-discuss at cubik.org
http://lists.cubik.org/mailman/listinfo/enet-discuss
--
---
"The great thing about Object Oriented code is that it can make small,
simple problems look like large, complex ones."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cubik.org/pipermail/enet-discuss/attachments/20110427/3e576dd9/attachment.html>
Jacob F.
2011-04-27 20:34:52 UTC
Permalink
Both the server and client are created without an error, and I can receive
the data placed into e.evt.peer->data after I set it. Are there any
specific errors that I should check for?
By the way, the segfault happens directly on that call to enet_host_service.
I really don't know how that and the peer data relate but somehow they do.
The segfault happens even if I don't use the peer data or call it anywhere,
only having that one line to set it to something other than NULL. Setting
it to NULL does not make the segmentation fault happen.
Post by Jay Sprenkle
Perhaps you should clear e.evt.peer->data in the case of an error?
There's no way any caller could determine if the value there is valid/an
error occurred.
Post by Jacob F.
I really need some help. This bug has stalled me for 2 days and I am
getting no where at all.
What happens is when I change a peer's void* I can no longer call
enet_host_service() without making a segmentation fault.
I have pushed the bugged code to my repository so you can look at it.
https://github.com/Queatz/Simple-C---Game-Engine/blob/master/engine/network.cpp
As you can see, at line 147 I assign something to the peer data if someone
connects. Now, just above that on line 138 you see the call to
enet_host_service where the segmentation fault happens. It
happens consistently on the next call (which is of a none event type) after
a client connects, causing that peer data to get set. With that line (147)
commented I get no segmentation fault at all.
If someone could see something I am missing I would be very grateful.
_______________________________________________
ENet-discuss mailing list
ENet-discuss at cubik.org
http://lists.cubik.org/mailman/listinfo/enet-discuss
--
---
"The great thing about Object Oriented code is that it can make small,
simple problems look like large, complex ones."
_______________________________________________
ENet-discuss mailing list
ENet-discuss at cubik.org
http://lists.cubik.org/mailman/listinfo/enet-discuss
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cubik.org/pipermail/enet-discuss/attachments/20110427/7b4598f6/attachment.html>
Jay Sprenkle
2011-04-27 20:45:21 UTC
Permalink
If enet returns an error you don't change e.evt.peer->data and you don't
return an error code.
The code that calls this method has no way to detect if this happens.
It will blindly use that value when it may not be correct.
Post by Jacob F.
Both the server and client are created without an error, and I can receive
the data placed into e.evt.peer->data after I set it. Are there any
specific errors that I should check for?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cubik.org/pipermail/enet-discuss/attachments/20110427/68a0bcf8/attachment.html>
Jacob F.
2011-04-28 02:44:22 UTC
Permalink
How it is now if it's an error event.type() will return 'none' however I
have tested it and no errors are being created (as far as I can tell.) I
updated the code a little, still nothing good.
I did find one more thing though. The client is printing that it connected
1 client-service before the server prints that a client connected, and only
on the next client-service it connects on the server, and then the next
server-service segfaults.

Does enet do anything at all with peer->data?

Here is the whole server/client code (wrapped in Python, but it segfaults
when using C++ also.)
I know it would be easier to debug if I remade everything step by step from
scratch, though I'm afraid I would arrive at the same place without a
visible explanation. I will do that if we cannot figure this out.

Server:
from scge import *
from time import *

serv = server() #defaults to localhost:2000

while True:
e = serv.service()
if e.type() == 'disconnect':
print('Someone disconnected.')
elif e.type() == 'connect':
print('Someone connected.')
elif e.type() == 'receive':
print('received')
sleep(.2)

Client:
from scge import * from time import * cli = client() cli.connect()
window(160, 120) while window_opened(): e = cli.service() if e.type() ==
'connect': print('Connected.') swap() sleep(.01)
Post by Jay Sprenkle
If enet returns an error you don't change e.evt.peer->data and you don't
return an error code.
The code that calls this method has no way to detect if this happens.
It will blindly use that value when it may not be correct.
Post by Jacob F.
Both the server and client are created without an error, and I can receive
the data placed into e.evt.peer->data after I set it. Are there any
specific errors that I should check for?
_______________________________________________
ENet-discuss mailing list
ENet-discuss at cubik.org
http://lists.cubik.org/mailman/listinfo/enet-discuss
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cubik.org/pipermail/enet-discuss/attachments/20110427/6ca62e40/attachment-0001.html>
Ruud van Gaal
2011-04-28 08:36:28 UTC
Permalink
Try printing the pointer values as you assign/new (on connect) and
free/delete (on disconnect). Then print pointer where you access your local
'peer' pointers.
You'll probably find that you access a peer after it has been deleted or
such, my guess.

Ruud
Post by Jacob F.
How it is now if it's an error event.type() will return 'none' however I
have tested it and no errors are being created (as far as I can tell.) I
updated the code a little, still nothing good.
I did find one more thing though. The client is printing that it connected
1 client-service before the server prints that a client connected, and only
on the next client-service it connects on the server, and then the next
server-service segfaults.
Does enet do anything at all with peer->data?
Here is the whole server/client code (wrapped in Python, but it segfaults
when using C++ also.)
I know it would be easier to debug if I remade everything step by step from
scratch, though I'm afraid I would arrive at the same place without a
visible explanation. I will do that if we cannot figure this out.
from scge import *
from time import *
serv = server() #defaults to localhost:2000
e = serv.service()
print('Someone disconnected.')
print('Someone connected.')
print('received')
sleep(.2)
from scge import * from time import * cli = client() cli.connect()
window(160, 120) while window_opened(): e = cli.service() if e.type() ==
'connect': print('Connected.') swap() sleep(.01)
Post by Jay Sprenkle
If enet returns an error you don't change e.evt.peer->data and you don't
return an error code.
The code that calls this method has no way to detect if this happens.
It will blindly use that value when it may not be correct.
Post by Jacob F.
Both the server and client are created without an error, and I can
receive the data placed into e.evt.peer->data after I set it. Are there any
specific errors that I should check for?
_______________________________________________
ENet-discuss mailing list
ENet-discuss at cubik.org
http://lists.cubik.org/mailman/listinfo/enet-discuss
_______________________________________________
ENet-discuss mailing list
ENet-discuss at cubik.org
http://lists.cubik.org/mailman/listinfo/enet-discuss
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cubik.org/pipermail/enet-discuss/attachments/20110428/7c95a76b/attachment.html>
Jacob F.
2011-04-28 16:50:07 UTC
Permalink
It segfaults whether or not I access the data at all.

I made a simple example off the enet tutorial, you should be able to compile
it (the binaries are 64-bit Linux.)

http://queatz.com/enetest.zip

Run the server then run the client and see if it segfaults. Now I'm
thinking there is a bug, but how to describe it??
Post by Ruud van Gaal
Try printing the pointer values as you assign/new (on connect) and
free/delete (on disconnect). Then print pointer where you access your local
'peer' pointers.
You'll probably find that you access a peer after it has been deleted or
such, my guess.
Ruud
Post by Jacob F.
How it is now if it's an error event.type() will return 'none' however I
have tested it and no errors are being created (as far as I can tell.) I
updated the code a little, still nothing good.
I did find one more thing though. The client is printing that it
connected 1 client-service before the server prints that a client connected,
and only on the next client-service it connects on the server, and then the
next server-service segfaults.
Does enet do anything at all with peer->data?
Here is the whole server/client code (wrapped in Python, but it segfaults
when using C++ also.)
I know it would be easier to debug if I remade everything step by step
from scratch, though I'm afraid I would arrive at the same place without a
visible explanation. I will do that if we cannot figure this out.
from scge import *
from time import *
serv = server() #defaults to localhost:2000
e = serv.service()
print('Someone disconnected.')
print('Someone connected.')
print('received')
sleep(.2)
from scge import * from time import * cli = client() cli.connect()
window(160, 120) while window_opened(): e = cli.service() if e.type() ==
'connect': print('Connected.') swap() sleep(.01)
Post by Jay Sprenkle
If enet returns an error you don't change e.evt.peer->data and you don't
return an error code.
The code that calls this method has no way to detect if this happens.
It will blindly use that value when it may not be correct.
Post by Jacob F.
Both the server and client are created without an error, and I can
receive the data placed into e.evt.peer->data after I set it. Are there any
specific errors that I should check for?
_______________________________________________
ENet-discuss mailing list
ENet-discuss at cubik.org
http://lists.cubik.org/mailman/listinfo/enet-discuss
_______________________________________________
ENet-discuss mailing list
ENet-discuss at cubik.org
http://lists.cubik.org/mailman/listinfo/enet-discuss
_______________________________________________
ENet-discuss mailing list
ENet-discuss at cubik.org
http://lists.cubik.org/mailman/listinfo/enet-discuss
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cubik.org/pipermail/enet-discuss/attachments/20110428/970343c6/attachment.html>
Lee Salzman
2011-04-28 09:45:28 UTC
Permalink
Make sure the ENet header files you are including into the code and the linked version of the library are definitively from the same version. If they were not, and due to changes in the ENetPeer structure in different versions, your code and the library could be working off of different layouts and causing all sorts of nastiness.
I really need some help. This bug has stalled me for 2 days and I am getting no where at all.
What happens is when I change a peer's void* I can no longer call enet_host_service() without making a segmentation fault.
I have pushed the bugged code to my repository so you can look at it.
https://github.com/Queatz/Simple-C---Game-Engine/blob/master/engine/network.cpp
As you can see, at line 147 I assign something to the peer data if someone connects. Now, just above that on line 138 you see the call to enet_host_service where the segmentation fault happens. It happens consistently on the next call (which is of a none event type) after a client connects, causing that peer data to get set. With that line (147) commented I get no segmentation fault at all.
If someone could see something I am missing I would be very grateful.
Jacob F.
2011-04-28 17:56:32 UTC
Permalink
Yes, was just told this in #enet and it was the problem. It works excellent
now, thanks for the help.
Post by Lee Salzman
Make sure the ENet header files you are including into the code and the
linked version of the library are definitively from the same version. If
they were not, and due to changes in the ENetPeer structure in different
versions, your code and the library could be working off of different
layouts and causing all sorts of nastiness.
Post by Jacob F.
I really need some help. This bug has stalled me for 2 days and I am
getting no where at all.
What happens is when I change a peer's void* I can no longer call
enet_host_service() without making a segmentation fault.
I have pushed the bugged code to my repository so you can look at it.
https://github.com/Queatz/Simple-C---Game-Engine/blob/master/engine/network.cpp
As you can see, at line 147 I assign something to the peer data if someone
connects. Now, just above that on line 138 you see the call to
enet_host_service where the segmentation fault happens. It happens
consistently on the next call (which is of a none event type) after a client
connects, causing that peer data to get set. With that line (147) commented
I get no segmentation fault at all.
If someone could see something I am missing I would be very grateful.
_______________________________________________
ENet-discuss mailing list
ENet-discuss at cubik.org
http://lists.cubik.org/mailman/listinfo/enet-discuss
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cubik.org/pipermail/enet-discuss/attachments/20110428/24e6383f/attachment-0001.html>
Loading...