Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some crashes 2025-01-13 #987

Merged

Conversation

stephengtuggy
Copy link
Contributor

@stephengtuggy stephengtuggy commented Jan 13, 2025

Code Changes:

Issues:

Purpose:

@stephengtuggy stephengtuggy added this to the 0.10.x milestone Jan 13, 2025
@stephengtuggy stephengtuggy self-assigned this Jan 13, 2025
@stephengtuggy
Copy link
Contributor Author

Note that this PR includes most of the changes from #974 , so should probably be tackled after #974 is out of the way.

@stephengtuggy stephengtuggy marked this pull request as ready for review January 14, 2025 03:41
@evertvorster
Copy link
Contributor

Hi there!

This does fix the crashing when loading a campaign #981

Pressing "m" in flight still causes a segfault.

Also, it breaks ship info and purchasing repair and refuel's description, among other things, on a new campaign.

Copy link
Member

@BenjamenMeyer BenjamenMeyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this on top of the other work I reviewed? seems like a lot of duplication.

@evertvorster
Copy link
Contributor

Just ran a little test now, and the python errors have changed somewhat.
When clicking on ship's information, it states that ship_view.py was not found, and when clicking on player info, it states that player_info.py was not found.
In upgrades, it complains about upgrade_view.py not being found.

So, you are on the right track, I believe.

@stephengtuggy
Copy link
Contributor Author

Just ran a little test now, and the python errors have changed somewhat. When clicking on ship's information, it states that ship_view.py was not found, and when clicking on player info, it states that player_info.py was not found. In upgrades, it complains about upgrade_view.py not being found.

So, you are on the right track, I believe.

LOL that's good to hear.

In my very latest changes, I have succeeded in getting the .py files to load. Now it's just a matter of debugging the Python code! 😃

@evertvorster
Copy link
Contributor

Much, much improved!

Upgrades now work, as do player information.
The only bit that still throws an error is ship info:

image

Once this is sorted, I'll test all the major functions of the game on my system. They all worked pretty much ok the last time I tested, but it is best to make sure.

@stephengtuggy
Copy link
Contributor Author

Much, much improved!

Upgrades now work, as do player information. The only bit that still throws an error is ship info:

image

Once this is sorted, I'll test all the major functions of the game on my system. They all worked pretty much ok the last time I tested, but it is best to make sure.

That's really good to hear! Ship View is now working for me too. For that, I had to make some changes to ship_view.py in the assets. I have a PR open for that here: vegastrike/Assets-Production#144

@evertvorster
Copy link
Contributor

Looking VERY good!

Only issue I see now is that in ship info it tells me that there is no shielding:

image

This may be because of the change in how many facets a shield has, and not related to this PR at all. Once this one is merged, I'll raise an issue on the engine for this one specifically.

Copy link
Contributor

@evertvorster evertvorster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested this for every major function that I can think of, and everything works.
I did notice a few bugs from long ago, but not relevant to this PR.

@kheckwrecker
Copy link

I tested this in Windows. I can now launch a new campaign, which is good. When I flew to a nearby mining base and requested docking clearance, however, it crashed to the desktop.

@evertvorster
Copy link
Contributor

I tested this in Windows. I can now launch a new campaign, which is good. When I flew to a nearby mining base and requested docking clearance, however, it crashed to the desktop.

Do you have any logs for this? I have also had a crash, but thought it was due to my hitting the "pause" button by mistake. It's right next to the Delete/Insert key on this laptop. Unfortunately I did not grab a log, and it did not crash on the next couple of tries.

@kheckwrecker
Copy link

The only log I can find (in my .vegastrike/logs directory) has nothing in it related to the crash. And worse than that, when I tried it again, it works fine without any crash. I hate intermittent bugs.

@stephengtuggy
Copy link
Contributor Author

@evertvorster that's awesome!

@kheckwrecker I know, those are the worst. Unfortunately, the game has had intermittent crashes for quite a while. Probably not much we can do about that in this PR. Soon, though. Hopefully.

@royfalk
Copy link
Contributor

royfalk commented Jan 16, 2025

I'm going to hold off on reviewing this until we merge #974. There are too many changes otherwise.

