News:

Do you need help?
Simutrans Wiki Manual can help you to play and extend Simutrans. In 9 languages.

Virtual function call

Started by zook2, August 13, 2014, 02:50:38 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

zook2

Not even a crash report popup...

The newest MSVC I seem to have is msvcr100.dll (10.00.40219.1)

jamespetts

Can you upload a saved game in which this can be reproduced?
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

zook2

Sorry, it's the first time I've seen it and it hasn't cropped up again. And I wasn't doing anything in the game at the moment; the game window had been in the background.

jamespetts

Hmm - odd. If you notice any pattern for this occurring or can reproduce it, please let me know; otherwise, I am afraid that I shall not be able to track down the cause of this.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

DrSuperGood

I recall coming across this error being highly specific. Something like it gets generated in 3 main cases.
1. Calling a virtual function in constructors. Some compilers may allow it at certain times such as for members of a parent but mostly it should be avoided as chances are it will not do anything like what you want.
2. Calling a virtual function in destructors. Due to how objects get broken down it is not safe to call virtual functions as what they operate on may no longer be defined as existing.
However these will usually throw compile time errors as it is easy for a compiler to see that the virtual table is not initialized for an object at that stage of construction. This unfortunately leaves the final cause...
3. Calling a virtual function on an object composing of garbage. This can be a result of a dangling reference/pointer where the memory once representing the object was freed and re-allocated to something else leaving garbage for the previous object's virtual function table.

The only really viable way to find the cause of 3 (outside of major time consuming testing of every aspect of the game) is to reproduce the error reliably and run with a debugger.

It may help to explain what you were doing when it crashed. As that would limit the scope where it could be (important for future investigations).

zook2

I had the game running in the background, reading the wikipedia.

Junna

What is the reason for the depot message, or was it left over from before you started reading?


prissi

If you delete something incorrectly, you can have a virtual function.

But mostly likely it is from accessing a dead objects (number 3 above). A short explaination is that many stuff (like trees) are in simutrans' own memory management to have less overhead. Such "deleted" objects cannot cause a unvalid memory access, because that memory still belongs to Simutrans. However, they are most likely reused or partly overwritten and contain garbage.

jamespetts

Quote from: prissi on August 19, 2014, 08:56:21 PM
If you delete something incorrectly, you can have a virtual function.

But mostly likely it is from accessing a dead objects (number 3 above). A short explaination is that many stuff (like trees) are in simutrans' own memory management to have less overhead. Such "deleted" objects cannot cause a unvalid memory access, because that memory still belongs to Simutrans. However, they are most likely reused or partly overwritten and contain garbage.

Thank you; this is helpful. I wonder whether it would be helpful to have a debugging preprocessor definition to disable the internal memory management system (and use actual new/delete calls) that can be invoked when looking for issues such as these?
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

prissi

There is a heap only debugger. But the OS can handle only pages of 4 kB, i.e. any object in Simutrans would use 4 kB. I tried this once but it seems Windows has less handles for those pages than Simutrans needs.

There is however a valgrind switch to compile which make valgrind aware of the freelist memory module. DrMemory hooks into the std memory allocation routines on windows, so it can be made aware too. You can easily change freelist to call malloc and free, but then do not complain when opening a map takes about 5-6 times longer ...

jamespetts

Quote from: prissi on August 20, 2014, 11:37:17 PM
There is a heap only debugger. But the OS can handle only pages of 4 kB, i.e. any object in Simutrans would use 4 kB. I tried this once but it seems Windows has less handles for those pages than Simutrans needs.

There is however a valgrind switch to compile which make valgrind aware of the freelist memory module. DrMemory hooks into the std memory allocation routines on windows, so it can be made aware too. You can easily change freelist to call malloc and free, but then do not complain when opening a map takes about 5-6 times longer ...

Ahh, that Valgrind switch sounds helpful. How does one invoke it?
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

zook2

Just a wild and uninformed guess here: could the problem be connected to industries closing down ? Because it crashed while I hadn't done anything myself in the game for a while and a closure happens very rarely, while other objects get destroyed all the time.

jamespetts

That's certainly possible, Zoosk2: closing industries involves deleting objects, and this error can be associated with things going wrong when objects are deleted, so this may well be a useful clue: thank you.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

prissi

To use malloc/free:

remove freelist.cc from the project

change freelest.h to

#ifndef freelist_t_h
#define freelist_t_h

/**
* Helper class to organize small memory objects i.e. nodes for linked lists
* and such.
*
* @author Hanjsjörg Malthaner
*/
class freelist_t
{
public:
static void *gimme_node( size_t size ) { return calloc(size,1); }
static void putback_node( size_t, void *p ) { free(p); }

// clears all list memories
static void free_all_nodes() {}
};

#endif

should do the trick.

jamespetts

Splendid - thank you. That can easily be done with preprocessor directives, I think.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.