Access violation when trying to destroy unit

Access violation when trying to destroy unit

Anonymous
Not applicable
1,220 Views
9 Replies
Message 1 of 10

Access violation when trying to destroy unit

Anonymous
Not applicable

So, I am working on a inventory system, and want to despawn/destroy the unit that the player picks up. However, when I call

stingray.World.destroy_unit(stingray.Application.main_world(), unit)

I get an access violation. 


Same thing happens when I try to call the Unspawn Unit flow node via a unit flow eventthis_does_not_work.PNG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

but triggering the Unspawn node via a keyboard button works.

this_works.PNG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

And the access violation error message doesn't tell me much.

What's the best way to do this?

Reply
Reply
0 Likes
1,221 Views
9 Replies
Replies (9)
Message 2 of 10

Anonymous
Not applicable

Do you have the callstack available? 

 

I'm guessing you've written your own Unspawn Flow node which then does that Lua call and then it crashes?

 

You need to double check that both params, i.e the world and the unit aren't nil.

Reply
Reply
0 Likes
Message 3 of 10

Anonymous
Not applicable

I have not written my own Unspawn node, I am using the one available in Unit Flow.

 

I have checked that both the world and the unit aren't nil, and both of them work in other places of my project. 

Here is the callstack and error message from when I am calling 

stingray.World.destroy_unit(stingray.Application.main_world(), unit)

in my inventory script.

Editor / General: Test Engine: Access violation (0xc0000005) in build e643650096712533ea0ade9e638eeb1d671fbb05
    accessing address 00000000FABEFEBB from 00000001400947CE
Build identifier: `e643650096712533ea0ade9e638eeb1d671fbb05`

Product version: `Developer Build (1.7.0.0)`

Thread name: `main`

Error context
----------------------------------------

    Flow callback: ProjectFlowCallbacks.AimedAtUnit

