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

Spyder crashes when replacing text #14176

Closed
LucaAmerio opened this issue Nov 9, 2020 · 7 comments
Closed

Spyder crashes when replacing text #14176

LucaAmerio opened this issue Nov 9, 2020 · 7 comments
Labels
Milestone

Comments

@LucaAmerio
Copy link

LucaAmerio commented Nov 9, 2020

Problem Description

I have the (poorly written) python script below. I want to replace all instances of "particles" with "self.particles". To do so, I do [Search] > [Replace text] and try to replace "particles" with "self.particles". Spyder crashes immediately. I was having the issue with Spyder 4.1.2 inside Anaconda. I installed Spyder 4.2.0 using the stand-alone installer, but the error still exists.

What steps reproduce the problem?

  1. Copy the EXACT following code into an editor window without saving
import rhinoscriptsyntax as rs
import random

particles = []
speedmax = 10
cycles = 20
sepval =5
alignval = 0.02 
chval = 0.02

class Particles:
    
    
    
    def __init__(self):
        
        pass

    def run(self):
        
        pass


    def flock(self):
              
        self.separate(sepval)
        self.cohesion(chval)
        self.align(alignval)

    def separate(self, magnitude):
        count = 0
        steer = [0.001,0.001,0.001]
        
        for i in range(0, len(particles)):
             dist = rs.Distance(self.coord,particles[i].coord)
             if dist>0 and dist <30 :
                 diff = rs.VectorSubtract(self.coord,particles[i].coord)
                 diff = rs.VectorUnitize(diff)
                 diff = rs.VectorScale(diff,1/dist)
                 steer = rs.VectorAdd(steer,diff)
                 count = count + 1
        if count > 0:
            steer = rs.VectorScale(steer,1/count)
        
        steer = rs.VectorScale(steer,magnitude)
        self.acc = rs.VectorAdd(self.acc,steer)


for i in range(nopoints):
    particles.append(Particles())

for i in range(cycles):
    for particle in particles:
        #particle.drawPosition()
        particle.run()

#for particle in particles:
#    rs.AddCurve(particle.path)
  1. Click "CTRL+R" and replace "particles" with "self.particles"
  2. Click "ALL"

Note: I tried several times to reduce the code to nail down the error. The extremely weird thing is that it's enough to replace one method's content with pass or deleting one of the rows at the beginning of the file containing those variables to prevent the error to occur.

However, with this EXACT content, I can reproduce the error systematically.

Versions

  • Spyder version: 4.2.0
  • Python version: 3.7.9 64-bit
  • Qt version: 5.12.9
  • PyQt version: 5.12.3
  • Operating System name/version: Windows 10

Dependencies


# Mandatory:
atomicwrites >=1.2.0            :  1.4.0 (OK)
chardet >=2.0.0                 :  3.0.4 (OK)
cloudpickle >=0.5.0             :  1.6.0 (OK)
diff_match_patch >=20181111     :  20200713 (OK)
intervaltree                    :  None (OK)
IPython >=4.0                   :  7.19.0 (OK)
jedi =0.17.2                    :  0.17.2 (OK)
jsonschema >=3.2.0              :  3.2.0 (OK)
nbconvert >=4.0                 :  6.0.7 (OK)
numpydoc >=0.6.0                :  1.1.0 (OK)
paramiko >=2.4.0                :  2.7.2 (OK)
parso =0.7.0                    :  0.7.0 (OK)
pexpect >=4.4.0                 :  4.8.0 (OK)
pickleshare >=0.4               :  0.7.5 (OK)
psutil >=5.3                    :  5.7.3 (OK)
pygments >=2.0                  :  2.7.2 (OK)
pylint >=1.0                    :  2.6.0 (OK)
pyls >=0.36.1;<1.0.0            :  0.36.1 (OK)
pyls_black >=0.4.6              :  0.4.6 (OK)
pyls_spyder >=0.1.1             :  0.1.1 (OK)
qdarkstyle >=2.8                :  2.8.1 (OK)
qtawesome >=0.5.7               :  1.0.1 (OK)
qtconsole >=4.7.7               :  4.7.7 (OK)
qtpy >=1.5.0                    :  1.9.0 (OK)
setuptools >=39.0.0             :  50.3.2 (OK)
sphinx >=0.6.6                  :  3.3.0 (OK)
spyder_kernels >=1.10.0;<1.11.0 :  1.10.0 (OK)
three_merge >=0.1.1             :  0.1.1 (OK)
watchdog                        :  None (OK)
zmq >=17                        :  19.0.2 (OK)

