Codechange: Increase scrollbar length limit to 32bits #8006
Conversation
There are 3 occurrences of |
f37d429
to
e3022c0
good catch, seems I'd missed quite a few |
462d4f2
to
77b52dc
77b52dc
to
50e6c94
50e6c94
to
9767467
9767467
to
f8d0365
f8d0365
to
800b469
No longer crashes the game, tried a few windows, scrolling seems to work fine. I am just there will be some window that doesn't work as we want or what-ever, but we will fix that when people report it :D |
Shouldn't be merged yet, lots of size_t -> uint warnings on Windows. Going to have to readd a load of casts :( |
800b469
to
c879ecb
I've updated it to just increase the size, no fiddling around with type-signedness. ...Except for some reason changing it from |
c879ecb
to
b91758d
This code has a lot of typecasting to stop the compiler complaining about signed/unsigned type ranges, but it's not actually range safe as far as I can tell. If the scrollbar isn't going to work properly with more than 2^31 elements in the list anyway, just make it use a plain signed int type and do some sanity checks against negative numbers in a few strategic locations. |
@@ -731,7 +731,7 @@ struct SelectCompanyLiveryWindow : public Window { | |||
/* Position scrollbar to selected group */ | |||
for (uint i = 0; i < this->rows; i++) { | |||
if (this->groups[i]->index == sel) { | |||
this->vscroll->SetPosition(Clamp(i - this->vscroll->GetCapacity() / 2, 0, std::max(this->vscroll->GetCount() - this->vscroll->GetCapacity(), 0))); | |||
this->vscroll->SetPosition(Clamp(i - this->vscroll->GetCapacity() / 2, 0, std::max<int>(this->vscroll->GetCount() - this->vscroll->GetCapacity(), 0))); |
nielsmh
Apr 10, 2021
Contributor
This line is really confusing. Actually I'm not sure why Scrollbar::SetPosition
assert-checks that the parameter is in range, instead of just clamping it into range itself. Letting the scrollbar handle that would make all the using code simpler, wouldn't it?
This line is really confusing. Actually I'm not sure why Scrollbar::SetPosition
assert-checks that the parameter is in range, instead of just clamping it into range itself. Letting the scrollbar handle that would make all the using code simpler, wouldn't it?
Also makes scrollbar internals properly use unsigned numbers. Bumped scrollbar limit to uint(32) as well, because why not
Fixes #7613