rust-skia / rust-skia

Rust Bindings for the Skia Graphics Library
MIT License
1.45k stars 133 forks source link

segmentation fault occur while using with v8 and sdl2 #316

Closed colorhook closed 3 years ago

colorhook commented 4 years ago

After using v8 and sdl2 together, segmentation fault occur.

  1. program panic while window render loop
  2. If using headless mode(without sdl2), program is ok.
  3. If disable canvas.draw_xxx method call in window render loop, program is ok too.

then, I found a similar demo and clone the repo: https://github.com/michael-swan/proveit

just add one line code

extern crate rusty_v8;

and get error

Process:               proveit [24993]
Path:                  /Users/USER/*/proveit
Identifier:            proveit
Version:               0
Code Type:             X86-64 (Native)
Parent Process:        zsh [82764]
Responsible:           Terminal [511]
User ID:               501

Date/Time:             2020-04-14 22:53:43.178 +0800
OS Version:            Mac OS X 10.15.2 (19C57)
Report Version:        12
Bridge OS Version:     3.0 (14Y908)
Anonymous UUID:        73EF03D5-C82C-90DC-6CE8-3605E202F7C8

Sleep/Wake UUID:       34549B26-0159-47FD-9323-76601D44F1A9

Time Awake Since Boot: 860000 seconds
Time Since Wake:       5500 seconds

System Integrity Protection: enabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       EXC_I386_GPFLT
Exception Note:        EXC_CORPSE_NOTIFY

Termination Signal:    Segmentation fault: 11
Termination Reason:    Namespace SIGNAL, Code 0xb
Terminating Process:   exc handler [24993]

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libsystem_platform.dylib        0x00007fff69a04c92 _platform_strlen + 18
1   proveit                         0x000000010a59f7be SkSL::to_string(long long) + 318
2   proveit                         0x000000010a577991 SkSL::IRGenerator::convertVarDeclarations(SkSL::ASTNode const&, SkSL::Variable::Storage) + 3089
3   proveit                         0x000000010a57f196 SkSL::IRGenerator::convertInterfaceBlock(SkSL::ASTNode const&) + 342
4   proveit                         0x000000010a58946d SkSL::IRGenerator::convertProgram(SkSL::Program::Kind, char const*, unsigned long, SkSL::SymbolTable&, std::__1::vector<std::__1::unique_ptr<SkSL::ProgramElement, std::__1::default_delete<SkSL::ProgramElement> >, std::__1::allocator<std::__1::unique_ptr<SkSL::ProgramElement, std::__1::default_delete<SkSL::ProgramElement> > > >*) + 541
5   proveit                         0x000000010a564d20 SkSL::Compiler::processIncludeFile(SkSL::Program::Kind, char const*, unsigned long, std::__1::shared_ptr<SkSL::SymbolTable>, std::__1::vector<std::__1::unique_ptr<SkSL::ProgramElement, std::__1::default_delete<SkSL::ProgramElement> >, std::__1::allocator<std::__1::unique_ptr<SkSL::ProgramElement, std::__1::default_delete<SkSL::ProgramElement> > > >*, std::__1::shared_ptr<SkSL::SymbolTable>*) + 432
6   proveit                         0x000000010a56481f SkSL::Compiler::Compiler(SkSL::Compiler::Flags) + 5503
7   proveit                         0x000000010a6e0dca GrGLContext::compiler() const + 42
8   proveit                         0x000000010a6fb4e9 GrSkSLtoGLSL(GrGLContext const&, SkSL::Program::Kind, SkSL::String const&, SkSL::Program::Settings const&, SkSL::String*, GrContextOptions::ShaderErrorHandler*) + 41
9   proveit                         0x000000010a6f7db7 GrGLProgramBuilder::finalize(GrGLPrecompiledProgram const*) + 2215
10  proveit                         0x000000010a6f74a5 GrGLProgramBuilder::CreateProgram(GrRenderTarget*, GrProgramInfo const&, GrProgramDesc*, GrGLGpu*, GrGLPrecompiledProgram const*) + 1429
11  proveit                         0x000000010a6ee3f4 GrGLGpu::ProgramCache::refProgram(GrGLGpu*, GrRenderTarget*, GrProgramInfo const&) + 356
12  proveit                         0x000000010a6e660f GrGLGpu::flushGLState(GrRenderTarget*, GrProgramInfo const&) + 47
13  proveit                         0x000000010a6e817b GrGLGpu::draw(GrRenderTarget*, GrProgramInfo const&, GrMesh const*, int) + 75
14  proveit                         0x000000010a5d5929 GrOpsRenderPass::draw(GrProgramInfo const&, GrMesh const*, int, SkRect const&) + 105
15  proveit                         0x000000010a5d40bb GrOpFlushState::executeDrawsAndUploadsForMeshDrawOp(GrOp const*, SkRect const&, GrPipeline const*) + 123
16  proveit                         0x000000010a5d73d7 GrOp::execute(GrOpFlushState*, SkRect const&) + 167
17  proveit                         0x000000010a5d7270 GrOpsTask::onExecute(GrOpFlushState*) + 1008
18  proveit                         0x000000010a5c8dd2 GrDrawingManager::executeRenderTasks(int, int, GrOpFlushState*, int*) + 546
19  proveit                         0x000000010a5c86ce GrDrawingManager::flush(GrSurfaceProxy**, int, SkSurface::BackendSurfaceAccess, GrFlushInfo const&, GrPrepareForExternalIORequests const&) + 1838
20  proveit                         0x000000010a5c8f63 GrDrawingManager::flushSurfaces(GrSurfaceProxy**, int, SkSurface::BackendSurfaceAccess, GrFlushInfo const&) + 115
21  proveit                         0x000000010a5ecc8f GrRenderTargetContext::flush(SkSurface::BackendSurfaceAccess, GrFlushInfo const&) + 287
22  proveit                         0x000000010a69ca65 SkGpuDevice::flush() + 37
23  proveit                         0x000000010a3d4435 skia_bindings::bindings::SkCanvas::flush::h1b77b242ac05c51b + 21 (bindings.rs:9241)
24  proveit                         0x000000010a3d4992 skia_safe::core::canvas::Canvas::flush::h605d1df33217ab10 + 34 (canvas.rs:281)
25  proveit                         0x0000000109d4cd63 proveit::main::h3e49d9dee6c0850f + 8755 (main.rs:354)
26  proveit                         0x0000000109d4d8d6 std::rt::lang_start::_$u7b$$u7b$closure$u7d$$u7d$::hae715e2483aaadda + 22 (rt.rs:67)
27  proveit                         0x000000010a780808 std::panicking::try::do_call::hf2b35caddf59127c + 24 (panicking.rs:305)
28  proveit                         0x000000010a78236b __rust_maybe_catch_panic + 27 (lib.rs:94)
29  proveit                         0x000000010a78109e std::rt::lang_start_internal::h8e563903bf99e7c1 + 542 (rt.rs:51)
30  proveit                         0x0000000109d4d8b2 std::rt::lang_start::h07aebbe8358ed533 + 66 (rt.rs:67)
31  proveit                         0x0000000109d4d862 main + 34
32  libdyld.dylib                   0x00007fff6980e7fd start + 1
pragmatrix commented 4 years ago

I can reproduce this with Rust nightly, but with two changes I made to the project:

It fails with nearly the same stack trace:

proveit(1373,0x10adb5dc0) malloc: *** error for object 0x200000000000000: pointer being freed was not allocated
proveit(1373,0x10adb5dc0) malloc: *** set a breakpoint in malloc_error_break to debug

and

Process:               proveit [1373]
Path:                  /Users/USER/*/proveit
Identifier:            proveit
Version:               0
Code Type:             X86-64 (Native)
Parent Process:        zsh [1050]
Responsible:           Terminal [1009]
User ID:               501

