render-with-notepad icon indicating copy to clipboard operation
render-with-notepad copied to clipboard

Toggling word wrap (which isn't on by default) crashes process

Open lloydtao opened this issue 4 years ago • 5 comments

Hey, fresh clone and build, and the cube is looking short and wide. Characters are changing about as expected, but it's distorted.

image

Just running RayTracer.exe C:/Windows/System32/notepad.exe off of command line.

lloydtao avatar May 21 '20 18:05 lloydtao

Squashed it. Word wrap needs to be toggled before launching, but toggling it after start makes it crash.

Will re-word issue.

lloydtao avatar May 21 '20 19:05 lloydtao

ah, word wrap was on by default on my system. Try that! :P

What might be happening is that toggling word wrap is somehow changing the address of the on screen before (maybe destroying / reallocating? or something else a little more clever), and if you try to write process memory to the old text buffer pointer after toggling word wrap, you try to write to a now-invalid address.

I'm happy to accept a pull request that has the code enabling word wrap before writing text!

khalladay avatar May 22 '20 18:05 khalladay

Sounds like you have a better idea than I over the crash.

As for setting the word wrap, it's a setting in the registry, and seems very safe to edit.

image

I'll work on the PR shortly.

lloydtao avatar May 25 '20 01:05 lloydtao

Happy to take a look at a PR, although I do wonder if this could be done without touching the registry. From stackoverflow, it looks like win32 edit controls don't support toggling word wrap (notepad just destroys the existing edit control and creates a new one).

If it's possible to query the status of word wrap in the existing edit control, we can probably just send the right message to the Notepad menu bar to toggle word wrap if we need to, before acquiring the address of the text buffer (since if we do things in the opposite order, we'll get the crash you reported).

Two things need to be sorted out for that:

  • Querying whether the existing edit control has word wrap enabled
  • Sending the right message (or messages) to the menu bar to make it toggle on word wrap

khalladay avatar Jun 08 '20 22:06 khalladay

I unfortunately wouldn't know where to start with that. Out of my expertise! 😛

I do back up the fact that there's no control for it (https://stackoverflow.com/questions/83045/command-switch-to-toggle-notepads-word-wrap), and I support the fact that this is much healthier than editing the registry.

lloydtao avatar Jun 10 '20 22:06 lloydtao