# Optional:
cython >=0.21                   :  0.29.21 (OK)
matplotlib >=2.0.0              :  3.3.2 (OK)
numpy >=1.7                     :  1.19.4 (OK)
pandas >=1.1.1                  :  1.1.4 (OK)
scipy >=0.17.0                  :  1.5.4 (OK)
sympy >=0.7.3                   :  1.6.2 (OK)

@steff456
Copy link
Member

steff456 commented Nov 9, 2020

Hi @pj1989,

I could reproduce this error, we will work in this for our next release.

Thanks for reporting!

@steff456 steff456 self-assigned this Nov 10, 2020
@ccordoba12 ccordoba12 added this to the v4.2.1 milestone Nov 10, 2020
@OverLordGoldDragon
Copy link
Contributor

I'll also note that Spyder's replace seems much slower than Notepad++'s (noticeable delay even on small text).

@ccordoba12
Copy link
Member

@OverLordGoldDragon, I think that problem was caused because we were highlighting all occurrences in the document. But that was fixed in 4.2.0

@OverLordGoldDragon
Copy link
Contributor

@ccordoba12 Spyder didn't yell for not upgrading; maybe it's to do with not being on -c anaconda (which is also where I looked). Upgraded - the delay's still there, and it's in "replace in selection"; it's small, but clearly noticeable unlike in Npp (also seems to get slower with selection size or match count).

@ccordoba12 ccordoba12 modified the milestones: v4.2.1, v4.2.2 Dec 14, 2020
@ccordoba12 ccordoba12 modified the milestones: v4.2.2, 4.x (missing) Feb 1, 2021
@LucaAmerio
Copy link
Author

Just to update, this error is still present in 5.2.2

@ccordoba12 ccordoba12 modified the milestones: 4.x, v5.3.1 Feb 22, 2022
@ccordoba12 ccordoba12 modified the milestones: v5.3.1, v5.3.2 Apr 9, 2022
@ccordoba12 ccordoba12 modified the milestones: v5.3.2, v5.3.3 May 4, 2022
@ccordoba12 ccordoba12 modified the milestones: v5.3.3, v5.3.4 Jun 20, 2022
@rear1019
Copy link
Contributor

We have looked into this issue and think that it’s an issue in Qt:

  • We weren’t able to find obvious issues in Spyder’s code.
  • The crash is reproducible with PySide2 and PyQt (most recent versions as of last month). The backtrace is the same regardless of the used bindings (ignoring bindings-specific portions)
  • Crash is due to a NULL pointer access in Qt. In fact this assert in Qt code is violated.

A possible fix is the inclusion of pull request #16988, at the very least the changes affecting spyder/widgets/findreplace.py.

Note: The reproduction steps provided @LucaAmerio work only if the text does not fit in the screen, i.e. scrollbars must be visible. The error occurs when a wrap-around¹ of the search is performed. With a sufficiently small font (no scrollbars) the error does not occur.

¹ Wrap-around of search: Editor scrolls the content to jump from the end of the file to the start of the file.

@ccordoba12
Copy link
Member

@rear1019, thanks for your thorough investigation of this bug! We'll try to merge PR #16988 in our next version (5.3.3) to fix it.

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

No branches or pull requests

5 participants