Date/Time:             2020-04-15 10:26:34.249 +0200
OS Version:            Mac OS X 10.15.4 (19E287)
Report Version:        12
Anonymous UUID:        D0CAE850-8011-B9E2-10E5-9B77DDA98C74

Time Awake Since Boot: 1200 seconds

System Integrity Protection: enabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_CRASH (SIGABRT)
Exception Codes:       0x0000000000000000, 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Application Specific Information:
abort() called
proveit(1373,0x10adb5dc0) malloc: *** error for object 0x200000000000000: pointer being freed was not allocated

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib          0x00007fff7003333a __pthread_kill + 10
1   libsystem_pthread.dylib         0x00007fff700efe60 pthread_kill + 430
2   libsystem_c.dylib               0x00007fff6ffba808 abort + 120
3   libsystem_malloc.dylib          0x00007fff700b050b malloc_vreport + 548
4   libsystem_malloc.dylib          0x00007fff700b340f malloc_report + 151
5   proveit                         0x0000000106771f75 operator delete(void*) + 21 (new.cpp:133)
6   proveit                         0x0000000105f3fa6d SkSL::IRGenerator::convertVarDeclarations(SkSL::ASTNode const&, SkSL::Variable::Storage) + 4141
7   proveit                         0x0000000105f46e56 SkSL::IRGenerator::convertInterfaceBlock(SkSL::ASTNode const&) + 342
8   proveit                         0x0000000105f5112d SkSL::IRGenerator::convertProgram(SkSL::Program::Kind, char const*, unsigned long, SkSL::SymbolTable&, std::__1::vector<std::__1::unique_ptr<SkSL::ProgramElement, std::__1::default_delete<SkSL::ProgramElement> >, std::__1::allocator<std::__1::unique_ptr<SkSL::ProgramElement, std::__1::default_delete<SkSL::ProgramElement> > > >*) + 541
9   proveit                         0x0000000105f2c9e0 SkSL::Compiler::processIncludeFile(SkSL::Program::Kind, char const*, unsigned long, std::__1::shared_ptr<SkSL::SymbolTable>, std::__1::vector<std::__1::unique_ptr<SkSL::ProgramElement, std::__1::default_delete<SkSL::ProgramElement> >, std::__1::allocator<std::__1::unique_ptr<SkSL::ProgramElement, std::__1::default_delete<SkSL::ProgramElement> > > >*, std::__1::shared_ptr<SkSL::SymbolTable>*) + 432
10  proveit                         0x0000000105f2c4df SkSL::Compiler::Compiler(SkSL::Compiler::Flags) + 5503
11  proveit                         0x00000001060aa11a GrGLContext::compiler() const + 42
12  proveit                         0x00000001060c4839 GrSkSLtoGLSL(GrGLContext const&, SkSL::Program::Kind, SkSL::String const&, SkSL::Program::Settings const&, SkSL::String*, GrContextOptions::ShaderErrorHandler*) + 41
13  proveit                         0x00000001060c1107 GrGLProgramBuilder::finalize(GrGLPrecompiledProgram const*) + 2215
14  proveit                         0x00000001060c07f5 GrGLProgramBuilder::CreateProgram(GrRenderTarget*, GrProgramInfo const&, GrProgramDesc*, GrGLGpu*, GrGLPrecompiledProgram const*) + 1429
15  proveit                         0x00000001060b7744 GrGLGpu::ProgramCache::refProgram(GrGLGpu*, GrRenderTarget*, GrProgramInfo const&) + 356
16  proveit                         0x00000001060af95f GrGLGpu::flushGLState(GrRenderTarget*, GrProgramInfo const&) + 47
17  proveit                         0x00000001060b14cb GrGLGpu::draw(GrRenderTarget*, GrProgramInfo const&, GrMesh const*, int) + 75
18  proveit                         0x0000000105f9e8c9 GrOpsRenderPass::draw(GrProgramInfo const&, GrMesh const*, int, SkRect const&) + 105
19  proveit                         0x0000000105f9d05b GrOpFlushState::executeDrawsAndUploadsForMeshDrawOp(GrOp const*, SkRect const&, GrPipeline const*) + 123
20  proveit                         0x0000000105ff4d84 (anonymous namespace)::FillRectOp::onExecute(GrOpFlushState*, SkRect const&) + 116
21  proveit                         0x0000000105fa0377 GrOp::execute(GrOpFlushState*, SkRect const&) + 167
22  proveit                         0x0000000105fa0210 GrOpsTask::onExecute(GrOpFlushState*) + 1008
23  proveit                         0x0000000105f91a9b GrDrawingManager::executeRenderTasks(int, int, GrOpFlushState*, int*) + 203
24  proveit                         0x0000000105f914ee GrDrawingManager::flush(GrSurfaceProxy**, int, SkSurface::BackendSurfaceAccess, GrFlushInfo const&, GrPrepareForExternalIORequests const&) + 1838
25  proveit                         0x0000000105f91d83 GrDrawingManager::flushSurfaces(GrSurfaceProxy**, int, SkSurface::BackendSurfaceAccess, GrFlushInfo const&) + 115
26  proveit                         0x0000000105fb5c2f GrRenderTargetContext::flush(SkSurface::BackendSurfaceAccess, GrFlushInfo const&) + 287
27  proveit                         0x0000000106065a05 SkGpuDevice::flush() + 37
28  proveit                         0x0000000105d9c281 skia_bindings::bindings::SkCanvas::flush::hb7eb0d388094ecde + 17 (bindings.rs:9241)
29  proveit                         0x0000000105d9ce72 skia_safe::core::canvas::Canvas::flush::h43c0efa3d71caa75 + 34
30  proveit                         0x0000000105d6bc4a proveit::main::h44cca76e4466a5d4 + 8938 (main.rs:354)
31  proveit                         0x0000000105d6461d std::rt::lang_start::_$u7b$$u7b$closure$u7d$$u7d$::h4ce5f660503ace59 + 29 (rt.rs:67)
32  proveit                         0x0000000106795604 std::rt::lang_start_internal::h70084482207aef9f + 564 (rt.rs:51)
33  proveit                         0x0000000105d645f1 std::rt::lang_start::h828ddb3f6bd9f333 + 65 (rt.rs:67)
34  proveit                         0x0000000105d6c4c2 main + 34
35  libdyld.dylib                   0x00007fff6feebcc9 start + 1

