Author Topic: unknown exception  (Read 60064 times)

Offline 280Z28

  • Regular
  • ***
  • Posts: 397
  • *insert unicode here*
Re: unknown exception
« Reply #60 on: December 17, 2005, 02:59:22 am »
Oh yeah, you have to change wxChar* back to char* in wxCrc32::FromString()

That's all I had to do to 1536+your patch to make it build.
78 280Z, "a few bolt-ons" - 12.71@109.04
99 Trans Am, "Daily Driver" - 525rwhp/475rwtq
 Check out The Sam Zone :cool:

grv575

  • Guest
Re: unknown exception
« Reply #61 on: December 17, 2005, 03:06:25 am »
Perfect.  works.  build 1524 tested.  Do note that the generated default.conf file will crash prior versions now :)
But just make a note of it in the wiki - delete default.conf if you get an undefined exception.

grv575

  • Guest
Re: unknown exception
« Reply #62 on: December 17, 2005, 03:21:38 am »
One thing.  This gives a crc of 0:
Code
unsigned long wxCrc32::FromString(const wxString& text)
{
    static unsigned long *crc_table = NULL;
    unsigned long crc = 0;
    const char* p = text.mb_str(wxConvUTF8);

    if (text)
    {
        // Get the crc table, on first call, generate, otherwise do nothing
        crc_table = GetCRC32Table( crc_table ) ;

        // Do we have a crc table?
        if ( crc_table )
        {
            // Calculate the checksum
            crc = 0xFFFFFFFFUL;
            while (*p)
                { crc = (crc>>8) ^ crc_table[ (crc^(*p++)) & 0xFF ]; }

            crc ^= 0xFFFFFFFFUL ;
        }
    }

    // If we have a crc table, delete it from memory
    if ( crc_table ) { delete[] crc_table; }

    // Set it to a null pointer, the have it (re)created on next calls to this
    // function
    crc_table = NULL;

    // Return the checksum result
    return( crc ) ;
}

This computes the correct crc (verified same as 1512 binary):

Code
unsigned long wxCrc32::FromString(const wxString& text)
{
    static unsigned long *crc_table = NULL;
    unsigned long crc = 0;
    int i = 0;

    if (text)
    {
        // Get the crc table, on first call, generate, otherwise do nothing
        crc_table = GetCRC32Table( crc_table ) ;

        // Do we have a crc table?
        if ( crc_table )
        {
            // Calculate the checksum
            crc = 0xFFFFFFFFUL;
            while (text[i])
                { crc = (crc>>8) ^ crc_table[ (crc^(text[i++])) & 0xFF ]; }

            crc ^= 0xFFFFFFFFUL ;
        }
    }

    // If we have a crc table, delete it from memory
    if ( crc_table ) { delete[] crc_table; }

    // Set it to a null pointer, the have it (re)created on next calls to this
    // function
    crc_table = NULL;

    // Return the checksum result
    return( crc ) ;
}

Should the latter be used?  I think it's something about the conversion in unicode or ???
« Last Edit: December 17, 2005, 03:23:25 am by grv575 »

Offline 280Z28

  • Regular
  • ***
  • Posts: 397
  • *insert unicode here*
Re: unknown exception
« Reply #63 on: December 17, 2005, 03:34:12 am »
crc is a binary data check, I have no idea why it's taking variable length srings at all. It should take a void* and size_t and cast it to unsigned char   :?

Code
unsigned int wxCrc32::FromString(const wxString& text)
{
    const char* p = text.mb_str(wxConvUTF8);
    return FromBytes(p, strlen(p));
}

unsigned int wxCrc32::FromBytes(const void* data, size_t length)
{
    static unsigned int *crc_table = NULL;
    unsigned int crc = 0;
    const unsigned char* p = static_cast<const unsigned char*>(data);

    if (p)
    {
        // Get the crc table, on first call, generate, otherwise do nothing
        crc_table = GetCRC32Table( crc_table );

        // Do we have a crc table?
        if ( crc_table )
        {
            // Calculate the checksum
            crc = 0xFFFFFFFFUL;
            while (length--)
                { crc = (crc>>8) ^ crc_table[ (crc^(*p++)) & 0xFF ]; }

            crc ^= 0xFFFFFFFFUL ;
        }
    }

    // If we have a crc table, delete it from memory
    if ( crc_table ) { delete[] crc_table; }

    // Set it to a null pointer, the have it (re)created on next calls to this
    // function
    crc_table = NULL;

    // Return the checksum result
    return( crc ) ;
}
« Last Edit: December 17, 2005, 04:35:00 am by 280Z28 »
78 280Z, "a few bolt-ons" - 12.71@109.04
99 Trans Am, "Daily Driver" - 525rwhp/475rwtq
 Check out The Sam Zone :cool:

Offline 280Z28

  • Regular
  • ***
  • Posts: 397
  • *insert unicode here*
Re: unknown exception
« Reply #64 on: December 17, 2005, 04:31:58 am »
I set those back to #defines in appglobals.h, and made the change above to the crc check, and now it saves the CRC and looks like this. :)



