Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

fix(gameclient): widen the listbox scroll offset past a signed short

Olcay Seygance966c3e8479
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 14a1c1b0f..6c0f1edb2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -399,6 +399,11 @@ The game overwrites the same replay file after every match, so the only way to k
and rename the file before starting the next one. Turn on replay archiving and each game is also
saved under its own date-and-time name, in its own folder, automatically.
+Keep enough of them and the list itself used to give up. Past roughly two thousand rows the scroll
+position wrapped around to a negative number: the view snapped somewhere it should not be and
+scrolling back up stopped responding. Any long list in the game -- replays, maps, a busy chat room
+-- now scrolls the whole way, however many entries it holds.
+
## Placing a building, then changing your mind
Right-clicking to cancel a building you were about to place used to also deselect the builder, so
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/Gadget.h b/GeneralsMD/Code/GameEngine/Include/GameClient/Gadget.h
index 538391ed3..66e741573 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/Gadget.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/Gadget.h
@@ -377,11 +377,15 @@ typedef struct _ListboxData
Int selectPos; // Position of current selected entry (for SINGLE select)
Int *selections; // Pointer to array of selections (for MULTI select)
- Short displayHeight; // Height in pixels of listbox display region
+ Int displayHeight; // Height in pixels of listbox display region
// this is computed based on the existance
// of a title or not.
UnsignedInt doubleClickTime; //
- Short displayPos; // Position of current display entry in pixels
+ // both of these are pixel offsets into totalHeight, which is an Int, and displayPos is assigned
+ // straight out of ListEntryRow::listHeight. A list whose entries add up to more than 32767
+ // pixels - a few thousand chat lines or replays - used to wrap these to a negative number and
+ // the scrollbar jumped to the wrong end of the list.
+ Int displayPos; // Position of current display entry in pixels
} ListboxData;
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index 01086ad73..6842d8a36 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -46,6 +46,7 @@
#include "Common/AudioRandomValue.h"
#include "GameNetwork/CrcAgreement.h"
#include "Common/RadarShroudCache.h"
+#include "GameClient/Gadget.h"
#include "GameNetwork/NetworkUtil.h"
#include "GameNetwork/NetCommandList.h"
#include "GameNetwork/GameInfo.h"
@@ -4256,3 +4257,28 @@ TEST(radar_shroud_cache_clear_owes_the_whole_texture_a_write_again)
CHECK_EQ( cache.getDirtyMaxY(), 127 );
CHECK_EQ( (Int)cache.getAlpha( 60, 60 ), 0 );
}
+
+// ---------------------------------------------------------------------------------------------
+// A listbox scroll offset is a pixel offset into the running height of every entry above it.
+// Both of the fields that carry it used to be Short while the running total they are compared
+// with, and assigned from, is an Int.
+// ---------------------------------------------------------------------------------------------
+TEST(listbox_scroll_offset_survives_a_list_taller_than_a_signed_short)
+{
+ ListboxData list;
+ memset( &list, 0, sizeof( list ) );
+
+ // four thousand chat lines or replay files at fifteen pixels a row
+ list.totalHeight = 60000;
+ list.displayHeight = 200;
+ list.displayPos = 45000;
+
+ CHECK_EQ( list.displayPos, 45000 );
+ CHECK( list.displayPos > 0 );
+ CHECK( list.displayPos + list.displayHeight <= list.totalHeight );
+
+ // scrolling to the bottom, the way the slider and the mouse wheel do it
+ list.displayPos = list.totalHeight - list.displayHeight;
+ CHECK_EQ( list.displayPos, 59800 );
+ CHECK( list.displayPos > 0 );
+}