Callstack
----------------------------------------

    0x4062ce74 d:\stingray\stingray\runtime\foundation\error\callstack_win.cpp(286): stingray::callstack::exception_call_stack
    0x4062d430 d:\stingray\stingray\runtime\foundation\error\exception_handling_win.cpp(97): stingray::exceptions::exception_filter
    0x4091f3de d:\stingray\stingray\runtime\main\windows\main.cpp(72): `safe_run'::`1'::filt$0
    0x408adf58 __C_specific_handler
    0x1589976d __chkstk
    0x15824c19 RtlImageNtHeaderEx
    0x1589887a KiUserExceptionDispatcher
    0x400947ce d:\stingray\stingray\runtime\application\flow\flow.cpp(495): stingray::flow::trigger_in_event
    0x4009d40d d:\stingray\stingray\runtime\application\flow\flow_nodes.cpp(125): stingray::flow_nodes::trigger_out_event
    0x402e945d d:\stingray\stingray\runtime\application\flow\flow_nodes\script_flow_nodes.cpp(355): stingray::flow_nodes::script_nodes::custom_script_node_trigger
    0x401da9a5 d:\stingray\stingray\runtime\application\flow\flow_nodes_registry.cpp(81): stingray::flow_nodes::registry::internal::trigger_callback
    0x4009d3a4 d:\stingray\stingray\runtime\application\flow\flow_nodes.cpp(555): stingray::flow_nodes::trigger_in_event
    0x400947d9 d:\stingray\stingray\runtime\application\flow\flow.cpp(496): stingray::flow::trigger_in_event
    0x4020a72f d:\stingray\stingray\runtime\application\flow\flow_nodes_api.h(53): stingray::flow_nodes::api::trigger_out_event
    0x402f0e88 d:\stingray\stingray\runtime\application\flow\flow_nodes\utility_flow_nodes.cpp(415): stingray::flow_nodes::utility_nodes::compare_objects_trigger
    0x401da9a5 d:\stingray\stingray\runtime\application\flow\flow_nodes_registry.cpp(81): stingray::flow_nodes::registry::internal::trigger_callback
    0x4009d3a4 d:\stingray\stingray\runtime\application\flow\flow_nodes.cpp(555): stingray::flow_nodes::trigger_in_event
    0x400947d9 d:\stingray\stingray\runtime\application\flow\flow.cpp(496): stingray::flow::trigger_in_event
    0x4020a72f d:\stingray\stingray\runtime\application\flow\flow_nodes_api.h(53): stingray::flow_nodes::api::trigger_out_event
    0x402d7d7d d:\stingray\stingray\runtime\application\flow\flow_nodes\event_flow_nodes.cpp(49): stingray::flow_nodes::event_nodes::event_callback
    0x401d9d57 d:\stingray\stingray\runtime\application\flow\flow_nodes_registry.cpp(99): stingray::flow_nodes::registry::internal::event_callback
    0x4009d3b9 d:\stingray\stingray\runtime\application\flow\flow_nodes.cpp(593): stingray::flow_nodes::trigger_out_event
    0x400948f8 d:\stingray\stingray\runtime\application\flow\flow.cpp(519): stingray::flow::trigger_out_event
    0x4009466e d:\stingray\stingray\runtime\application\flow\flow.cpp(534): stingray::flow::trigger_external_event
    0x401d6fc4 d:\stingray\stingray\runtime\application\flow\flow_switchboard.cpp(283): stingray::FlowSwitchboard::trigger_level_updates
    0x403ed03f d:\stingray\stingray\runtime\application\script\interface\if_level.cpp(81): <lambda_a8a59b0f7c5b41e9e742074e845fd0a8>::operator()
    0xeeaddcee lua_newstate
    0xeea9456d lua_pcall
    0x401b59c9 d:\stingray\stingray\runtime\application\script\lua_environment.cpp(687): stingray::LuaEnvironment::call
    0x401b5c7b d:\stingray\stingray\runtime\application\script\lua_environment.cpp(1039): stingray::LuaEnvironment::call_global
    0x4073d335 d:\stingray\stingray\runtime\game\game.cpp(466): `anonymous namespace'::MyGame::update
    0x401a1f0c d:\stingray\stingray\runtime\application\application.cpp(3004): stingray::Application::update

System Information
----------------------------------------

    --- CPU
    CPU: Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
    Vendor: GenuineIntel
    Logical processors: 8
    Family: 0:6, Model: 5:14
    Type: 0, Stepping: 3
    Features: SSE SSE2 SSE3 SSSE3 SSE4.1 SSE4.2
    Feature bits:
    EBX: 00000000 00010000 00001000 00000000 
    ECX: 01111111 11111010 11111011 10111111 
    EDX: 10111111 11101011 11111011 11111111 
    --- OS
    Windows version 6.2 build 9200
    Windows 8
    --- Graphics
    Graphics card: NVIDIA GeForce GTX 980 Ti (DirectX 11.0)
    Graphics card: Microsoft Basic Render Driver (DirectX 11.0)
    --- Sound
    No sound card detected.
    --- Network
    Network interface: Intel(R) Dual Band Wireless-AC 3165 (IPv4, IPv6)
    Network interface: Microsoft Wi-Fi Direct Virtual Adapter (IPv4, IPv6)
    Network interface: Realtek PCIe GBE Family Controller (IPv4, IPv6)
    Network interface: Microsoft 6to4 Adapter (IPv6)
    Network interface: Bluetooth Device (Personal Area Network) (IPv4, IPv6)
    Network interface: Microsoft ISATAP Adapter #3 (IPv6)
    --- Input
    Input device: Mouse (18.1): Mouse
    Input device: Keyboard (19.4): Keyboard
    Input device: Generic (17.0): Razer Lycosa

Lua Stack
----------------------------------------

    [0] [C]: in function trigger_level_update
    [1] core/appkit/lua/level_wrapper.lua:80: in function update
    [2] core/appkit/lua/app.lua:252: in function update
    [3] core/appkit/lua/simple_project.lua:214:in function <core/appkit/lua/simple_project.lua:210>

Lua Locals
----------------------------------------

    [1] self = table: 000000007ECD11C0, dt = 0.01667485386133194
    [2] dt = 0.01667485386133194, managed = table: 000000007EC91458, _ = [Level], level_wrapper = table: 000000007ECD11C0
    [3] dt = 0.01667485386133194

Editor / General: Testing failed. See logs.

 And here is the callstack when I call the Unspawn flow node via an external in event:

Editor / General: Test Engine: Access violation (0xc0000005) in build e643650096712533ea0ade9e638eeb1d671fbb05
accessing address 000000011581FEBB from 00000001400947CE
Build identifier: `e643650096712533ea0ade9e638eeb1d671fbb05`

Product version: `Developer Build (1.7.0.0)`

Thread name: `main`

Error context
----------------------------------------

Flow callback: ProjectFlowCallbacks.AimedAtUnit

Callstack
----------------------------------------

0x4062ce74 d:\stingray\stingray\runtime\foundation\error\callstack_win.cpp(286): stingray::callstack::exception_call_stack
0x4062d430 d:\stingray\stingray\runtime\foundation\error\exception_handling_win.cpp(97): stingray::exceptions::exception_filter
0x4091f3de d:\stingray\stingray\runtime\main\windows\main.cpp(72): `safe_run'::`1'::filt$0
0x408adf58 __C_specific_handler
0x1589976d __chkstk
0x15824c19 RtlImageNtHeaderEx
0x1589887a KiUserExceptionDispatcher
0x400947ce d:\stingray\stingray\runtime\application\flow\flow.cpp(495): stingray::flow::trigger_in_event
0x4009d40d d:\stingray\stingray\runtime\application\flow\flow_nodes.cpp(125): stingray::flow_nodes::trigger_out_event
0x402e945d d:\stingray\stingray\runtime\application\flow\flow_nodes\script_flow_nodes.cpp(355): stingray::flow_nodes::script_nodes::custom_script_node_trigger
0x401da9a5 d:\stingray\stingray\runtime\application\flow\flow_nodes_registry.cpp(81): stingray::flow_nodes::registry::internal::trigger_callback
0x4009d3a4 d:\stingray\stingray\runtime\application\flow\flow_nodes.cpp(555): stingray::flow_nodes::trigger_in_event
0x400947d9 d:\stingray\stingray\runtime\application\flow\flow.cpp(496): stingray::flow::trigger_in_event
0x4020a72f d:\stingray\stingray\runtime\application\flow\flow_nodes_api.h(53): stingray::flow_nodes::api::trigger_out_event
0x402f0e88 d:\stingray\stingray\runtime\application\flow\flow_nodes\utility_flow_nodes.cpp(415): stingray::flow_nodes::utility_nodes::compare_objects_trigger
0x401da9a5 d:\stingray\stingray\runtime\application\flow\flow_nodes_registry.cpp(81): stingray::flow_nodes::registry::internal::trigger_callback
0x4009d3a4 d:\stingray\stingray\runtime\application\flow\flow_nodes.cpp(555): stingray::flow_nodes::trigger_in_event
0x400947d9 d:\stingray\stingray\runtime\application\flow\flow.cpp(496): stingray::flow::trigger_in_event
0x4020a72f d:\stingray\stingray\runtime\application\flow\flow_nodes_api.h(53): stingray::flow_nodes::api::trigger_out_event
0x402d7d7d d:\stingray\stingray\runtime\application\flow\flow_nodes\event_flow_nodes.cpp(49): stingray::flow_nodes::event_nodes::event_callback
0x401d9d57 d:\stingray\stingray\runtime\application\flow\flow_nodes_registry.cpp(99): stingray::flow_nodes::registry::internal::event_callback
0x4009d3b9 d:\stingray\stingray\runtime\application\flow\flow_nodes.cpp(593): stingray::flow_nodes::trigger_out_event
0x400948f8 d:\stingray\stingray\runtime\application\flow\flow.cpp(519): stingray::flow::trigger_out_event
0x4009466e d:\stingray\stingray\runtime\application\flow\flow.cpp(534): stingray::flow::trigger_external_event
0x401d6fc4 d:\stingray\stingray\runtime\application\flow\flow_switchboard.cpp(283): stingray::FlowSwitchboard::trigger_level_updates
0x403ed03f d:\stingray\stingray\runtime\application\script\interface\if_level.cpp(81): <lambda_a8a59b0f7c5b41e9e742074e845fd0a8>::operator()
0xeeaddcee lua_newstate
0xeea9456d lua_pcall
0x401b59c9 d:\stingray\stingray\runtime\application\script\lua_environment.cpp(687): stingray::LuaEnvironment::call
0x401b5c7b d:\stingray\stingray\runtime\application\script\lua_environment.cpp(1039): stingray::LuaEnvironment::call_global
0x4073d335 d:\stingray\stingray\runtime\game\game.cpp(466): `anonymous namespace'::MyGame::update
0x401a1f0c d:\stingray\stingray\runtime\application\application.cpp(3004): stingray::Application::update

System Information
----------------------------------------

--- CPU
CPU: Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
Vendor: GenuineIntel
Logical processors: 8
Family: 0:6, Model: 5:14
Type: 0, Stepping: 3
Features: SSE SSE2 SSE3 SSSE3 SSE4.1 SSE4.2
Feature bits:
EBX: 00000100 00010000 00001000 00000000
ECX: 01111111 11111010 11111011 10111111
EDX: 10111111 11101011 11111011 11111111
--- OS
Windows version 6.2 build 9200
Windows 8
--- Graphics
Graphics card: NVIDIA GeForce GTX 980 Ti (DirectX 11.0)
Graphics card: Microsoft Basic Render Driver (DirectX 11.0)
--- Sound
No sound card detected.
--- Network
Network interface: Intel(R) Dual Band Wireless-AC 3165 (IPv4, IPv6)
Network interface: Microsoft Wi-Fi Direct Virtual Adapter (IPv4, IPv6)
Network interface: Realtek PCIe GBE Family Controller (IPv4, IPv6)
Network interface: Microsoft 6to4 Adapter (IPv6)
Network interface: Bluetooth Device (Personal Area Network) (IPv4, IPv6)
Network interface: Microsoft ISATAP Adapter #3 (IPv6)
--- Input
Input device: Mouse (18.1): Mouse
Input device: Keyboard (19.4): Keyboard
Input device: Generic (17.0): Razer Lycosa

Lua Stack
----------------------------------------

[0] [C]: in function trigger_level_update
[1] core/appkit/lua/level_wrapper.lua:80: in function update
[2] core/appkit/lua/app.lua:252: in function update
[3] core/appkit/lua/simple_project.lua:214:in function <core/appkit/lua/simple_project.lua:210>

Lua Locals
----------------------------------------

[1] self = table: 000000007ECD11C8, dt = 0.016684051603078842
[2] dt = 0.016684051603078842, managed = table: 000000007EC60BE0, _ = [Level], level_wrapper = table: 000000007ECD11C8
[3] dt = 0.016684051603078842

Editor / General: Testing failed. See logs.

 

Reply
Reply
0 Likes
Message 4 of 10

Anonymous
Not applicable

It looks like your issue is in 

Flow callback: ProjectFlowCallbacks.AimedAtUnit

Are you sure you don't have some dangling unit references somewhere that you try to use in AimedAtUnit ? 

Reply
Reply
Message 5 of 10

Anonymous
Not applicable

Aimed at unit.PNG

The unit being passed to Aimed at Unit is the unit that is being hit by a raycast comming from the crosshair, i.e being aimed at. Aimed at Unit then checks what type of unit it is, if it is interactable or not, and then calls the appropriate functionality.

Reply
Reply
0 Likes
Message 6 of 10

paul.kind
Alumni
Alumni

The unspawn unit node works as expected, there must be something you are doing where maybe you still need the unit alive for an operation.  It is hard to tell exactly what you are doing just from the shown example of the problem.

Areas of Expertise - MayaLT : Mudbox : 3DS Max : Inventor : Game Dev
Follow me on Twitter : @paulkind3d

Please remember to give kudos freely and mark acceptable answers as solved!

PLEASE do not send me private messages unless asked to do so. If you have a question, start a thread, and ask me on the public forums where answering your question may help others.

Did you know there was a YouTube learning channel for Autodesk Games? New videos are posted regularly with all sorts of content relative to Stingray, Maya/MayaLT, 3DS Max, and other game related tools. Get your game on @ https://www.youtube.com/user/autodeskgameshowtos
Reply
Reply
0 Likes
Message 7 of 10

Anonymous
Not applicable

Let me try to explain better. 
If the player is looking at a key for example, and picks it up and places it in the inventory, I want to despawn the key unit that is in the level.

I have tried despawning the unit in my "insert to selected slot" function, but that gives me an access violation.


Because the unspawn flow node works when it is connected to a keyboard input node, I thought that it might work with an external in event sent from the same function as mentioned above, but that gives me an access violation aswell.

 

Here's a look at my function where I insert items in my inventory:

--inserts a string "reference" into the selected slot, and despawns the aimed at unit
function Inventory:InsertToSelected(insertObject_s, unit) if(self.inventorySlots_t[1] ~= nil and self.inventorySlots_t[2] ~= nil and self.inventorySlots_t[3] ~= nil and self.inventorySlots_t[4] ~= nil) then local full_inventory_hud_event = nil full_inventory_hud_event = { eventId = scaleform.EventTypes.Custom, name = "full_inventory", data = {selectedSlot = self.selectedSlot_i} } scaleform.Stage.dispatch_event(full_inventory_hud_event) end if(self.inventorySlots_t[self.selectedSlot_i] == nil) then self.inventorySlots_t[self.selectedSlot_i] = insertObject_s stingray.Unit.flow_event(unit, "despawn") --ComponentManager.remove_components(unit) --stingray.World.destroy_unit(stingray.Application.main_world(), unit) if(self.selectedSlot_i < 5 and self.selectedSlot_i ~=4) then self:ChangeSelected(self.selectedSlot_i + 1) end end end--End of InsertToSelected()

insertObject_s is a unit script data string that contains which type the unit aimed at is, in this case it would be "Key".

Both it and the unit ref is being passed down from my flow node Aimed at Unit which checks what type of unit is being aimed at and has "seen" that this is an unit that can be picked up and placed in the player's inventory.

Reply
Reply
0 Likes
Message 8 of 10

__ben__
Alumni
Alumni

This looks like it might be an engine bug. Can you provide a minimal project that reproduces the issue? If so I'll take a look and try to debug.

Reply
Reply
0 Likes
Message 9 of 10

Anonymous
Not applicable

I'll send a project as soon as I get to school tomorrow.

Reply
Reply
0 Likes
Message 10 of 10

Anonymous
Not applicable

Here is a stripped down project with only my inventory system, and picking out the unit being aimed at.

Reply
Reply
0 Likes