[attachment deleted by admin]
« Last Edit: December 17, 2005, 04:35:22 am by 280Z28 »
78 280Z, "a few bolt-ons" - 12.71@109.04
99 Trans Am, "Daily Driver" - 525rwhp/475rwtq
 Check out The Sam Zone :cool:

grv575

  • Guest
Re: unknown exception
« Reply #65 on: December 17, 2005, 07:55:48 am »
I tested 280Z28's unicode.patch under a unicode build and it fixes the problem as well as uses an unsigned int for the crc as it should (the xml routines accept and int and overflow giving a negative crc if it gets an unsigned long - this was one of the problems it seems).

Building a clean ansi build to test on but it should work.  There may be another unicode bug re syntax highlighting but it looks like a seperate issue.  Have to look at a couple of different revisions (both ansi & unicode) to isolate it: basically open a .cpp, click settings->editor->OK.  do that twice in a row and the syntax highlighting dissapears - 280Z28 pointed it out and I haven't got a chance to look at it further but right now: 1512 ansi doesn't exhibit, 1537 unicode does (but this should be a seperate thread anyway).

Also, since people have said they couldn't get unicode to build for whatever reasons, here's all the relevant settings that should be checked (they assume a WX_SFX custom variable that should be blank for ansi and u for unicode, just to be appended to msw$(WX_SFX) to make switching back and forth easier (present in the unicode.patch)) :

Code
0 compile either an ansi (UNICODE=0) or unicode (UNICODE=1) build - at the cmd.exe prompt
type:

mingw32-make -f makefile.gcc USE_XRC=1 SHARED=1 MONOLITHIC=1 BUILD=release UNICODE=1 VENDOR=cb

(if you get an error then update to a later mingw (make >= 3.80 needed))

1 checkout svn source with tortoisesvn.
2 right click checked out directory and apply patch - apply unicode.patch - right-click on
file list -> patch all (this won't be necessary once the unknown exception bug fix is in svn)
3 open CodeBlocks-NewBuild.cbp with a recent codeblocks build (download one of the svn
binaries you can find links to in the forums)
4 goto project -> build options
5

ANSI
====
Compiler->#defines
   make sure wxUSE_UNICODE if present is:
   wxUSE_UNICODE=0
Custom variables
   WX_CFG=NonUnicode
   WX_SFX=
rename wxWidgets-2.6.2\lib\gcc_dll to wxWidgets-2.6.2\lib\gcc_dllNonUnicode
open wxWidgets-2.6.2\lib\gcc_dllNonUnicode\msw\wx\setup.h
   it should have
   #define wxUSE_UNICODE 0

UNICODE
=======
Compiler->#defines
   make sure wxUSE_UNICODE if present is:
   wxUSE_UNICODE=1
Custom variables
   WX_CFG=NonUnicode
   WX_SFX=u
rename wxWidgets-2.6.2\lib\gcc_dll to wxWidgets-2.6.2\lib\gcc_dllUnicode
open wxWidgets-2.6.2\lib\gcc_dllUnicode\msw\wx\setup.h
   it should have
   #define wxUSE_UNICODE 1

6 save the project and exit CodeBlocks.  This is necessary so the custom variables get set
and reloaded.
7 hit compile and if it prompts you to set the wx variable, just browse to the
wxWidgets-2.6.2 directory and hit ok
8 let it compile and run update.bat once it finishes

Those should be the only settings that affect ansi vs. unicode building.

Update:  OK tested and the patch works on ansi as well.  Looked over all the diffs and everything looks clean.  It's a merge of thomas' main.patch.txt and changes made by 280Z28.  I'll post the link to the file for now:

280Z28: if you have a more recent version or whatever I'll take the link down, but wanted to have something people could look over now as it tests and looks fine for clean checkouts of both unicode and ansi builds.

http://www.geocities.com/grv575/unicode.zip

Finally, the syntax highlighting thing looks like a unicode only thing - doesn't show up in ansi builds but does in unicode (both with and without the unicode.zip patch so it's a seperate issue).  A third seperate <snip...lies about some nonexistant behavior deleted>
« Last Edit: December 17, 2005, 08:24:42 am by grv575 »

Offline 280Z28

  • Regular
  • ***
  • Posts: 397
  • *insert unicode here*
Re: unknown exception
« Reply #66 on: December 17, 2005, 08:12:42 am »
78 280Z, "a few bolt-ons" - 12.71@109.04
99 Trans Am, "Daily Driver" - 525rwhp/475rwtq
 Check out The Sam Zone :cool:

grv575

  • Guest
Re: unknown exception
« Reply #67 on: December 17, 2005, 08:16:41 am »
Oh, you are around.  Do you mind if I post the unicode patch?  It looks good (see modified post above)

Offline 280Z28

  • Regular
  • ***
  • Posts: 397
  • *insert unicode here*