Font font(font_array[0], font_array[1]);
c->setFont(font);
if (font_array.size() < 2) {
VS_LOG(error, "controls_factory getControl(): font_array doesn't have enough elements");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why this condition is happening. We will probably want to investigate further. But for now, this keeps the game from crashing at this point.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, this raises a bigger philosophical question of how much crap are we willing to let the engine take from the assets?

For JSON files, the file obviously needs to be formatted correctly or parsing will fail. Most JSON files are crucial to the game, so may as well crash it with an error.

But this is inside content and for a specific control so it points to an error in how I converted fonts to controls. Best open an issue/bug for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@royfalk royfalk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still a long review but much better. Thanks.

@BenjamenMeyer we may need to think about syncing our efforts so we don't write the same code twice. At least some of the code is stuff I've written but was waiting for the cmake stuff to get merged and splitting other stuff from it (like #969 ) so the actual review of the PR will be shorter and easier.

@@ -114,8 +116,8 @@ std::vector<std::string> getWeapFilterVec() {
std::vector<std::string> weapfiltervec = getWeapFilterVec();

bool upgradeNotAddedToCargo(std::string category) {
for (unsigned int i = 0; i < weapfiltervec.size(); ++i) {
if (weapfiltervec[i].find(category) == 0) {
for (const auto & i : weapfiltervec) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally don't have a problem with auto, but @BenjamenMeyer frowns upon them.
Therefore, where I can deduce the type, I'll use it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BenjamenMeyer has said previously that he's OK with auto for iterators.

@@ -527,7 +529,7 @@ void BaseComputer::constructControls(void) {
return;
}

if (m_displayModes.size() != 1 || m_displayModes[0] != NETWORK) {
if (m_displayModes.size() != 1 || m_displayModes.at(0) != NETWORK) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume these fail for some OS'es. I have the dangest errors in the CI, where my machine blissfully compiles and runs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These don't fail to compile on any OS particularly. This is just to add bounds checking, to make sure we're not reading or writing outside the bounds of the collection.

@@ -3942,7 +3943,7 @@ string buildUpgradeDescription(Cargo &item) {
const std::string key = item.GetName() + "__upgrades";
PyObject* args = PyTuple_Pack(1, PyUnicode_FromString(key.c_str()));
const std::string text = GetString("get_upgrade_info", "upgrade_view",
"python/base_computer/upgrade_view.py", args);
"upgrade_view.py", args);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you expand on why you did this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You were specifying the subfolder ("python/base_computer") twice. Once here, and once in the Python path initialization code. That's part of why VS was failing to locate these Python scripts.

Now the subfolder is specified in only one place: initpaths(). Which is more or less in keeping with the way existing code did things.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm concerned that we could potentially have two utils.py somewhere with unexpected and hard to debug errors.

Font font(font_array[0], font_array[1]);
c->setFont(font);
if (font_array.size() < 2) {
VS_LOG(error, "controls_factory getControl(): font_array doesn't have enough elements");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, this raises a bigger philosophical question of how much crap are we willing to let the engine take from the assets?

For JSON files, the file obviously needs to be formatted correctly or parsing will fail. Most JSON files are crucial to the game, so may as well crash it with an error.

But this is inside content and for a specific control so it points to an error in how I converted fonts to controls. Best open an issue/bug for this.

@@ -524,7 +524,7 @@ float Damageable::RShieldData() const {
void Damageable::ArmorData(float armor[8]) const {
Damageable *damageable = const_cast<Damageable *>(this);
DamageableLayer armor_layer = damageable->GetArmorLayer();
for (int i = 0; i < 8; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. You caught a bug of mine here. Did this segfault or fill the array with junk?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I actually hit this section of code during my testing. If I had, though, I think a segfault would have been most likely. The destination array was too small to write 8 elements to.

(armor[1] + armor[3] + armor[5]
+ armor[7]) / (float) (StartArmor[1] + StartArmor[3] + StartArmor[5] + StartArmor[7]),
parent->GetHull() / (*maxhull), true, false);
DrawHUDSprite(this, draw_damage_sprite ? parent->getHudImage() : nullptr, .6, x, y, w, h,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of the stuff for armor and 8 facets is stuff I'm waiting to submit. It would be interesting to compare and also a bit frustrating.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. We would do well to communicate a bit better in real time about stuff we're working on. That isn't always feasible though, what with time zone differences and such.

Copy link
Contributor

@royfalk royfalk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@stephengtuggy stephengtuggy merged commit 871a692 into vegastrike:master Jan 16, 2025
16 checks passed
@stephengtuggy stephengtuggy deleted the fix/index_out_of_bounds_2025-01-11 branch January 16, 2025 21:41
@stephengtuggy
Copy link
Contributor Author

LGTM

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Game crashes upon loading a new campaign.
5 participants