Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
magicseteditor
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
magicseteditor
Commits
043f92db
Commit
043f92db
authored
Oct 02, 2010
by
twanvl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix error in vc9: use _wassert instead of _assert, the latter no longer exists.
parent
97492e8d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
187 additions
and
187 deletions
+187
-187
src/util/error.cpp
src/util/error.cpp
+187
-187
No files found.
src/util/error.cpp
View file @
043f92db
//+----------------------------------------------------------------------------+
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2010 Twan van Laarhoven and Sean Hunt |
//| Copyright: (C) 2001 - 2010 Twan van Laarhoven and Sean Hunt |
//| License: GNU General Public License 2 or later (see file COPYING) |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
//+----------------------------------------------------------------------------+
// ----------------------------------------------------------------------------- : Includes
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <util/prec.hpp>
#include <util/error.hpp>
#include <util/error.hpp>
#include <cli/text_io_handler.hpp>
#include <cli/text_io_handler.hpp>
#include <cli/text_io_handler.hpp>
#include <cli/text_io_handler.hpp>
#if wxUSE_STACKWALKER
#if wxUSE_STACKWALKER
#include <wx/stackwalk.h>
#include <wx/stackwalk.h>
#endif
#endif
DECLARE_TYPEOF_COLLECTION
(
ScriptParseError
);
DECLARE_TYPEOF_COLLECTION
(
ScriptParseError
);
// ----------------------------------------------------------------------------- : Debug utilities
// ----------------------------------------------------------------------------- : Debug utilities
#if defined(_MSC_VER) && defined(_DEBUG)
#if defined(_MSC_VER) && defined(_DEBUG)
void
msvc_assert
(
const
char
*
msg
,
const
char
*
expr
,
const
char
*
file
,
unsigned
line
)
{
void
msvc_assert
(
const
wchar_t
*
msg
,
const
wchar_t
*
expr
,
const
wchar_t
*
file
,
unsigned
line
)
{
if
(
IsDebuggerPresent
())
{
if
(
IsDebuggerPresent
())
{
char
buffer
[
1024
];
wchar_t
buffer
[
1024
];
if
(
msg
)
{
if
(
msg
)
{
sprintf
(
buffer
,
"Assertion failed: %s: %s, file %s, line %d
\n
"
,
msg
,
expr
,
file
,
line
);
wsprintf
(
buffer
,
L"Assertion failed: %s: %s, file %s, line %d
\n
"
,
msg
,
expr
,
file
,
line
);
}
else
{
}
else
{
sprintf
(
buffer
,
"Assertion failed: %s, file %s, line %d
\n
"
,
expr
,
file
,
line
);
wsprintf
(
buffer
,
L"Assertion failed: %s, file %s, line %d
\n
"
,
expr
,
file
,
line
);
}
}
OutputDebugString
A
(
buffer
);
OutputDebugString
W
(
buffer
);
DebugBreak
();
DebugBreak
();
}
else
{
}
else
{
_
assert
(
expr
,
file
,
line
);
_
wassert
(
expr
,
file
,
line
);
}
}
}
}
#endif
#endif
// ----------------------------------------------------------------------------- : Error types
// ----------------------------------------------------------------------------- : Error types
Error
::
Error
(
const
String
&
message
)
Error
::
Error
(
const
String
&
message
)
:
message
(
message
)
:
message
(
message
)
{}
{}
Error
::~
Error
()
{}
Error
::~
Error
()
{}
String
Error
::
what
()
const
{
String
Error
::
what
()
const
{
return
message
;
return
message
;
}
}
// Stolen from wx/appbase.cpp
// Stolen from wx/appbase.cpp
// we can't just call it, because of static linkage
// we can't just call it, because of static linkage
...
@@ -107,145 +107,145 @@ String get_stack_trace() {
...
@@ -107,145 +107,145 @@ String get_stack_trace() {
String
get_stack_trace
()
{
String
get_stack_trace
()
{
return
_
(
""
);
// not supported
return
_
(
""
);
// not supported
}
}
#endif // wxUSE_STACKWALKER
#endif // wxUSE_STACKWALKER
InternalError
::
InternalError
(
const
String
&
str
)
InternalError
::
InternalError
(
const
String
&
str
)
:
Error
(
:
Error
(
_
(
"An internal error occured:
\n\n
"
)
+
_
(
"An internal error occured:
\n\n
"
)
+
str
+
_
(
"
\n
"
)
str
+
_
(
"
\n
"
)
_
(
"Please save your work (use 'save as' to so you don't overwrite things)
\n
"
)
_
(
"Please save your work (use 'save as' to so you don't overwrite things)
\n
"
)
_
(
"and restart Magic Set Editor.
\n\n
"
)
_
(
"and restart Magic Set Editor.
\n\n
"
)
_
(
"You should leave a bug report on http://magicseteditor.sourceforge.net/
\n
"
)
_
(
"You should leave a bug report on http://magicseteditor.sourceforge.net/
\n
"
)
_
(
"Press Ctrl+C to copy this message to the clipboard."
)
_
(
"Press Ctrl+C to copy this message to the clipboard."
)
)
)
{
{
// add a stacktrace
// add a stacktrace
const
String
stack_trace
=
get_stack_trace
();
const
String
stack_trace
=
get_stack_trace
();
if
(
!
stack_trace
.
empty
())
{
if
(
!
stack_trace
.
empty
())
{
message
<<
_
(
"
\n\n
Call stack:
\n
"
)
<<
stack_trace
;
message
<<
_
(
"
\n\n
Call stack:
\n
"
)
<<
stack_trace
;
}
}
}
}
// ----------------------------------------------------------------------------- : Parse errors
// ----------------------------------------------------------------------------- : Parse errors
ScriptParseError
::
ScriptParseError
(
size_t
pos
,
int
line
,
const
String
&
filename
,
const
String
&
error
)
ScriptParseError
::
ScriptParseError
(
size_t
pos
,
int
line
,
const
String
&
filename
,
const
String
&
error
)
:
ParseError
(
error
)
:
ParseError
(
error
)
,
start
(
pos
),
end
(
pos
),
line
(
line
),
filename
(
filename
)
,
start
(
pos
),
end
(
pos
),
line
(
line
),
filename
(
filename
)
{}
{}
ScriptParseError
::
ScriptParseError
(
size_t
pos
,
int
line
,
const
String
&
filename
,
const
String
&
exp
,
const
String
&
found
)
ScriptParseError
::
ScriptParseError
(
size_t
pos
,
int
line
,
const
String
&
filename
,
const
String
&
exp
,
const
String
&
found
)
:
ParseError
(
_
(
"Expected '"
)
+
exp
+
_
(
"' instead of '"
)
+
found
+
_
(
"'"
))
:
ParseError
(
_
(
"Expected '"
)
+
exp
+
_
(
"' instead of '"
)
+
found
+
_
(
"'"
))
,
start
(
pos
),
end
(
pos
+
found
.
size
()),
line
(
line
),
filename
(
filename
)
,
start
(
pos
),
end
(
pos
+
found
.
size
()),
line
(
line
),
filename
(
filename
)
{}
{}
ScriptParseError
::
ScriptParseError
(
size_t
pos1
,
size_t
pos2
,
int
line
,
const
String
&
filename
,
const
String
&
open
,
const
String
&
close
,
const
String
&
found
)
ScriptParseError
::
ScriptParseError
(
size_t
pos1
,
size_t
pos2
,
int
line
,
const
String
&
filename
,
const
String
&
open
,
const
String
&
close
,
const
String
&
found
)
:
ParseError
(
_
(
"Expected closing '"
)
+
close
+
_
(
"' for this '"
)
+
open
+
_
(
"' instead of '"
)
+
found
+
_
(
"'"
))
:
ParseError
(
_
(
"Expected closing '"
)
+
close
+
_
(
"' for this '"
)
+
open
+
_
(
"' instead of '"
)
+
found
+
_
(
"'"
))
,
start
(
pos1
),
end
(
pos2
+
found
.
size
()),
line
(
line
),
filename
(
filename
)
,
start
(
pos1
),
end
(
pos2
+
found
.
size
()),
line
(
line
),
filename
(
filename
)
{}
{}
String
ScriptParseError
::
what
()
const
{
String
ScriptParseError
::
what
()
const
{
return
String
(
_
(
"("
))
<<
(
int
)
start
<<
_
(
"): "
)
<<
Error
::
what
();
return
String
(
_
(
"("
))
<<
(
int
)
start
<<
_
(
"): "
)
<<
Error
::
what
();
}
}
String
concat
(
const
vector
<
ScriptParseError
>&
errors
)
{
String
concat
(
const
vector
<
ScriptParseError
>&
errors
)
{
String
total
;
String
total
;
FOR_EACH_CONST
(
e
,
errors
)
{
FOR_EACH_CONST
(
e
,
errors
)
{
if
(
!
total
.
empty
())
total
+=
_
(
"
\n
"
);
if
(
!
total
.
empty
())
total
+=
_
(
"
\n
"
);
total
+=
e
.
what
();
total
+=
e
.
what
();
}
}
return
total
;
return
total
;
}
}
ScriptParseErrors
::
ScriptParseErrors
(
const
vector
<
ScriptParseError
>&
errors
)
ScriptParseErrors
::
ScriptParseErrors
(
const
vector
<
ScriptParseError
>&
errors
)
:
ParseError
(
concat
(
errors
))
:
ParseError
(
concat
(
errors
))
{}
{}
// ----------------------------------------------------------------------------- : Error handling
// ----------------------------------------------------------------------------- : Error handling
// Errors for which a message box was already shown
// Errors for which a message box was already shown
vector
<
String
>
previous_errors
;
vector
<
String
>
previous_errors
;
vector
<
String
>
previous_warnings
;
vector
<
String
>
previous_warnings
;
String
pending_errors
;
String
pending_errors
;
String
pending_warnings
;
String
pending_warnings
;
DECLARE_TYPEOF_COLLECTION
(
String
);
DECLARE_TYPEOF_COLLECTION
(
String
);
wxMutex
crit_error_handling
;
wxMutex
crit_error_handling
;
bool
write_errors_to_cli
=
false
;
bool
write_errors_to_cli
=
false
;
void
show_pending_errors
();
void
show_pending_errors
();
void
show_pending_warnings
();
void
show_pending_warnings
();
void
handle_error
(
const
String
&
e
,
bool
allow_duplicate
=
true
,
bool
now
=
true
)
{
void
handle_error
(
const
String
&
e
,
bool
allow_duplicate
=
true
,
bool
now
=
true
)
{
{
{
// Thread safety
// Thread safety
wxMutexLocker
lock
(
crit_error_handling
);
wxMutexLocker
lock
(
crit_error_handling
);
// Check duplicates
// Check duplicates
if
(
!
allow_duplicate
)
{
if
(
!
allow_duplicate
)
{
FOR_EACH
(
pe
,
previous_errors
)
{
FOR_EACH
(
pe
,
previous_errors
)
{
if
(
e
==
pe
)
return
;
if
(
e
==
pe
)
return
;
}
}
previous_errors
.
push_back
(
e
);
previous_errors
.
push_back
(
e
);
}
}
// Only show errors in the main thread
// Only show errors in the main thread
if
(
!
pending_errors
.
empty
())
pending_errors
+=
_
(
"
\n\n
"
);
if
(
!
pending_errors
.
empty
())
pending_errors
+=
_
(
"
\n\n
"
);
pending_errors
+=
e
;
pending_errors
+=
e
;
}
}
// show messages
// show messages
if
((
write_errors_to_cli
||
now
)
&&
wxThread
::
IsMain
())
{
if
((
write_errors_to_cli
||
now
)
&&
wxThread
::
IsMain
())
{
show_pending_warnings
();
// warnings are older, show them first
show_pending_warnings
();
// warnings are older, show them first
show_pending_errors
();
show_pending_errors
();
}
}
}
}
void
handle_error
(
const
Error
&
e
,
bool
allow_duplicate
,
bool
now
)
{
void
handle_error
(
const
Error
&
e
,
bool
allow_duplicate
,
bool
now
)
{
handle_error
(
e
.
what
(),
allow_duplicate
,
now
);
handle_error
(
e
.
what
(),
allow_duplicate
,
now
);
}
}
void
handle_warning
(
const
String
&
w
,
bool
now
)
{
void
handle_warning
(
const
String
&
w
,
bool
now
)
{
{
{
// Check duplicates
// Check duplicates
wxMutexLocker
lock
(
crit_error_handling
);
wxMutexLocker
lock
(
crit_error_handling
);
// Check duplicates
// Check duplicates
FOR_EACH
(
pw
,
previous_warnings
)
{
FOR_EACH
(
pw
,
previous_warnings
)
{
if
(
w
==
pw
)
return
;
if
(
w
==
pw
)
return
;
}
}
previous_warnings
.
push_back
(
w
);
previous_warnings
.
push_back
(
w
);
// Only show errors in the main thread
// Only show errors in the main thread
if
(
!
pending_warnings
.
empty
())
pending_warnings
+=
_
(
"
\n\n
"
);
if
(
!
pending_warnings
.
empty
())
pending_warnings
+=
_
(
"
\n\n
"
);
pending_warnings
+=
w
;
pending_warnings
+=
w
;
}
}
// show messages
// show messages
if
((
write_errors_to_cli
||
now
)
&&
wxThread
::
IsMain
())
{
if
((
write_errors_to_cli
||
now
)
&&
wxThread
::
IsMain
())
{
show_pending_errors
();
show_pending_errors
();
show_pending_warnings
();
show_pending_warnings
();
}
}
}
}
void
handle_pending_errors
()
{
void
handle_pending_errors
()
{
show_pending_errors
();
show_pending_errors
();
show_pending_warnings
();
show_pending_warnings
();
}
}
void
show_pending_errors
()
{
void
show_pending_errors
()
{
assert
(
wxThread
::
IsMain
());
assert
(
wxThread
::
IsMain
());
if
(
crit_error_handling
.
TryLock
()
!=
wxMUTEX_NO_ERROR
)
if
(
crit_error_handling
.
TryLock
()
!=
wxMUTEX_NO_ERROR
)
return
;
return
;
if
(
!
pending_errors
.
empty
())
{
if
(
!
pending_errors
.
empty
())
{
if
(
write_errors_to_cli
)
{
if
(
write_errors_to_cli
)
{
cli
.
showError
(
pending_errors
);
cli
.
showError
(
pending_errors
);
}
else
{
}
else
{
wxMessageBox
(
pending_errors
,
_
(
"Error"
),
wxOK
|
wxICON_ERROR
);
wxMessageBox
(
pending_errors
,
_
(
"Error"
),
wxOK
|
wxICON_ERROR
);
}
}
pending_errors
.
clear
();
pending_errors
.
clear
();
}
}
crit_error_handling
.
Unlock
();
crit_error_handling
.
Unlock
();
}
}
void
show_pending_warnings
()
{
void
show_pending_warnings
()
{
assert
(
wxThread
::
IsMain
());
assert
(
wxThread
::
IsMain
());
if
(
crit_error_handling
.
TryLock
()
!=
wxMUTEX_NO_ERROR
)
if
(
crit_error_handling
.
TryLock
()
!=
wxMUTEX_NO_ERROR
)
return
;
return
;
if
(
!
pending_warnings
.
empty
())
{
if
(
!
pending_warnings
.
empty
())
{
if
(
write_errors_to_cli
)
{
if
(
write_errors_to_cli
)
{
cli
.
showWarning
(
pending_warnings
);
cli
.
showWarning
(
pending_warnings
);
}
else
{
}
else
{
wxMessageBox
(
pending_warnings
,
_
(
"Warning"
),
wxOK
|
wxICON_EXCLAMATION
);
wxMessageBox
(
pending_warnings
,
_
(
"Warning"
),
wxOK
|
wxICON_EXCLAMATION
);
}
}
pending_warnings
.
clear
();
pending_warnings
.
clear
();
}
}
crit_error_handling
.
Unlock
();
crit_error_handling
.
Unlock
();
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment