Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in mission.lua due to DCS API getCategory behaviour change #246

Closed
funkyfranky opened this issue Nov 17, 2023 · 3 comments
Closed
Labels
bug Something isn't working

Comments

@funkyfranky
Copy link

In latest OB patch, the DCS API function getCategory was corrected. It now correctly returns the unit, weapon airbase category depending on the object type the method is used on. Before it always returned the object category.

In the file mission.lua, the lines

local category = object:getCategory()

must be changed to

local category = Object.getCategory(object)

to correctly retrieve the object category.

Currently, we get the error

2023-11-17 01:24:32.044 ERROR dcs_grpc: Error in event handler: [string "C:\Users\frank\Saved Games\DCS.testing\Scripts\DCS-gRPC\exporters\object.lua"]:21: attempt to call method 'getID' (a nil value)
stack traceback:
[string "C:\Users\frank\Saved Games\DCS.testing\Scripts\DCS-gRPC\exporters\object.lua"]:21: in function <[string "C:\Users\frank\Saved Games\DCS.testing\Scripts\DCS-gRPC\exporters\object.lua"]:19>
(tail call): ?
[string "C:\Users\frank\Saved Games\DCS.testing\Scripts\DCS-gRPC\methods\mission.lua"]:73: in function <[string "C:\Users\frank\Saved Games\DCS.testing\Scripts\DCS-gRPC\methods\mission.lua"]:63>
(tail call): ?
[C]: in function 'xpcall'
[string "C:\Users\frank\Saved Games\DCS.testing\Scripts\DCS-gRPC\grpc.lua"]:233: in function 'onEvent'
[string "Scripts/World/EventHandlers.lua"]:13: in function <[string "Scripts/World/EventHandlers.lua"]:11>

@Penecruz
Copy link
Contributor

Also needs to be corrected in unit.lua as well.

@peterb154
Copy link

peterb154 commented Nov 19, 2023

Note, I have implemented the changes in this PR locally on top of the 0.7.1 release. #247

Even with those fixes in place, the StreamUnit hangs after a unitGone event.

Here is the output from a little python grpc script streaming units. Whenever a "unit gone" event happens, the stream stops. The unit gone is me jumping out of a slot and taking another slot. It only records the unit gone, no other events..

2023-11-19T09:39:34 INFO    :  GRPC is up
2023-11-19T09:39:34 INFO    :  unit     : 3 SSS-Jeep
2023-11-19T09:39:35 INFO    :  unit     : 4 BAG_GUY
2023-11-19T09:39:35 INFO    :  unit     : 2 HHH-Jeep
2023-11-19T09:39:35 INFO    :  unit     : 1 Hawk1-1
2023-11-19T09:39:35 INFO    :  unit     : 1 Hawk1-1
2023-11-19T09:39:39 INFO    :  unit     : 1 Hawk1-1
2023-11-19T09:39:44 INFO    :  unit gone: 1 Hawk1-1
<I get nothing more after this event>

Here is the dcs.log from that time period

2023-11-19 15:39:41.157 INFO    ASYNCNET (Main): onPlayerSlot(2, 5)
2023-11-19 15:39:41.158 INFO    ASYNCNET (Main): passed onPlayerTryChangeSlot
2023-11-19 15:39:41.158 INFO    ASYNCNET (Main): release unit 1
2023-11-19 15:39:41.158 INFO    Scripting (Main): event:initiator_unit_type=P-51D-30-NA,type=relinquished,initiator_object_id=16778498,targetMissionID=1,target=Hawk1-1,t=3495.891,initiatorPilotName=sockeye,initiator_coalition=2,
2023-11-19 15:39:41.158 INFO    SCRIPTING (Main): [GRPC] Could not determine object category of object with ID: 1, Category: 0
2023-11-19 15:39:41.158 INFO    ASYNCNET (Main): client[2] occupied unit 5
2023-11-19 15:39:44.791 INFO    SCRIPTING (Main): [GRPC] Could not determine object category of object with ID: 5, Category: 0

the gRPC.log shows more detail about that timeframe...