Re: unknown exception
« Reply #68 on: December 17, 2005, 08:18:20 am »
Oh, you are around.  Do you mind if I post the unicode patch?  It looks good (see modified post above)

Sure, but I didn't post it because people were complaining about the preprocessor directives. I tryed 3 different ways of using wxString but in the end I went with something that's time-proven reliable.

You don't have to rehost it btw, I own the server it's on. ;)

I have other stuff done, but you can find it in the top 8 latest patches on SF (I was a nobody from work :cry: ).
« Last Edit: December 17, 2005, 08:20:03 am by 280Z28 »
78 280Z, "a few bolt-ons" - 12.71@109.04
99 Trans Am, "Daily Driver" - 525rwhp/475rwtq
 Check out The Sam Zone :cool:

grv575

  • Guest
Re: unknown exception
« Reply #69 on: December 17, 2005, 08:21:23 am »
OK, not aware of that discussion, but I figure that those changes can just be ignored if not desired.  At least the patch for this crash is ready to be integrated into the tree once devs have verified.

Offline 280Z28

  • Regular
  • ***
  • Posts: 397
  • *insert unicode here*
Re: unknown exception
« Reply #70 on: December 17, 2005, 08:23:06 am »
OK, not aware of that discussion, but I figure that those changes can just be ignored if not desired.  At least the patch for this crash is ready to be integrated into the tree once devs have verified.

I say go back to the directives. Variables didn't work once, there's a patch ready that does work with directives, why spend any more time on it? :)

You want to be the one to put it on SF? haha  :lol:

Edit: For what I was talking about, see replies 57, 58 in this thread.
78 280Z, "a few bolt-ons" - 12.71@109.04
99 Trans Am, "Daily Driver" - 525rwhp/475rwtq
 Check out The Sam Zone :cool:

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: unknown exception
« Reply #71 on: December 17, 2005, 02:44:42 pm »
I have committed my patch to main.cpp along with grv575's modification to crc32.cpp.

I don't like mangling FromString() through FromBytes(), as it introduces unnecessary indirection and works on char pointers instead of using safe string ops.
Replacing long by int in the crc table does not make anything better. These are logically different types, but exactly the same on all modern architectures. And on older architectures, int would acutally break that particular code.
It means rewriting the whole function and the functions calling it with no noticeable difference (identical executable).
Besides, it is tinyXML which uses signed variables and introduces the minus sign in the xml, consequentially. There is nothing we can do about that short of either rewriting tinyXML or converting the CRC to a string. Neither solution is required or advisable, though.

The changes regarding reverting appglobals.h to using macros are also not committed because that makes no sense at all. Yiannis changed the #defines to const wxStrings to get rid of some macros.
If there is a problem in some code using the constants (about box, for example), then that code should be adjusted.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline 280Z28

  • Regular
  • ***
  • Posts: 397
  • *insert unicode here*
Re: unknown exception
« Reply #72 on: December 17, 2005, 02:49:28 pm »
I have committed my patch to main.cpp along with grv575's modification to crc32.cpp.

I don't like mangling FromString() through FromBytes(), as it introduces unnecessary indirection and works on char pointers instead of using safe string ops.
Replacing long by int in the crc table does not make anything better. These are logically different types, but exactly the same on all modern architectures. And on older architectures, int would acutally break that particular code.
It means rewriting the whole function and the functions calling it with no noticeable difference (identical executable).
Besides, it is tinyXML which uses signed variables and introduces the minus sign in the xml, consequentially. There is nothing we can do about that short of either rewriting tinyXML or converting the CRC to a string. Neither solution is required or advisable, though.

The changes regarding reverting appglobals.h to using macros are also not committed because that makes no sense at all. Yiannis changed the #defines to const wxStrings to get rid of some macros.
If there is a problem in some code using the constants (about box, for example), then that code should be adjusted.

Long and int are different on 64bit platforms, and as such broke one of our math libraries. :( If you know it's a 32bit answer you want, you need to use int. long is 64bits on 64bit platforms.
78 280Z, "a few bolt-ons" - 12.71@109.04
99 Trans Am, "Daily Driver" - 525rwhp/475rwtq
 Check out The Sam Zone :cool:

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: unknown exception
« Reply #73 on: December 17, 2005, 02:53:14 pm »
My two Athlon64 PCs and my Turion64 notebook don't seem to know that.

Anyway, that can be adressed at a later time separately.
« Last Edit: December 17, 2005, 02:55:09 pm by thomas »
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline Urxae

  • Regular
  • ***
  • Posts: 376
Re: unknown exception
« Reply #74 on: December 17, 2005, 02:58:38 pm »
Besides, it is tinyXML which uses signed variables and introduces the minus sign in the xml, consequentially. There is nothing we can do about that short of either rewriting tinyXML or converting the CRC to a string. Neither solution is required or advisable, though.

Why not convert it to a string? There shouldn't be a performance disadvantage as tinyXML would otherwise do that anyway, right? So what's the problem with moving that conversion to C::B itself where you know the CRC is unsigned and will handle it properly?