ClassCastException when creating default context in JS
Closed this issue · 2 comments
andrey-zakharov commented
I've made clean Kotlin/JS project, add dependency
kotlin {
js(IR) {
binaries.executable()
browser {
commonWebpackConfig {
cssSupport.enabled = true
}
}
}
dependencies {
implementation("de.fabmax.kool:kool-core-js:0.8.0")
}
}
Build and run, got ClassCastException
in console:
"ClassCastException
at THROW_CCE (webpack-internal:///./kotlin/untitled.js:21774:11)
at new JsContext (webpack-internal:///./kotlin/untitled.js:89775:68)
at JsImpl.createContext_u6767_k$ (webpack-internal:///./kotlin/untitled.js:86481:20)
at createContext (webpack-internal:///./kotlin/untitled.js:86443:33)
at createDefaultContext (webpack-internal:///./kotlin/untitled.js:86440:12)
at main (webpack-internal:///./kotlin/untitled.js:95226:15)
at Object.eval (webpack-internal:///./kotlin/untitled.js:95613:3)
at eval (webpack-internal:///./kotlin/untitled.js:5:35)
at eval (webpack-internal:///./kotlin/untitled.js:8:2)
at Object../kotlin/untitled.js (http://localhost:8080/untitled.js:505:1)"
my versions:
kotlin: 1.6.10
webpack: 5.57.1
fabmax commented
Hmm I've never seen this error and it's a bit difficult to see where this happens without the correct line numbers.
As a wild guess I could imagine that the error happens on getting the canvas element, which is casted to an HTMLCanvasElement
does your html contain a canvas element with id glCanvas
(like in the kool-demo index.html)?
andrey-zakharov commented
Yes, index.html is just with <script>, and nothing more. WIth such index.html it looks like working great:
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Kotlin + OpenGL = KOOL</title>
<style>
body {
background-color: black;
border: 0;
padding: 0;
margin: 0;
}
canvas {
width: 100vw;
height: 100vh;
display: block;
}
</style>
</head>
<body>
<!-- Hidden div is needed to get the physical screen resolution, i.e. how many pixels fit into 1 inch -->
<!-- Apparently this always results in 96 dpi anyway... :/ -->
<div id="dpiMeasure" style="height: 1in; width: 1in; position: fixed; left: 100%; top: 100%;"></div>
<!-- tabindex is required to make canvas focusable, needed to get per-canvas key events -->
<canvas id="glCanvas" tabindex="1">
Your browser doesn't appear to support the
<code><canvas></code> element.
</canvas>
<script src="untitled.js"></script>
</body>
</html>
But. looks like need some dumb proof error handling.