2023-11-19 09:39:41.540 WARN    dcs_grpc: Could not determine object category of object with ID: 1, Category: 0
2023-11-19 09:39:41.540 DEBUG   dcs_grpc: Received event: StreamEventsResponse {
    time: 3495.891,
    event: Some(
        PlayerLeaveUnit(
            PlayerLeaveUnitEvent {
                initiator: Some(
                    Initiator {
                        initiator: Some(
                            Unknown(
                                Unknown {
                                    name: "Hawk1-1",
                                },
                            ),
                        ),
                    },
                ),
            },
        ),
    ),
}
2023-11-19 09:39:41.540 DEBUG   dcs_grpc: Received event: StreamEventsResponse {
    time: 3495.922,
    event: Some(
        PlayerChangeSlot(
            PlayerChangeSlotEvent {
                player_id: 2,
                coalition: Blue,
                slot_id: "5",
            },
        ),
    ),
}
2023-11-19 09:39:41.541 DEBUG   dcs_grpc: Received event: StreamEventsResponse {
    time: 3495.922,
    event: Some(
        PlayerSendChat(
            PlayerSendChatEvent {
                player_id: 1,
                message: "SRS Running @ ds1.dcs.xxxxx:5002",
            },
        ),
    ),
}
2023-11-19 09:39:42.337 DEBUG   dcs_grpc: Sending request `getUnitTransform`: {
  "name" = "SSS-Jeep",
}

.... <several normal events pass by>

2023-11-19 09:39:44.621 DEBUG   dcs_grpc: Sending request `getUnitTransform`: {
  "name" = "Hawk1-1",
}
2023-11-19 09:39:45.172 WARN    dcs_grpc: Could not determine object category of object with ID: 5, Category: 0
2023-11-19 09:39:45.173 DEBUG   dcs_grpc: Received event: StreamEventsResponse {
    time: 3499.533,
    event: Some(
        Birth(
            BirthEvent {
                initiator: Some(
                    Initiator {
                        initiator: Some(
                            Unknown(
                                Unknown {
                                    name: "Hawk1-2",
                                },
                            ),
                        ),
                    },
                ),
                place: Some(
                    Airbase {
                        unit: None,
                        name: "Tonopah Test Range",
                        callsign: "Tonopah Test Range",
                        coalition: Blue,
                        position: Some(
                            Position {
                                lat: 37.784039521659764,
                                lon: -116.77330290766967,
                                alt: 1686.8143310546875,
                                u: -174035.171875,
                                v: -228149.671875,
                            },
                        ),
                        category: Airdrome,
                        display_name: "Tonopah Test Range",
                    },
                ),
            },
        ),
    ),
}
2023-11-19 09:39:45.824 DEBUG   dcs_grpc: Sending request `getUnitTransform`: {
  "name" = "BAG_GUY",
}

@peterb154
Copy link

Note, I have implemented the changes in this PR locally on top of the 0.7.1 release. #247

Even with those fixes in place, the StreamUnit hangs after a unitGone event.

Here is the output from a little python grpc script streaming units. Whenever a "unit gone" event happens, the stream stops. The unit gone is me jumping out of a slot and taking another slot. It only records the unit gone, no other events..

2023-11-19T09:39:34 INFO    :  GRPC is up
2023-11-19T09:39:34 INFO    :  unit     : 3 SSS-Jeep
2023-11-19T09:39:35 INFO    :  unit     : 4 BAG_GUY
2023-11-19T09:39:35 INFO    :  unit     : 2 HHH-Jeep
2023-11-19T09:39:35 INFO    :  unit     : 1 Hawk1-1
2023-11-19T09:39:35 INFO    :  unit     : 1 Hawk1-1
2023-11-19T09:39:39 INFO    :  unit     : 1 Hawk1-1
2023-11-19T09:39:44 INFO    :  unit gone: 1 Hawk1-1
<I get nothing more after this event>

Here is the dcs.log from that time period

