Used __builtin_wasm_memory_size(0) instead of having the Javascript code call init_mem with the initial page count. Added a simple <div> below the canvas that can hold any number of labels that can be filled/updated through jsSetLabel which lives in a new file misc_functions.js.
This commit is contained in:
@@ -9,20 +9,19 @@ Description:
|
||||
|
||||
extern unsigned char __heap_base;
|
||||
|
||||
static void* heapBaseAddress = 0;
|
||||
static void* heapBaseAddress = nullptr;
|
||||
static size_t stdCurrentHeapSize = 0;
|
||||
static size_t stdCurrentPageCount = 0;
|
||||
|
||||
WASM_EXPORT(init_mem) void init_mem(size_t numInitialPages)
|
||||
{
|
||||
heapBaseAddress = (void*)&__heap_base;
|
||||
stdCurrentPageCount = numInitialPages;
|
||||
}
|
||||
|
||||
//These are our own std-like functions for interacting with WebAssembly memory
|
||||
void* grow_mem(size_t numBytes)
|
||||
{
|
||||
assert_msg(heapBaseAddress != nullptr, "growmem called before initmem! Make sure initmem is being called by the Javascript code!");
|
||||
if (heapBaseAddress == nullptr)
|
||||
{
|
||||
stdCurrentPageCount = __builtin_wasm_memory_size(0);
|
||||
heapBaseAddress = (void*)&__heap_base;
|
||||
}
|
||||
|
||||
size_t memorySizeNeeded = ((size_t)heapBaseAddress) + stdCurrentHeapSize;
|
||||
size_t numPagesNeeded = (memorySizeNeeded / WASM_MEMORY_PAGE_SIZE) + (((memorySizeNeeded % WASM_MEMORY_PAGE_SIZE) > 0) ? 1 : 0);
|
||||
if (numPagesNeeded > WASM_MEMORY_MAX_NUM_PAGES)
|
||||
|
||||
@@ -26,7 +26,6 @@ _Noreturn void abort_msg(const char* message);
|
||||
// void* aligned_alloc(size_t numBytes, size_t alignmentSize);
|
||||
|
||||
//These are our own std-like functions for interacting with WebAssembly memory
|
||||
WASM_EXPORT(init_mem) void init_mem(size_t numInitialPages);
|
||||
void* grow_mem(size_t numBytes);
|
||||
size_t get_mem();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user