Troubleshooting game crash

I have a game that just started crashing. I am having a hard time diagnosing the problem. I get the

window.
The game doesn’t always crash at the same time.

The command window doesn’t report any exceptions. I put print statements all over my code to track the execution, but it seems to crash outside of my loops.

I changed my config.prc file to have:

notify-level warning spam
default-directnotify-level info
notify-output mygame-log.txt 

but it’s not really helping me track down the error. I’ll paste the last few lines here, in case they are meaningful to anybody:

And the next time it ran, here is the last part of the output:

Without going into details about what I’m doing in the game (I have a feeling the error is related to sockets), how can I go about getting more information about how/why the game crashed? (or better understanding the info I have?)

Any help would be greatly appreciated because the project has been going great until now, but I only have four days to complete it!

Mysterious hard crashes are vexing and can be difficult to track down. My sympathies.

If you have the patience, you might do well to install Microsoft Visual Studio, download Panda from source, and build it yourself. Then, when you get the crash, it should offer you to open up a debugger, from whence you can see the C++ call stack at the time of the crash. That will be very informative.

Other than that, all I can suggest is what you are doing: try to insert print statements and/or comment out code paths in an attempt to isolate the problem.

The logs you post are unfortunately not very helpful. They appear to be perfectly normal log output.

David

OK, I’m in the process of compiling panda, so as to get under the hood and see where the problem is coming from.

In the meantime, I’d like to ask about my specific problem with sockets. I am using a QueuedConnectionManager, QueuedConnectionReader, and a ConnectionWriter. My game acts as a client and communicates with a server program (not written in python, nothing to do with panda).

Since the server app is not using panda and datagrams, I set everything to raw mode and send everything using fixed strings. I can’t remember where I stole this code from, but my game has a client class that polls the connection reader:

def tskReaderPolling(self, taskdata):
    if self.cReader.dataAvailable():
        datagram=NetDatagram()
        if self.cReader.getData(datagram):
            msg = datagram.getMessage()
            self.messagesFromServer.append(msg)
    return Task.cont

On the game update loop, I iterate through socketClient.messagesFromServer and parse and handle them. I have verified that I am correctly parsing the messages and handling them as expected.

However, upon certain messages (not the same one, I can’t find a pattern), python crashes hard.

I’m working with another programmer who programmed the server end, and he is concerned about me using polling rather than something like python’s OnDataAvailable event (he told me about this event, but I can’t find documentation on it).

What is the board’s suggestion on how to approach this problem?
Should I just use python’s socket implementation straight up (I think I remember reading that is uses blocking, which would prevent my game update loop from running, if I understand it correctly)?
Is there a way to implement an event-based message receiving system with panda’s classes, rather than using polling?
I’m new to sockets and inter-process communication and I’m just trying to wrap my head around what different approaches are available.

Well, I don’t know what’s wrong with using polling. If you really wanted to avoid it, probably the best way would be to use blocking I/O in a thread. But that has its own set of complications, and I really don’t recommend it. In fact, if you were to ask my opinion, I would specifically recommend a polling network loop as the best way to implement client I/O in general.

Server I/O is a different beast altogether, and depending on your server design requirements, blocking I/O might be preferred. Though I’ve found that even on a server handling thousands of connections, polling is likely to be a bit faster.

Speaking of threads, are you creating your connection reader with one or more threads? That is, are you passing 1 or higher as the second parameter to your QueuedConnectionReader constructor? If so, try passing 0 for now, just to eliminate the possibility of some misuse of threads causing your problem, or making it difficult to see where the problem occurs. In fact, you might try putting:

support-threads 0

in your Config.prc to underscore the point.

David

No, I’m not dealing with threading. I passed 0 to the QueuedConnectionReader. I added support-threads 0 to config.prc just to make sure, but the same thing is happening.

Now I’m having trouble building panda 1.6.2. With makepanda --everything, it runs for about an hour, but comes up with a linker error:

I tried makepanda --nothing, and got a compile error:

I don’t think I have time to troubleshoot this for long. I might go back and try a different approach to sockets…

I gave up on building Panda. I went back and reimplemented my socket client class to use Python’s socket stuff directly. I set the socket to non-blocking and poll it once per game update. It still crashed the same way.

Then I realized that every message from the server ended with ‘\r\n’. Once I stripped this out of the message, no more crashes! I never found out exactly where everything exploded trying to handle the string ‘\r\n’, but as long as it works, I’m good.

Thanks for your help.

Fantastic! Congratulations on finding and fixing the problem.

David

And for the record, those build issues are already fixed in the latest CVS trunk of Panda3D.