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

Assertion failure "Expression: cannot seek value-initialized vector iterator" #7434

Closed
glx22 opened this issue Mar 29, 2019 · 3 comments
Closed

Comments

@glx22
Copy link
Contributor

@glx22 glx22 commented Mar 29, 2019

Version of OpenTTD

20190328-master-gacb09eb9a8

Expected result

No crash.

Actual result

Debug Assertion Failed!

Program: ...t\GitHub\glx22\OpenTTD\projects\..\objs\x64\Debug\openttd.exe
File: c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\vector
Line: 114

Expression: cannot seek value-initialized vector iterator

For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.

(Press Retry to debug the application)

Stack:
 	openttd.exe!std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<ContentInfo const *> > >::_Verify_offset(const __int64 _Off) Ligne 114	C++
 	openttd.exe!std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<ContentInfo const *> > >::operator+=(const __int64 _Off) Ligne 130	C++
 	openttd.exe!std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<ContentInfo const *> > >::operator+(const __int64 _Off) Ligne 137	C++
>	openttd.exe!NetworkContentListWindow::DrawMatrix(const Rect & r) Ligne 639	C++
 	openttd.exe!NetworkContentListWindow::DrawWidget(const Rect & r, int widget) Ligne 602	C++
 	openttd.exe!NWidgetLeaf::Draw(const Window * w) Ligne 2520	C++
 	openttd.exe!NWidgetPIPContainer::Draw(const Window * w) Ligne 1114	C++
 	openttd.exe!NWidgetPIPContainer::Draw(const Window * w) Ligne 1114	C++
 	openttd.exe!NWidgetPIPContainer::Draw(const Window * w) Ligne 1114	C++
 	openttd.exe!NWidgetPIPContainer::Draw(const Window * w) Ligne 1114	C++
 	openttd.exe!NWidgetPIPContainer::Draw(const Window * w) Ligne 1114	C++
 	openttd.exe!NWidgetBackground::Draw(const Window * w) Ligne 1865	C++
 	openttd.exe!NWidgetPIPContainer::Draw(const Window * w) Ligne 1114	C++
 	openttd.exe!Window::DrawWidgets() Ligne 608	C++
 	openttd.exe!NetworkContentListWindow::OnPaint() Ligne 614	C++
 	openttd.exe!DrawOverlappedWindow(Window * w, int left, int top, int right, int bottom) Ligne 933	C++
 	openttd.exe!DrawOverlappedWindowForAll(int left, int top, int right, int bottom) Ligne 960	C++
 	openttd.exe!RedrawScreenRect(int left, int top, int right, int bottom) Ligne 1292	C++
 	openttd.exe!DrawDirtyBlocks() Ligne 1390	C++
 	openttd.exe!UpdateWindows() Ligne 3185	C++
 	openttd.exe!VideoDriver_Win32::MainLoop() Ligne 1280	C++
 	openttd.exe!openttd_main(int argc, char * * argv) Ligne 849	C++
 	openttd.exe!WinMain(HINSTANCE__ * hInstance, HINSTANCE__ * hPrevInstance, char * lpCmdLine, int nCmdShow) Ligne 443	C++
 	[Code externe]	

Steps to reproduce

From main menu, open newgrf window, click on "check online content"
Clicking on "online content" from main window fails too of course.

@LordAro

This comment has been minimized.

Copy link
Member

@LordAro LordAro commented Mar 29, 2019

auto iter = this->content.begin() + this->vscroll->GetPosition();
auto end = iter + this->vscroll->GetCapacity();
if (end > this->content.end())
end = this->content.end();

that'd do it

@PeterN

This comment has been minimized.

Copy link
Member

@PeterN PeterN commented Mar 29, 2019

Something like this?

-               auto end = iter + this->vscroll->GetCapacity();
-               if (end > this->content.end())
-                       end = this->content.end();
+               size_t last = this->vscroll->GetPosition() + this->vscroll->GetCapacity();
+               auto end = (last < this->content.size()) ? this->content.begin() + last : this->content.end();
@glx22

This comment has been minimized.

Copy link
Contributor Author

@glx22 glx22 commented Mar 29, 2019

@PeterN's solution works.

PeterN added a commit to PeterN/OpenTTD that referenced this issue Mar 29, 2019
@PeterN PeterN closed this in #7437 Mar 29, 2019
PeterN added a commit that referenced this issue Mar 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.