Skip to content

Commit c4a3047

Browse files
authored
webgpu : Remove try catch (#8936)
1 parent dfcdc9c commit c4a3047

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

filament/backend/src/webgpu/WebGPUProgram.cpp

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,14 @@
2626
#include <utils/FixedCapacityVector.h>
2727
#include <utils/Panic.h>
2828
#include <utils/debug.h>
29-
#include <utils/ostream.h>
3029

3130
#include <webgpu/webgpu_cpp.h>
32-
#include <dawn/webgpu_cpp_print.h>
3331

3432
#include <array>
3533
#include <cstdint>
34+
#include <cstdlib>
35+
#include <limits>
3636
#include <sstream>
37-
#include <stdexcept>
3837
#include <string>
3938
#include <string_view>
4039
#include <unordered_map>
@@ -98,15 +97,28 @@ namespace {
9897
}
9998
posOfEqual += posAfterId; // position in original source overall, not just the segment
10099
int constantId = 0;
101-
try {
102-
constantId = std::stoi(idStr.data());
103-
} catch (const std::invalid_argument& e) {
104-
PANIC_POSTCONDITION("Invalid spec constant id '%s' in %s (not a valid integer?): %s",
105-
idStr.data(), shaderLabel.data(), e.what());
106-
} catch (const std::out_of_range& e) {
107-
PANIC_POSTCONDITION(
108-
"Invalid spec constant id '%s' in %s (not an integer? out of range?): %s",
109-
idStr.data(), shaderLabel.data(), e.what());
100+
char* endPtr;
101+
errno = 0; // Clear errno before the call
102+
103+
long tempConstantId = std::strtol(idStr.data(), &endPtr, 10);
104+
105+
// Check for conversion errors
106+
if (endPtr == idStr.data() || *endPtr != '\0' || errno == ERANGE) {
107+
// Parsing failed, or conversion was out of range for 'long'
108+
// or the string contained non-numeric characters after the number.
109+
PANIC_POSTCONDITION("Invalid spec constant id '%s' in %s (not a valid integer or out "
110+
"of range for 'long'?)",
111+
idStr.data(), shaderLabel.data());
112+
} else {
113+
// Check if the parsed long value fits into an int
114+
if (tempConstantId > std::numeric_limits<int>::max() ||
115+
tempConstantId < std::numeric_limits<int>::min()) {
116+
PANIC_POSTCONDITION(
117+
"Invalid spec constant id '%s' in %s (value out of range for 'int')",
118+
idStr.data(), shaderLabel.data());
119+
} else {
120+
constantId = static_cast<int>(tempConstantId);
121+
}
110122
}
111123
const auto newValueItr = specConstants.find(static_cast<uint32_t>(constantId));
112124
if (newValueItr == specConstants.end()) {

0 commit comments

Comments
 (0)