[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Development
. . -> [Subject]  Problem with text view

Problem with text view

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Pages: 1 2  3  4  5  6  

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Sun 26 Sep 2010 06:27 AM (UTC)
Message
OK I'm stumped on this one. This used to work, except for the occasional report of text views crashing under Wine.

Now, under a debug build, if I load a file in the internal notepad, I get this:



However in the release build it looks OK. Worstje put this comment into the source:


* Originally there is an '#IFDEF _UNICODE' statement around these pragmas, but we don't compile as _UNICODE.
* Research shows this #IFDEF seems to exist by default due to a bug in CEditView in MBCS mode, but I do not
* believe this bug can affect us at present as it involves 'loading from files'. Testing thus far seems to
* confirm there is no different behaviour in/around the command window with this enabled. -JW


This seems to be pretty close to the problem area - a bug in CEditView, and possibly involving MBCS mode. Do you have any more details or suggestions?

I tried to work around it by reading directly into the edit control (which worked) and then saving from the edit control, which also worked. But doing it that way the Find dialog fails to find anything. I believe it is using a shadow buffer (for unknown reasons) and the find is searching the shadow buffer, not the edit control.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Sun 26 Sep 2010 06:40 AM (UTC)
Message
I'm not particularly happy with some builds randomly working - it suggests it is good luck rather than good management. For example, a bit of memory that happens to be zero this time.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Sun 26 Sep 2010 06:44 AM (UTC)
Message
And I should add that when reading the file with the debugger, the data is actually correct when read in. However setting the handle in the shadow buffer seems to somehow fail. Perhaps it thinks it is Unicode. I don't know for sure.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #3 on Sun 26 Sep 2010 09:54 AM (UTC)
Message
That's odd. Building from your branch under Debug mode and opening my script file in the internal notepad shows nothing strange. Maybe it has to do with the theming that Worstje enabled? Our development environments are obviously pretty different, and I know there are some things Worstje did to keep VC6 viable with the changes.

Try using `git bisect` to determine which precise commit did it?

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Sun 26 Sep 2010 10:21 AM (UTC)
Message
It happened before the theming stuff, and in any case that doesn't affect the text windows.

I tried reverting back to the previous version and then bisecting my way back to the current one, and it all worked. After all it works now in the release build.

I tried deleting all the temporary VS files and rebuilding and that seemed to work for a while.

I think there is something more subtle going on.

I'm interested to know more about "a bug in CEditView". CTextView, which exhibits the behaviour, is derived from CEditView.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #5 on Sun 26 Sep 2010 10:27 AM (UTC)
Message
This, perhaps?

http://blogs.msdn.com/b/michkap/archive/2004/11/13/257048.aspx

It says it was fixed in MFC 7; VS2005 has MFC 8, and VS2010 has MFC 10. I don't know what's up with the Release build working, though.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Worstje   Netherlands  (899 posts)  [Biography] bio
Date Reply #6 on Sun 26 Sep 2010 02:07 PM (UTC)

Amended on Sun 26 Sep 2010 03:12 PM (UTC) by Worstje

Message
I see lots of stuff happened while I was asleep.

I had failed to catch that CTextView is derived of CEditView, even though I tried loading addxml.lua just now - no glitches or bugs that I can see. Regarding the bugs, I couldn't find any good sources on the issue when I was searching, hence my vague comment - although I am really glad Twisol found a more indepth explanation of the issue.

It is just a guess, but I think if you (conditionally for MSVC++6) redefine the appropriate methods in CTextView, it should be possible to work around the issue. That'd make the fix somewhat similar to the KB issues suggested fix earlier in this topic over a year ago for the glitches with world tabs displayed.

Something else to look at: http://groups.google.co.uk/group/microsoft.public.dotnet.languages.vc/browse_thread/thread/f6fc1b21d8d6338c/cc4e5227ddd1f7a9?lnk=st&q=ceditview+manifest+partch&rnum=4&hl=en#cc4e5227ddd1f7a9

The reason the release build has this fixed is because you are dynamically linking against the MFC libraries (or so I deduce). Those likely have had this particular bug fixed. The MFC debug libraries however seem not to have had it fixed. If you check the version numbers of the relevant DLLs, I bet you can find out a thing or two to confirm this theory.

And I found yet something else... I figure http://www.codeproject.com/KB/files/textfiledocument.aspx might be a replacement for CTextView if this problem is unsolvable?

Btw, Nick, if you could upload some builds showing the behaviour you describe (a debug that garbles text, a release that works fine), I can check it here to see if it isn't per chance some weird stuff going on on your PC.
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Sun 26 Sep 2010 09:49 PM (UTC)
Message
Well I almost bit the bullet and downloaded VS2010 but when I saw the price:


Visual Studio 2010 Professional
Developer tool
Buy Download
AU$1,387.00


I can't quite make my fingers enter my credit card details for $1387 for a compiler, when g++ (arguably better) is free, and it is to support a program that I am giving away.

So I better try to solve the problem another way.

BTW if this was g++ (which you get free downloads for) then I agree it would be crazy to be using a 10-year old compiler.

Even Apple, you know, give away their development environment (which includes g++) but also has a very snazzy graphical IDE.

I just can't quite stop resenting the fact that Microsoft is trying to make money - a lot of it - from the people who will develop software to help sell their operating system.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #8 on Sun 26 Sep 2010 09:56 PM (UTC)
Message
Twisol said:

This, perhaps?

http://blogs.msdn.com/b/michkap/archive/2004/11/13/257048.aspx

It says it was fixed in MFC 7; VS2005 has MFC 8, and VS2010 has MFC 10. I don't know what's up with the Release build working, though.


I spotted that page, thanks.

Let me show what they are talking about:


void CEditView::ReadFromArchive(CArchive& ar, UINT nLen)
  // Read certain amount of text from the file, assume at least nLen
  // characters (not bytes) are in the file.
{
  ASSERT_VALID(this);

  LPVOID hText = LocalAlloc(LMEM_MOVEABLE, (nLen+1)*sizeof(TCHAR));
  if (hText == NULL)
    AfxThrowMemoryException();

  LPTSTR lpszText = (LPTSTR)LocalLock(hText);
  ASSERT(lpszText != NULL);
  if (ar.Read(lpszText, nLen*sizeof(TCHAR)) != nLen*sizeof(TCHAR))
  {
    LocalUnlock(hText);
    LocalFree(hText);
    AfxThrowArchiveException(CArchiveException::endOfFile);
  }
  // Replace the editing edit buffer with the newly loaded data
  lpszText[nLen] = '\0';
#ifndef _UNICODE
  if (afxData.bWin95)
  {
    // set the text with SetWindowText, then free
    BOOL bResult = ::SetWindowText(m_hWnd, lpszText);
    LocalUnlock(hText);
    LocalFree(hText);

    // make sure that SetWindowText was successful
    if (!bResult || ::GetWindowTextLength(m_hWnd) < (int)nLen)
      AfxThrowMemoryException();

    // remove old shadow buffer
    delete[] m_pShadowBuffer;
    m_pShadowBuffer = NULL;
    m_nShadowSize = 0;

    ASSERT_VALID(this);
    return;
  }
#endif
  LocalUnlock(hText);
  HLOCAL hOldText = GetEditCtrl().GetHandle();
  ASSERT(hOldText != NULL);
  LocalFree(hOldText);
  GetEditCtrl().SetHandle((HLOCAL)(UINT)(DWORD)hText);
  Invalidate();
  ASSERT_VALID(this);
}


The #ifndef _UNICODE only affects code that applies if you are Windows 95, right? Which I'm not, I am testing on XP.

However hoping that was the issue I had in fact forced it to think it *was* Windows 95, see here:

http://github.com/nickgammon/mushclient/commit/24e3b5253cd5c

Effectively I copied and pasted, removing the test for Windows 95 (otherwise not much point). And that worked, the window was not garbage.

Then I found it didn't save, because it was saving from the shadow buffer, not directly from the Edit control. So I changed the way it was written:

http://github.com/nickgammon/mushclient/commit/5e97cdfde237

So far so good. But then I found that the searches found nothing because it was *searching* the shadow buffer. So I thought "this is crazy" and it worked before anyway.

Surely there must be a fix?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #9 on Sun 26 Sep 2010 09:59 PM (UTC)
Message
Worstje said:

The reason the release build has this fixed is because you are dynamically linking against the MFC libraries (or so I deduce). Those likely have had this particular bug fixed.


No, I'm not. Good suggestion. But I in fact statically link against both to get consistent behaviour.

In any case, why would the library be fixed? I haven't downloaded fixes. That is, not recently. I got the latest Visual Studio 6 service pack a while back, but as you can understand, they don't update that every week.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Worstje   Netherlands  (899 posts)  [Biography] bio
Date Reply #10 on Sun 26 Sep 2010 10:02 PM (UTC)

Amended on Sun 26 Sep 2010 10:05 PM (UTC) by Worstje

Message
Edit: Seems I got ninja'd a couple of times while writing this. Will post in a bit on the stuff I missed. :)

I fully understand your reluctance to buy a newer version, and I am even tempted to agree with it.

But a part of me also feels like one needs to be realistic. You bought VC++6 like... 10+ years ago. That's a huge amount of time that has gone by. It is a professional tool meant to help you make money. While I don't know how much you have made using MUSHclient, nor what you do currently, I bet VC++ has been among the backbone of your work as a software developer.

Whatever work you have done during those 10 years, part of it should have been a fiscal write-off for your investment into the tools, and to allow you to buy new tools as your time/field requires it.

Now I don't say 'buy VS2010 for MUSHclient'. That would be stupid. Stick to VC6++ for that if it is the extent of your activities. But I am saying that if you are still a professional (fulltime) software developer, switching to a modern tool is completely expected. VC6++ is not supported anymore, so delivering work for a modern OS would be unprofessional.
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #11 on Sun 26 Sep 2010 10:08 PM (UTC)
Message
Nick Gammon said:
Well I almost bit the bullet and downloaded VS2010 but when I saw the price:


Visual Studio 2010 Professional
Developer tool
Buy Download
AU$1,387.00

...Ouch. There's a $549 package (US$) with the MSDN Essentials subscription instead, but it's unclear whether it's just the MSDN subscription that expires, or whether you have to renew the whole darn IDE.

Nick Gammon said:
I can't quite make my fingers enter my credit card details for $1387 for a compiler, when g++ (arguably better) is free, and it is to support a program that I am giving away.

I'm not advocating Microsoft here, but MSVC is a lot more than just a compiler. (Ugh, but I'm still trying to find a version with no MSDN subscription...)