2023-11-19 15:39:41.157 INFO    ASYNCNET (Main): onPlayerSlot(2, 5)
2023-11-19 15:39:41.158 INFO    ASYNCNET (Main): passed onPlayerTryChangeSlot
2023-11-19 15:39:41.158 INFO    ASYNCNET (Main): release unit 1
2023-11-19 15:39:41.158 INFO    Scripting (Main): event:initiator_unit_type=P-51D-30-NA,type=relinquished,initiator_object_id=16778498,targetMissionID=1,target=Hawk1-1,t=3495.891,initiatorPilotName=sockeye,initiator_coalition=2,
2023-11-19 15:39:41.158 INFO    SCRIPTING (Main): [GRPC] Could not determine object category of object with ID: 1, Category: 0
2023-11-19 15:39:41.158 INFO    ASYNCNET (Main): client[2] occupied unit 5
2023-11-19 15:39:44.791 INFO    SCRIPTING (Main): [GRPC] Could not determine object category of object with ID: 5, Category: 0

the gRPC.log shows more detail about that timeframe...

2023-11-19 09:39:41.540 WARN    dcs_grpc: Could not determine object category of object with ID: 1, Category: 0
2023-11-19 09:39:41.540 DEBUG   dcs_grpc: Received event: StreamEventsResponse {
    time: 3495.891,
    event: Some(
        PlayerLeaveUnit(
            PlayerLeaveUnitEvent {
                initiator: Some(
                    Initiator {
                        initiator: Some(
                            Unknown(
                                Unknown {
                                    name: "Hawk1-1",
                                },
                            ),
                        ),
                    },
                ),
            },
        ),
    ),
}
2023-11-19 09:39:41.540 DEBUG   dcs_grpc: Received event: StreamEventsResponse {
    time: 3495.922,
    event: Some(
        PlayerChangeSlot(
            PlayerChangeSlotEvent {
                player_id: 2,
                coalition: Blue,
                slot_id: "5",
            },
        ),
    ),
}
2023-11-19 09:39:41.541 DEBUG   dcs_grpc: Received event: StreamEventsResponse {
    time: 3495.922,
    event: Some(
        PlayerSendChat(
            PlayerSendChatEvent {
                player_id: 1,
                message: "SRS Running @ ds1.dcs.xxxxx:5002",
            },
        ),
    ),
}
2023-11-19 09:39:42.337 DEBUG   dcs_grpc: Sending request `getUnitTransform`: {
  "name" = "SSS-Jeep",
}

.... <several normal events pass by>

2023-11-19 09:39:44.621 DEBUG   dcs_grpc: Sending request `getUnitTransform`: {
  "name" = "Hawk1-1",
}
2023-11-19 09:39:45.172 WARN    dcs_grpc: Could not determine object category of object with ID: 5, Category: 0
2023-11-19 09:39:45.173 DEBUG   dcs_grpc: Received event: StreamEventsResponse {
    time: 3499.533,
    event: Some(
        Birth(
            BirthEvent {
                initiator: Some(
                    Initiator {
                        initiator: Some(
                            Unknown(
                                Unknown {
                                    name: "Hawk1-2",
                                },
                            ),
                        ),
                    },
                ),
                place: Some(
                    Airbase {
                        unit: None,
                        name: "Tonopah Test Range",
                        callsign: "Tonopah Test Range",
                        coalition: Blue,
                        position: Some(
                            Position {
                                lat: 37.784039521659764,
                                lon: -116.77330290766967,
                                alt: 1686.8143310546875,
                                u: -174035.171875,
                                v: -228149.671875,
                            },
                        ),
                        category: Airdrome,
                        display_name: "Tonopah Test Range",
                    },
                ),
            },
        ),
    ),
}
2023-11-19 09:39:45.824 DEBUG   dcs_grpc: Sending request `getUnitTransform`: {
  "name" = "BAG_GUY",
}

Just came to say that this PR did indeed fix the issue I reported above. I implemented the change in the PR incorrectly. I had changed it to: object:getCategory(object) (missing the the switch from to the Object class)... Cheers to @martinco for helping me spot this. Once I corrected the mission.lua and unit.lua to Object.getCategory(object), my export stream worked without issue.

@rurounijones rurounijones added the bug Something isn't working label Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants