emscripten + sdl = 抛出异常:类型错误:无法设置未定义的属性'widthNative'
emscripten + sdl = exception thrown: TypeError: cannot set property 'widthNative' of undefined
我今天刚刚启动并运行了emscripten,但无论我使用什么示例,我都会不断收到以下错误:
exception thrown: TypeError: Cannot set property 'widthNative' of undefined,TypeError: Cannot set property 'widthNative' of undefined
at Object.Browser.updateCanvasDimensions (file:///Users/rspice/LocalDev/UAPDevTests/bld/app.out.js:6964:30)
at Object.Browser.setCanvasSize (file:///Users/rspice/LocalDev/UAPDevTests/bld/app.out.js:6944:17)
at _emscripten_set_canvas_size (file:///Users/rspice/LocalDev/UAPDevTests/bld/app.out.js:9485:15)
at Array._Emscripten_CreateWindow (file:///Users/rspice/LocalDev/UAPDevTests/bld/app.out.js:150624:2)
at _SDL_CreateWindow (file:///Users/rspice/LocalDev/UAPDevTests/bld/app.out.js:58841:41)
at _SDL_CreateWindowAndRenderer (file:///Users/rspice/LocalDev/UAPDevTests/bld/app.out.js:34710:8)
at _main (file:///Users/rspice/LocalDev/UAPDevTests/bld/app.out.js:10433:4)
at Object.asm._main (file:///Users/rspice/LocalDev/UAPDevTests/bld/app.out.js:179274:19)
at Object.callMain (file:///Users/rspice/LocalDev/UAPDevTests/bld/app.out.js:179457:30)
at doRun (file:///Users/rspice/LocalDev/UAPDevTests/bld/app.out.js:179515:60)
2016-04-28 16:30:39.060 app.out.js:6964 Uncaught TypeError: Cannot set property 'widthNative' of undefinedBrowser.updateCanvasDimensions @ app.out.js:6964Browser.setCanvasSize @ app.out.js:6944_emscripten_set_canvas_size @ app.out.js:9485_Emscripten_CreateWindow @ app.out.js:150624_SDL_CreateWindow @ app.out.js:58841_SDL_CreateWindowAndRenderer @ app.out.js:34710_main @ app.out.js:10433asm._main @ app.out.js:179274callMain @ app.out.js:179457doRun @ app.out.js:179515run @ app.out.js:179529(anonymous function) @ app.out.js:179618
我用的是铬和osx elcrapitan。
使用此编译:
/Users/rspice/LocalDev/Emscripten/emscripten/1.35.0/em++ -s USE_SDL=2 -s GL_DEBUG=1 /Users/rspice/LocalDev/UAPDevTests/src/main.cpp -o /Users/rspice/LocalDev/UAPDevTests/bld/app.out.js --use-preload-plugins
我将教程中的.cpp复制到了自己的文件中http://kripken.github.io/emscripten-site/docs/getting_started/Tutorial.html#generating-html
谢谢。
编辑:
如果我从网络上的其他地方运行这个.cpp,我会得到红框和一行,但会出现错误:
app.out.js:6269 emscripten_set_main_loop_timing: Cannot set timing mode for main loop since a main loop does not exist! Call emscripten_set_main_loop first to set one up.
我不明白,因为它存在。。。
main.cpp
#include <stdio.h>
#include <SDL2/SDL.h>
#include <assert.h>
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif
SDL_Window * window;
SDL_Renderer * renderer;
void render_func(void) {
SDL_SetRenderDrawColor(renderer, 200, 0, 0, 255);
SDL_RenderClear(renderer);
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255);
SDL_RenderDrawLine(renderer, 0, 0, 640, 320);
SDL_RenderPresent(renderer);
#ifdef EMSCRIPTEN
emscripten_cancel_main_loop();
#endif
}
int main(int argc, char* argv[])
{
assert(SDL_Init(SDL_INIT_VIDEO) == 0);
SDL_CreateWindowAndRenderer(640, 320, 0, &window, &renderer);
#ifdef EMSCRIPTEN
emscripten_set_main_loop(render_func, 0, 1);
#else
render_func();
#endif
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
如果我运行这个.cpp,我会得到
(index):40 you should see a smoothly-colored square - no sharp lines but the square borders!
2016-04-29 09:36:44.049 (index):40 and here is some text that should be HTML-friendly: amp: |&| double-quote: |"| quote: |'| less-than, greater-than, html-like tags: |<cheez></cheez>|
2016-04-29 09:36:44.050 (index):40 another line.
但没有颜色或正方形。
hello_world_sdl.cpp
#include <stdio.h>
#include <SDL/SDL.h>
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif
extern "C" int main(int argc, char** argv) {
printf("hello, world!n");
SDL_Init(SDL_INIT_VIDEO);
SDL_Surface *screen = SDL_SetVideoMode(256, 256, 32, SDL_SWSURFACE);
#ifdef TEST_SDL_LOCK_OPTS
EM_ASM("SDL.defaults.copyOnLock = false; SDL.defaults.discardOnLock = true; SDL.defaults.opaqueFrontBuffer = false;");
#endif
if (SDL_MUSTLOCK(screen)) SDL_LockSurface(screen);
for (int i = 0; i < 256; i++) {
for (int j = 0; j < 256; j++) {
#ifdef TEST_SDL_LOCK_OPTS
// Alpha behaves like in the browser, so write proper opaque pixels.
int alpha = 255;
#else
// To emulate native behavior with blitting to screen, alpha component is ignored. Test that it is so by outputting
// data (and testing that it does get discarded)
int alpha = (i+j) % 255;
#endif
*((Uint32*)screen->pixels + i * 256 + j) = SDL_MapRGBA(screen->format, i, j, 255-i, alpha);
}
}
if (SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen);
SDL_Flip(screen);
printf("you should see a smoothly-colored square - no sharp lines but the square borders!n");
printf("and here is some text that should be HTML-friendly: amp: |&| double-quote: |"| quote: |'| less-than, greater-than, html-like tags: |<cheez></cheez>|nanother line.n");
SDL_Quit();
return 0;
}
当我尝试这个例子加载图像时,我得到了IMG_Error:
或者类似的事情,但我以后会调查的。
现在我很确定,我只是不清楚,我不理解生成的JS以及我需要做什么来运行模块。。。因为我还没有写过任何东西,而有效的包括JS代码。你们知道有什么好的例子吗?
答案是我需要JS中的这个模块。
var Module = {
print: (function() {
var element = document.getElementById('output');
return function(text) {
element.innerHTML += text.replace('n', '<br>', 'g') + '<br>';
};
})(),
canvas: document.getElementById('canvas')
};
"基本上就是这样,是的。定义Module.print和printErr,控制台应用程序就可以工作,添加Module.canvas来获得渲染。有关默认内容,请参阅src/shell.html。"
相关文章:
- 编译C++时未定义的引用
- vscode g++链路故障:体系结构x86_64的未定义符号
- 如何修复此错误:未定义对"距离(浮点数,浮点数,浮点数,浮点数,浮点数)"的引用
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- 不知道某个东西是否被忽略会引入未定义的行为吗
- 对C宏的未定义引用,但在定义它时会出现重新定义错误
- 未定义的引用在哪里
- 编译时的 CImg 库返回对"__imp_SetDIBitsToDevice"的未定义引用
- 对Py_Initialize()的未定义引用
- c++11评估顺序(未定义的行为)
- 使用mysql c++连接器的未定义引用
- 从python调用openMP共享库时,未定义opnMP函数
- 在 Mac 上使用 CMAKE 将 FFTW 和 FFTWPP 链接到项目中时未定义的符号
- Cmake 链接问题:未定义对 Button::mousePressEvent(QGraphicsSceneMouseE
- 未定义的引用 .. 使用 OpenCV 编译 C++ 代码时,从命令行
- 具有外部"c"和程序集的未定义函数
- 此增量后语句是否会导致未定义的行为?
- 尝试调用 .h 文件中定义的变量时出现变量未定义错误
- 在C++中使用内联方法时出现未定义的符号错误
- emscripten + sdl = 抛出异常:类型错误:无法设置未定义的属性'widthNative'