Nick Gammon said:
I just can't quite stop resenting the fact that Microsoft is trying to make money - a lot of it - from the people who will develop software to help sell their operating system.

If you join a local community college for a semester, maybe you can get in on Microsoft's DreamSpark program. XD

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #12 on Sun 26 Sep 2010 10:15 PM (UTC)
Message
It looks like this one doesn't come with the MSDN subscription... ($723)

http://www.amazon.com/Microsoft-C5E-00521-Visual-Studio-Professional/dp/B0038KTO8S/ref=amb_link_6338112_1?pf_rd_m=ATVPDKIKX0DER&pf_rd_s=browse&pf_rd_r=1TVY30VP67FSX5JCZB1A&pf_rd_t=101&pf_rd_p=1268136242&pf_rd_i=404443011

The one at CDW is about the same price, but maybe $20 USD more. ($745)

http://www.cdw.com/shop/products/default.aspx?EDC=2079228

I assume it's pricier than the one-year subscription product because they don't have their hook in you.

(I'm not trying to get you to buy it, I'm just pointing out better deals than what you posted. Of course, if you did get it, then I could get the $200 upgrade and we'd all be on even ground, which would be astonishing. :O)

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Worstje   Netherlands  (899 posts)  [Biography] bio
Date Reply #13 on Sun 26 Sep 2010 10:23 PM (UTC)
Message
Nick, I dug into the sourcecode for the CEditView as VS2010s MFC has it, and I've put the parts I thought relevant up on Pastebin so you can try to figure out how to do a good fix.

I'd do more but I'm totally unsure on how to properly fix it without having the version of the framework that has the booboo in the first place.

http://pastebin.com/yDyeV1D1
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #14 on Sun 26 Sep 2010 10:23 PM (UTC)
Message
Well is it just much more expensive from the horse's mouth?


Visual Studio 2010 Professional with MSDN
Developer tool
Buy activation key
AU$2,084.00


As you can see, *with* MSDN we cracked the $2K barrier.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


187,136 views.

This is page 1, subject is 6 pages long: 1 2  3  4  5  6  [Next page]

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]