quadra-game / quadra

An addictive action puzzle game with single player and multiplayer capabilities (Internet or LAN).
GNU Lesser General Public License v2.1
28 stars 18 forks source link

Quadra crashed in single player mode when no network is available #85

Closed pphaneuf closed 10 years ago

pphaneuf commented 10 years ago

Quadra crashes (segfault) when using single player mode in offline mode (all network interfaces down)

I have traced the problem, it is in the method Game::prepare_logging() in the following rows: Dword addr=net->host_adr_pub[0]; char st[65]; Net::stringaddress(st, addr, config.info.port_number); log.add(Packet_serverlog::Var("server_address", st));

It looks like the "addr" is faulty, any attempt to access it will cause a segmentation fault. It also happens when attempting to display its value using msgbox() or printf().

If I replace the addr assignation with the following, it works fine: Dword addr = 0

Commenting out Net::stringaddress ... also solves the issue.

This problem occurs in trunk and quadra-sdl.

I also wonder why quadra needs/checks for network access in single player mode. I think it would be better to instantiate the network classes only when explicitly selecting multiplayer->network mode.

pphaneuf commented 10 years ago

Should be fixed with r628 (in trunk, I'll merge to quadra-sdl momentarily). I couldn't reproduce the problem in a "natural" way (Mac OS X keeps a close watch on its interfaces, and brings the loopback interface up the moment you bring it down, as it knows Quadra crashing is a sad event!). I'm a bit curious as to how this happened, as from a quick look at the code, it looks like it should always have something in that array, but now it should be bulletproof.

I agree that, ideally, networking should be involved only when needed, but Quadra's source code is subtle and quick to anger, so I think it's better not to mess with this at this point. ;-)