https://issues.qgis.org/https://issues.qgis.org/favicon.ico2013-12-14T13:08:24ZQGIS Issue TrackingQGIS Application - Bug report #9213: 'bad_alloc' error at QGIS starthttps://issues.qgis.org/issues/9213?journal_id=469622013-12-14T13:08:24ZLuigi Pirelliluipir@gmail.com
<ul></ul><p>append to me too...</p>
<p>first we had experienced with this error on windows (32b) loading plugin containing a lot of data (300MB) and we solved separating plugin from test data. But I started to have this error since last week randomly (three times) and I'm on debian wheezy. I wasn't able to reproduce the error.</p> QGIS Application - Bug report #9213: 'bad_alloc' error at QGIS starthttps://issues.qgis.org/issues/9213?journal_id=469632013-12-14T13:22:50ZGiovanni Allegrigiohappy@gmail.com
<ul></ul><p>I confirm the same random problem, both on Ubuntu and Xubuntu 12.04 with QGIS 2.0.1 packages from UbuntuGis PPA</p> QGIS Application - Bug report #9213: 'bad_alloc' error at QGIS starthttps://issues.qgis.org/issues/9213?journal_id=469672013-12-15T02:05:00ZLuigi Pirelliluipir@gmail.com
<ul></ul><p>Luigi Pirelli wrote:</p>
<blockquote>
<p>append to me too...</p>
<p>first we had experienced with this error on windows (32b) loading plugin containing a lot of data (300MB) and we solved separating plugin from test data. But I started to have this error since last week randomly (three times) and I'm on debian wheezy (compiled). I wasn't able to reproduce the error.</p>
</blockquote> QGIS Application - Bug report #9213: 'bad_alloc' error at QGIS starthttps://issues.qgis.org/issues/9213?journal_id=469802013-12-16T07:50:11ZIvan Mincikivan.mincik@gmail.com
<ul></ul><p>At least in my case, it seems that this problem appears more frequently when running Ubuntu in VirtualBox than on physical machine.</p> QGIS Application - Bug report #9213: 'bad_alloc' error at QGIS starthttps://issues.qgis.org/issues/9213?journal_id=469832013-12-16T10:26:58ZJürgen Fischerjef@norbit.de
<ul><li><strong>Assignee</strong> deleted (<del><i>Jürgen Fischer</i></del>)</li></ul> QGIS Application - Bug report #9213: 'bad_alloc' error at QGIS starthttps://issues.qgis.org/issues/9213?journal_id=470182013-12-17T23:47:20ZMatthias Kuhn
<ul></ul><p>Just got the same for the first time on my Fedora machine (using a freshly compiled master). The last time I have seen this was on a Windows machine using an early 1.9 dev build.</p>
<p>At the same time I lost my whole local configuration.</p> QGIS Application - Bug report #9213: 'bad_alloc' error at QGIS starthttps://issues.qgis.org/issues/9213?journal_id=470212013-12-18T01:04:02ZIvan Mincikivan.mincik@gmail.com
<ul></ul><p>Could it be some problem in counting extent and starting scale of map canvas from QGIS application window ? From debug messages it seems that the error is thrown just before setting scale.</p> QGIS Application - Bug report #9213: 'bad_alloc' error at QGIS starthttps://issues.qgis.org/issues/9213?journal_id=471732014-01-01T12:32:06ZIvan Mincikivan.mincik@gmail.com
<ul></ul><p>I have found that if I run QGIS from command line this problem occurs less frequently than when running from applications menu. Any ideas ?</p> QGIS Application - Bug report #9213: 'bad_alloc' error at QGIS starthttps://issues.qgis.org/issues/9213?journal_id=481382014-02-04T14:54:37ZIvan Mincikivan.mincik@gmail.com
<ul></ul><p>Tests with latest master has shown that QGIS will throw bad_alloc error when there is less than 880 MiB of virtual memory on 64bit system or 310 MiB on 32 bit system. Error is thrown from 'setEditText' from 'QgsScaleComboBox::setScaleString' in 'src/gui/qgsscalecombobox.cpp'.</p>
<p>QGIS is allocating 64 MiB at start. I do not understand why it grows to 800 suddenly.</p>
<p>Test was done by Ferdinand Majerech.</p> QGIS Application - Bug report #9213: 'bad_alloc' error at QGIS starthttps://issues.qgis.org/issues/9213?journal_id=481542014-02-05T11:48:30ZFerdinand Majerechkiithsacmp@gmail.com
<ul></ul><p>Memory usage doesn't really 'grow' to ~880 MiB; QGIS is simply unable to allocate if it doesn't have that much virtual memory<br />(which can be limited by `ulimit -Sv <SIZE>` where <SIZE> is the virtual memory limit in kiB).<br />The same thing happens to various other programs that pull a lot of dependencies (e.g. Gimp, KDevelop).</p>
<p>I think that's not really a 'bug', but rather a performance problem - QGIS <strong>always</strong> crashes with<br />std::bad_alloc (or a different alloc error, based on where it fails to alloc, although <br />the setEditText() call mentioned above is the most common cause, and produces a matching log to <br />this bugreport) if it doesn't have that much free virtual memory. I also suspect it may vary between <br />machines (e.g. the 32bit system I tested on has 2 GiB of RAM, the 64bit one has 16 GiB).</p>
<p>It doesn't exactly match the behavior of this bug (<strong>randomly</strong> throws std::bad_alloc at startup regardless of memory size), which<br />I've reproduced only with 2.0.1 so far (still testing). It just produces the same log as above (and even that may not be the case<br />if it fails to alloc elsewhere)</p> QGIS Application - Bug report #9213: 'bad_alloc' error at QGIS starthttps://issues.qgis.org/issues/9213?journal_id=482412014-02-07T04:54:51ZGiovanni Manghigiovanni.manghi@gmail.com
<ul><li><strong>Priority</strong> changed from <i>Normal</i> to <i>High</i></li></ul> QGIS Application - Bug report #9213: 'bad_alloc' error at QGIS starthttps://issues.qgis.org/issues/9213?journal_id=482852014-02-07T17:05:31ZFerdinand Majerechkiithsacmp@gmail.com
<ul><li><strong>File</strong> <a href="/attachments/download/6752/std_bad_alloc_before_adjust_extent_to_size.txt">std_bad_alloc_before_adjust_extent_to_size.txt</a><a href="/attachments/6752/std_bad_alloc_before_adjust_extent_to_size.txt"><img alt="Magnifier" src="/images/magnifier.png" /></a> added</li></ul><p>I've now reproduced the random std::bad_alloc at startup bug. I think it's unrelated to the <br />std::bad_alloc on low RAM described in the 2 above updates.</p>
<p>It seems the std::bad_alloc is actually thrown before adjustExtentToSize() is called.<br />I added some prints to QgsApplication::notify() where the std::bad_alloc is caught, log is in the attached file.</p>
<p>The interesting part of the log (see the '//' comments)<br />The std::bad_alloc always seems to happen when QgsApplication::notify() is called with a QEvent::MouseMove event and a QWidget receiver. I'm not yet sure if it's always the same widget since I can't reproduce this bug in GDB.</p>
<pre>
src/core/qgsmessagelog.cpp: 45: (logMessage) 2014-02-08T00:46:44 [0] QGIS Ready!
src/app/qgisapp.cpp: 723: (QgisApp) Before processEvents
// BEFORE EXCEPTION CAUGHT (event 5 is QEvent::MouseMove)
src/core/qgsapplication.cpp: 232: (notify) notify QWidget, event 5
// AFTER EXCEPTION CAUGHT
src/core/qgsapplication.cpp: 270: (notify) Exception info: std::bad_alloc
receiver class: QWidget
event type: 5
src/gui/qgsmapcanvas.cpp: 1042: (paintEvent) QgsMapCanvas::paintEvent
src/gui/qgsmapcanvasmap.cpp: 46: (resize) resizing to 844x598
src/core/qgsmaprenderer.cpp: 193: (adjustExtentToSize) Map units per pixel (x,y) : 0, 0
src/core/qgsmaprenderer.cpp: 194: (adjustExtentToSize) Pixmap dimensions (x,y) : 844, 598
src/core/qgsmaprenderer.cpp: 195: (adjustExtentToSize) Extent dimensions (x,y) : 0, 0
src/core/qgsmaprenderer.cpp: 196: (adjustExtentToSize) Empty
src/core/qgsmaprenderer.cpp: 204: (adjustExtentToSize) Adjusted map units per pixel (x,y) : 0, 0
src/core/qgsmaprenderer.cpp: 206: (adjustExtentToSize) Recalced pixmap dimensions (x,y) : nan, nan
src/core/qgsscalecalculator.cpp: 131: (calculateGeographicDistance) Distance across map extent (m): 0
src/core/qgsscalecalculator.cpp: 88: (calculate) scale = 0 conversionFactor = 39.3701
src/core/qgsmaprenderer.cpp: 211: (adjustExtentToSize) Scale (assuming meters as map units) = 1:0
src/gui/qgsmapcanvas.cpp: 1098: (paintEvent) QgsMapCanvas::paintEvent exit
</pre> QGIS Application - Bug report #9213: 'bad_alloc' error at QGIS starthttps://issues.qgis.org/issues/9213?journal_id=483872014-02-09T15:15:34ZFerdinand Majerechkiithsacmp@gmail.com
<ul></ul><p>I found the source of the bug.</p>
<p>The QgisApp class defined in src/app/qgisapp.h and src/app/qgisapp.cpp has a data member unsigned int mMousePrecisionDecimalPlaces, which is not initialized to any value by QgisApp constructor.<br />This member is then used uninitialized in QgisApp::showMouseCoordinate() to specify precision for a QgsPoint::toString() call. Since mMousePrecisionDecimalPlaces is unsigned, any value it may have without initialization is valid as a precision specifier. If this value happens to be e.g. 2bln, it will create a 2bln character string, which takes 2GiB. The worst-case is a 4GiB allocation, which is why the bug can't be (easily) reproduced oh high-RAM machines.</p>
<p>Also, there is a mMousePrecisionAutomatic data member, which seems related, but is not used anywhere in QGIS.</p>
<p>Also, I noticed that there is quite a lot of data members not initialized by the constructor of QgisApp (and likely in the rest of QGIS?). This should be avoided if possible; even if a variable is expected to be set right after the constructor by e.g. a method call, not every user of the class may know that and it may result in more similar bugs. It's better to find a workable default and use that in the constructor, or to set an absurd value that is guaranteed to blow up if not set before use to detect bugs immediately (rather than an uninitialized value that <strong>may or may not</strong> crash resulting in heisenbugs like this)</p> QGIS Application - Bug report #9213: 'bad_alloc' error at QGIS starthttps://issues.qgis.org/issues/9213?journal_id=483882014-02-09T16:36:20ZFerdinand Majerechkiithsacmp@gmail.com
<ul></ul><p>Pull request with the fix:</p>
<p><a class="external" href="https://github.com/qgis/QGIS/pull/1157">https://github.com/qgis/QGIS/pull/1157</a></p> QGIS Application - Bug report #9213: 'bad_alloc' error at QGIS starthttps://issues.qgis.org/issues/9213?journal_id=483892014-02-09T18:59:14ZMartin Dobiaswonder.sk@gmail.com
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul><p>Fixed in changeset <a class="changeset" href="https://issues.qgis.org/projects/qgis/repository/revisions/ac9eed7e052428722cd66ce0e39aee933c8176e6" title="Merge pull request #1157 from kiith-sa/master Fix #9213 ('bad_alloc' error at QGIS start)">ac9eed7e052428722cd66ce0e39aee933c8176e6</a>.</p>