Closed Nilsolm closed 3 years ago
Thanks - is it reproducible?
A change I often make to get better debugging symbols for individual plugins is:
--- a/plugins/CMakeLists.txt
+++ b/plugins/CMakeLists.txt
@@ -113,7 +113,7 @@ if(BUILD_SUPPORTED)
dfhack_plugin(dig dig.cpp)
dfhack_plugin(digFlood digFlood.cpp)
add_subdirectory(diggingInvaders)
- dfhack_plugin(dwarfvet dwarfvet.cpp)
+ dfhack_plugin(dwarfvet dwarfvet.cpp COMPILE_FLAGS_GCC "-O0 -g")
dfhack_plugin(dwarfmonitor dwarfmonitor.cpp LINK_LIBRARIES lua)
add_subdirectory(embark-assistant)
dfhack_plugin(embark-tools embark-tools.cpp)
I couldn't find a way to reliably reproduce it, unfortunately. It doesn't happen every time dischargePatient is called.
I'll dig a bit deeper and see if I can find out more.
Taking a brief look at dwarfvet, I noticed that the Patient
structure's spot_index
field is uninitialized - it's provided to the constructor, but it's never actually saved. This is almost definitely what's responsible for the crash, which happened at the line spots_in_use[(*accepted_patient)->getSpotIndex()] = false;
.
The following patch might work, though I don't have the means to test it right now:
diff --git a/plugins/dwarfvet.cpp b/plugins/dwarfvet.cpp
index 6826f38..604a229 100644
--- a/plugins/dwarfvet.cpp
+++ b/plugins/dwarfvet.cpp
@@ -72,21 +72,22 @@ struct hospital_spot {
class Patient {
public:
// Constructor/Deconstrctor
- Patient(int32_t id, int spot_index, int32_t x, int32_t y, int32_t z);
+ Patient(int32_t id, size_t spot_index, int32_t x, int32_t y, int32_t z);
int32_t getID() { return this->id; };
- int32_t getSpotIndex() { return this->spot_index; };
+ size_t getSpotIndex() { return this->spot_index; };
int32_t returnX() { return this->spot_in_hospital.x; };
int32_t returnY() { return this->spot_in_hospital.y; };
int32_t returnZ() { return this->spot_in_hospital.z; };
private:
struct hospital_spot spot_in_hospital;
- int id;
- int spot_index;
+ int32_t id;
+ size_t spot_index;
};
-Patient::Patient(int32_t id, int32_t spot_index, int32_t x, int32_t y, int32_t z){
+Patient::Patient(int32_t id, size_t spot_index, int32_t x, int32_t y, int32_t z){
this->id = id;
+ this->spot_index = spot_index;
this->spot_in_hospital.x = x;
this->spot_in_hospital.y = y;
this->spot_in_hospital.z = z;
(I also cleaned up a few types that were either mismatched or inappropriate)
I noticed that dwarfvet is a bit crashy currently so I've been trying to track down the possible causes. I got one of them which sometimes leads to a crash when an animal is discharged from the hospital after having been treated:
DFHack version: 0.47.04-r3 (development build 0.47.04-r3-151-gddbd22fc) on x86_64