I would suspect that this is a similar problem like in #299: a mixup of same named functions pulled from different native C / C++ libraries.

pragmatrix commented 4 years ago

Hmm, with SKIA_DEBUG=1 the failure seems to be detected slightly earlier in the constructor of SkSL::Compiler::Compiler:

../../../../../../../rust-skia/skia-bindings/skia/src/sksl/SkSLCompiler.cpp:1711: fatal error: "assert(fSource)"
Process:               proveit [5349]
Path:                  /Users/USER/*/proveit
Identifier:            proveit
Version:               0
Code Type:             X86-64 (Native)
Parent Process:        zsh [1050]
Responsible:           Terminal [1009]
User ID:               501

Date/Time:             2020-04-15 11:37:18.785 +0200
OS Version:            Mac OS X 10.15.4 (19E287)
Report Version:        12
Anonymous UUID:        D0CAE850-8011-B9E2-10E5-9B77DDA98C74

Time Awake Since Boot: 5500 seconds

System Integrity Protection: enabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BREAKPOINT (SIGTRAP)
Exception Codes:       0x0000000000000002, 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Termination Signal:    Trace/BPT trap: 5
Termination Reason:    Namespace SIGNAL, Code 0x5
Terminating Process:   exc handler [5349]

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   proveit                         0x0000000107c1b455 sk_abort_no_print() + 5 (SkMemory_malloc.cpp:45)
1   proveit                         0x0000000107b6a9c2 SkSL::Compiler::position(int)::$_21::operator()() const + 50 (SkSLCompiler.cpp:1711)
2   proveit                         0x0000000107b6a8f3 SkSL::Compiler::position(int) + 51 (SkSLCompiler.cpp:1712)
3   proveit                         0x0000000107b6aa6e SkSL::Compiler::error(int, SkSL::String) + 62 (SkSLCompiler.cpp:1728)
4   proveit                         0x0000000107bf3e56 SkSL::SymbolTable::addWithoutOwnership(SkSL::StringFragment, SkSL::Symbol const*) + 1110 (SkSLSymbolTable.cpp:104)
5   proveit                         0x0000000107b5d446 SkSL::Compiler::Compiler(SkSL::Compiler::Flags) + 2902 (SkSLCompiler.cpp:134)
6   proveit                         0x0000000107b624ab SkSL::Compiler::Compiler(SkSL::Compiler::Flags) + 27 (SkSLCompiler.cpp:292)
7   proveit                         0x0000000107f46da7 GrGLContext::compiler() const + 55 (GrGLContext.cpp:99)
8   proveit                         0x0000000107f955f6 GrSkSLtoGLSL(GrGLContext const&, SkSL::Program::Kind, SkSL::String const&, SkSL::Program::Settings const&, SkSL::String*, GrContextOptions::ShaderErrorHandler*) + 70 (GrGLShaderStringBuilder.cpp:37)
9   proveit                         0x0000000107f8dbc2 GrGLProgramBuilder::finalize(GrGLPrecompiledProgram const*) + 2642 (GrGLProgramBuilder.cpp:324)
10  proveit                         0x0000000107f8d070 GrGLProgramBuilder::CreateProgram(GrRenderTarget*, GrProgramInfo const&, GrProgramDesc*, GrGLGpu*, GrGLPrecompiledProgram const*) + 448 (GrGLProgramBuilder.cpp:71)
11  proveit                         0x0000000107f6f46c GrGLGpu::ProgramCache::refProgram(GrGLGpu*, GrRenderTarget*, GrProgramInfo const&) + 572 (GrGLGpuProgramCache.cpp:75)
12  proveit                         0x0000000107f54809 GrGLGpu::flushGLState(GrRenderTarget*, GrProgramInfo const&) + 57 (GrGLGpu.cpp:1821)
13  proveit                         0x0000000107f5904b GrGLGpu::draw(GrRenderTarget*, GrProgramInfo const&, GrMesh const*, int) + 91 (GrGLGpu.cpp:2369)
14  proveit                         0x0000000107f697b8 GrGLOpsRenderPass::onDraw(GrProgramInfo const&, GrMesh const*, int, SkRect const&) + 56 (GrGLOpsRenderPass.h:55)
15  proveit                         0x0000000107c91298 GrOpsRenderPass::draw(GrProgramInfo const&, GrMesh const*, int, SkRect const&) + 536 (GrOpsRenderPass.cpp:64)
16  proveit                         0x0000000107c8c331 GrOpFlushState::executeDrawsAndUploadsForMeshDrawOp(GrOp const*, SkRect const&, GrPipeline const*) + 993 (GrOpFlushState.cpp:57)
17  proveit                         0x0000000107d6cc91 (anonymous namespace)::FillRectOp::onExecute(GrOpFlushState*, SkRect const&) + 193 (GrFillRectOp.cpp:288)
18  proveit                         0x0000000107c94f41 GrOp::execute(GrOpFlushState*, SkRect const&) + 257 (GrOp.h:180)
19  proveit                         0x0000000107c94975 GrOpsTask::onExecute(GrOpFlushState*) + 1749 (GrOpsTask.cpp:587)
20  proveit                         0x0000000107c60311 GrRenderTask::execute(GrOpFlushState*) + 33 (GrRenderTask.h:38)
21  proveit                         0x0000000107c5fdd6 GrDrawingManager::executeRenderTasks(int, int, GrOpFlushState*, int*) + 358 (GrDrawingManager.cpp:452)
22  proveit                         0x0000000107c5f08b GrDrawingManager::flush(GrSurfaceProxy**, int, SkSurface::BackendSurfaceAccess, GrFlushInfo const&, GrPrepareForExternalIORequests const&) + 2779 (GrDrawingManager.cpp:364)
23  proveit                         0x0000000107c605f4 GrDrawingManager::flushSurfaces(GrSurfaceProxy**, int, SkSurface::BackendSurfaceAccess, GrFlushInfo const&) + 372 (GrDrawingManager.cpp:520)
24  proveit                         0x0000000107cd4650 GrDrawingManager::flushSurface(GrSurfaceProxy*, SkSurface::BackendSurfaceAccess, GrFlushInfo const&) + 48 (GrDrawingManager.h:102)
25  proveit                         0x0000000107cd22a1 GrRenderTargetContext::flush(SkSurface::BackendSurfaceAccess, GrFlushInfo const&) + 433 (GrRenderTargetContext.cpp:2178)
26  proveit                         0x0000000107e7678f SkGpuDevice::flush(SkSurface::BackendSurfaceAccess, GrFlushInfo const&) + 111 (SkGpuDevice.cpp:1609)
27  proveit                         0x0000000107e76716 SkGpuDevice::flush() + 70 (SkGpuDevice.cpp:1602)
28  proveit                         0x00000001077ad8b4 SkCanvas::onFlush() + 52 (SkCanvas.cpp:621)
29  proveit                         0x00000001077ad879 SkCanvas::flush() + 25 (SkCanvas.cpp:614)
30  proveit                         0x00000001077657c1 skia_bindings::bindings::SkCanvas::flush::hb71c2c7340939f6e + 17 (bindings.rs:9249)
31  proveit                         0x000000010776b722 skia_safe::core::canvas::Canvas::flush::h9010b335e7e60a7e + 34
32  proveit                         0x00000001077333aa proveit::main::hd1eb25342598a824 + 8938 (main.rs:354)
33  proveit                         0x00000001077374dd std::rt::lang_start::_$u7b$$u7b$closure$u7d$$u7d$::h23b9d93a9773bc5f + 29 (rt.rs:67)
34  proveit                         0x00000001086ca0c4 std::rt::lang_start_internal::h70084482207aef9f + 564 (rt.rs:51)
35  proveit                         0x00000001077374b1 std::rt::lang_start::hd0f10a187b88d7ac + 65 (rt.rs:67)
36  proveit                         0x0000000107733c22 main + 34
37  libdyld.dylib                   0x00007fff6feebcc9 start + 1
pragmatrix commented 3 years ago

Closing this, as the original reproduction repository is gone (https://github.com/michael-swan/proveit). May reopen if that problem is an issue with the latest rust-skia versions.